AT2 module on Mac OS X

"P. A. Bagyenda" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
For some reason, the stock AT2 SMSC module does not quite work right  
under OSX (bluetooth serial). After making the changes (attached),  
largely by inspecting minicom's code, it works fine. No time to  
figure out why, but perhaps somebody can take a look and make sense  
of it.

P.
smsc_at.diff (application/octet-stream, 3.8 KB)
Index: gw/smsc/smsc_at.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc/smsc_at.c,v
retrieving revision 1.35
diff -u -r1.35 smsc_at.c
--- gw/smsc/smsc_at.c	20 May 2007 16:11:31 -0000	1.35
+++ gw/smsc/smsc_at.c	30 Jul 2007 14:30:56 -0000
@@ -105,7 +105,11 @@
     }
     if (privdata->is_serial) {
         privdata->fd = open(octstr_get_cstr(privdata->device),
-                            O_RDWR | O_NONBLOCK | O_NOCTTY);
+                            O_RDWR | O_NDELAY | O_NOCTTY);
+	if (privdata->fd >= 0) {
+	     int n = fcntl(privdata->fd, F_GETFL, 0);
+	     fcntl(privdata->fd, F_SETFL, n & ~O_NDELAY);
+	}
     } else {
         if (octstr_str_compare(privdata->device, "rawtcp") == 0) {
             privdata->fd = tcpip_connect_to_server(octstr_get_cstr(privdata->rawtcp_host),
@@ -129,6 +133,7 @@
 {
     struct termios tios;
     int ret;
+    int out = 0;
 
     if ((ret = at2_open_device1(privdata)) != 0)
         return ret;
@@ -140,19 +145,29 @@
 
     kannel_cfmakeraw(&tios);
                       
-    tios.c_iflag |= IGNBRK; /* ignore break & parity errors */
-    tios.c_iflag &= ~INPCK; /* INPCK: disable parity check */
-    tios.c_cflag |= HUPCL; /* hangup on close */
-    tios.c_cflag |= CREAD; /* enable receiver */
+    tios.c_iflag  = IGNBRK; /* ignore break & parity errors */
+    tios.c_lflag  = 0;
+    tios.c_oflag  = 0;
+    tios.c_cflag  = CLOCAL | CREAD; /* enable receiver */
+    tios.c_cflag |= HUPCL;
+
+    tios.c_iflag &= ~(IXON | IXOFF | IXANY);
+    
+    tios.c_cc[VMIN] = 1;
+    tios.c_cc[VTIME] = 5;
+
+    tios.c_cflag &= ~(PARENB | PARODD);
+    tios.c_cflag &= ~(CSTOPB);
+    
+#if defined(_DCDFLOW)
+    tios.c_cflag &= ~CRTSCTS;
+#endif
+
+
     tios.c_cflag &= ~CSIZE; /* set to 8 bit */
     tios.c_cflag |= CS8;
-    tios.c_oflag &= ~ONLCR; /* no NL to CR-NL mapping outgoing */
-    tios.c_iflag |= IGNPAR; /* ignore parity */
-    tios.c_iflag &= ~INPCK;
-#if defined(CRTSCTS)
-    tios.c_cflag |= CRTSCTS; /* enable hardware flow control */
-#endif
-    tios.c_cc[VSUSP] = 0; /* otherwhise we can not send CTRL Z */
+
+    tios.c_cc[VSUSP] = 0;  /* otherwhise we can not send CTRL Z */
 
     /*
     if ( ModemTypes[privdata->modemid].enable_parity )
@@ -166,6 +181,8 @@
     }
     tcflush(privdata->fd, TCIOFLUSH);
          
+/*    ioctl(privdata->fd, TIOCFLUSH, &out); */
+
     /* 
      * Nokia 7110 and 6210 need some time between opening
      * the connection and sending the first AT commands 
@@ -349,8 +366,8 @@
     }
     O_DESTROY(linestr);
     if (s < 0) {
-        error(errno, "AT2[%s]: Couldnot write to device.", 
-              octstr_get_cstr(privdata->name));
+        error(errno, "AT2[%s]: Couldnot write to device: %s", 
+              octstr_get_cstr(privdata->name), strerror(errno));
         tcflush(privdata->fd, TCOFLUSH);
         return s;
     }
@@ -2059,11 +2076,10 @@
                 sprintf(command, "%s%s", sc, octstr_get_cstr(pdu));
                 at2_write(privdata, command);
                 at2_write_ctrlz(privdata);
-            
-            } else {
+	    } else {
             
                 /* include the CTRL-Z in the PDU string */
-                sprintf(command, "%s%s%c", sc, octstr_get_cstr(pdu), 0x1A);
+                sprintf(command, "%s%s%c\r", sc, octstr_get_cstr(pdu), 0x1A);
        
                 /* chop PDU into 18-byte-at-a-time pieces to prevent choking 
                  * of certain GSM Phones (e.g. Nokia 6310, 6230 etc.) */
@@ -2086,7 +2102,7 @@
                     at2_write(privdata, command);
                 }
             }               
-                
+	 
             /* wait 20 secs for modem command */
             ret = at2_wait_modem_command(privdata, 20, 0, &msg_id);
             debug("bb.smsc.at2", 0, "AT2[%s]: send command status: %d",
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.