<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][14622] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=14622">14622</a></dd>
<dt>Author</dt> <dd>gmaruzz</dd>
<dt>Date</dt> <dd>2009-08-24 14:41:40 -0500 (Mon, 24 Aug 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>celliax: beefed up a little the serial loop: yeah, it core dumps</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchbranchesgmaruzzmod_celliaxcelliaxh">freeswitch/branches/gmaruzz/mod_celliax/celliax.h</a></li>
<li><a href="#freeswitchbranchesgmaruzzmod_celliaxcelliax_protocolc">freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchbranchesgmaruzzmod_celliaxcelliaxh"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax.h (14621 => 14622)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_celliax/celliax.h        2009-08-24 18:12:42 UTC (rev 14621)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax.h        2009-08-24 19:41:40 UTC (rev 14622)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> #include &lt;switch_version.h&gt;
</span><span class="cx"> #include &lt;termios.h&gt;
</span><span class="cx"> #include &lt;sys/ioctl.h&gt;
</span><ins>+#include &lt;iconv.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> #ifndef WIN32
</span><span class="cx"> #include &lt;sys/time.h&gt;
</span><span class="lines">@@ -57,6 +58,10 @@
</span><span class="cx"> #define         PROTOCOL_FBUS2   1
</span><span class="cx"> #define         PROTOCOL_NO_SERIAL   3
</span><span class="cx"> 
</span><ins>+#define                AT_BUFSIZ 8192
+#define AT_MESG_MAX_LENGTH 2048 /* much more than 10 SMSs */
+#define AT_MESG_MAX_LINES 256   /* 256 lines, so it can contains the results of AT+CLAC, that gives all the AT commands the phone supports */
+
</ins><span class="cx"> #define SAMPLERATE_SKYPIAX 16000
</span><span class="cx"> #define SAMPLES_PER_FRAME SAMPLERATE_SKYPIAX/50
</span><span class="cx"> 
</span><span class="lines">@@ -91,11 +96,15 @@
</span><span class="cx"> 
</span><span class="cx"> /*********************************/
</span><span class="cx"> #define SKYPIAX_CAUSE_NORMAL                1
</span><ins>+#define SKYPIAX_CAUSE_FAILURE                2
+#define SKYPIAX_CAUSE_NO_ANSWER                3
</ins><span class="cx"> /*********************************/
</span><span class="cx"> #define SKYPIAX_FRAME_DTMF                        1
</span><span class="cx"> /*********************************/
</span><span class="cx"> #define SKYPIAX_CONTROL_RINGING                1
</span><span class="cx"> #define SKYPIAX_CONTROL_ANSWER                2
</span><ins>+#define SKYPIAX_CONTROL_HANGUP                3
+#define SKYPIAX_CONTROL_BUSY                4
</ins><span class="cx"> 
</span><span class="cx"> /*********************************/
</span><span class="cx"> #define                SKYPIAX_STATE_IDLE                                        0
</span><span class="lines">@@ -142,6 +151,9 @@
</span><span class="cx"> 
</span><span class="cx"> /*********************************/
</span><span class="cx"> 
</span><ins>+#define         AT_OK   0
+#define         AT_ERROR   1
+
</ins><span class="cx"> #define SKYPIAX_MAX_INTERFACES 64
</span><span class="cx"> 
</span><span class="cx"> #ifndef WIN32
</span><span class="lines">@@ -169,6 +181,18 @@
</span><span class="cx"> 
</span><span class="cx"> #endif //WIN32
</span><span class="cx"> 
</span><ins>+/*! 
+ * \brief structure for storing the results of AT commands, in an array of AT_MESG_MAX_LINES * AT_MESG_MAX_LENGTH chars
+ */
+struct s_result {
+  int elemcount;
+  char result[AT_MESG_MAX_LINES][AT_MESG_MAX_LENGTH];
+};
+
+struct owner_struct {
+int _state;
+int hangupcause;
+};
</ins><span class="cx"> struct private_object {
</span><span class="cx">         unsigned int flags;
</span><span class="cx">         switch_codec_t read_codec;
</span><span class="lines">@@ -239,7 +263,6 @@
</span><span class="cx">         //int phonebook_last_entry;
</span><span class="cx">         //int phonebook_number_lenght;
</span><span class="cx">         //int phonebook_text_lenght;
</span><del>-        FILE *phonebook_writing_fp;
</del><span class="cx">         int celliax_dir_entry_extension_prefix;
</span><span class="cx">         char skype_user[256];
</span><span class="cx">         char skype_password[256];
</span><span class="lines">@@ -262,6 +285,7 @@
</span><span class="cx">   int controldevfd;             /*!&lt; \brief serial controlling file descriptor for this interface */
</span><span class="cx">   //pthread_t controldev_thread;  /*!&lt; \brief serial control thread for this interface, running during the call */
</span><span class="cx">   speed_t controldevice_speed;
</span><ins>+  int controldev_dead;
</ins><span class="cx">  
</span><span class="cx">   char at_dial_pre_number[64];
</span><span class="cx">   char at_dial_post_number[64];
</span><span class="lines">@@ -330,10 +354,37 @@
</span><span class="cx">   int at_has_clcc;
</span><span class="cx">   int at_has_ecam;
</span><span class="cx"> 
</span><ins>+  char at_cmgw[16];
</ins><span class="cx">   int no_ucs2;
</span><del>-  int sms_cnmi_not_supported;
</del><span class="cx">   time_t celliax_serial_sync_period;
</span><span class="cx"> 
</span><ins>+  time_t celliax_serial_synced_timestamp;
+  struct s_result line_array;
+
+
+  int unread_sms_msg_id;
+  int reading_sms_msg;
+  char sms_message[4800];
+  int sms_cnmi_not_supported;
+  char sms_receiving_program[256];
+
+
+  struct timeval call_incoming_time;
+  int phone_callflow;           /*!&lt; \brief 'callflow' of the phone interface (as opposed to skype interface) */
+  switch_mutex_t *controldev_lock;
+
+  int phonebook_listing;
+  int phonebook_querying;
+  int phonebook_listing_received_calls;
+
+  int phonebook_first_entry;
+  int phonebook_last_entry;
+  int phonebook_number_lenght;
+  int phonebook_text_lenght;
+  FILE *phonebook_writing_fp;
+
+  struct timeval ringtime;
+  struct owner_struct *owner;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> typedef struct private_object private_t;
</span><span class="lines">@@ -419,3 +470,20 @@
</span><span class="cx"> #endif// NOTDEF
</span><span class="cx"> #define RESULT_FAILURE 0
</span><span class="cx"> #define RESULT_SUCCESS 1
</span><ins>+int utf_to_ucs2(private_t * tech_pvt, char *utf_in, size_t inbytesleft, char *ucs2_out,
+                size_t outbytesleft);
+int ucs2_to_utf8(private_t * tech_pvt, char *ucs2_in, char *utf8_out,
+                 size_t outbytesleft);
+//#define PUSHA_UNLOCKA(x)    pthread_cleanup_push(celliax_unlocka_log, (void *) x);
+//#define POPPA_UNLOCKA(x)    pthread_cleanup_pop(0);
+
+#define PUSHA_UNLOCKA(x)    ERRORA(&quot;PUSHA_UNLOCKA: %p\n&quot;, SKYPIAX_P_LOG, (void *)x);
+#define POPPA_UNLOCKA(x)    ERRORA(&quot;POPPA_UNLOCKA: %p\n&quot;, SKYPIAX_P_LOG, (void *)x);
+#define LOKKA(x)    ERRORA(&quot;LOKKA: %p\n&quot;, SKYPIAX_P_LOG, (void *)x);
+#define UNLOCKA(x)    ERRORA(&quot;UNLOCKA: %p\n&quot;, SKYPIAX_P_LOG, (void *)x);
+
+#define celliax_queue_control(x, y) ERRORA(&quot;celliax_queue_control: %p, %d\n&quot;, SKYPIAX_P_LOG, (void *)x, y);
+
+#define ast_setstate(x, y) ERRORA(&quot;ast_setstate: %p, %d\n&quot;, SKYPIAX_P_LOG, (void *)x, y);
+
+
</ins></span></pre></div>
<a id="freeswitchbranchesgmaruzzmod_celliaxcelliax_protocolc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c (14621 => 14622)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c        2009-08-24 18:12:42 UTC (rev 14621)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c        2009-08-24 19:41:40 UTC (rev 14622)
</span><span class="lines">@@ -15,7 +15,10 @@
</span><span class="cx"> int samplerate_celliax = SAMPLERATE_SKYPIAX;
</span><span class="cx"> 
</span><span class="cx"> extern int running;
</span><ins>+int celliax_dir_entry_extension = 1;
</ins><span class="cx"> 
</span><ins>+int option_debug=100;
+
</ins><span class="cx"> /*************************************/
</span><span class="cx"> /* suspicious globals FIXME */
</span><span class="cx"> #ifdef WIN32
</span><span class="lines">@@ -1104,13 +1107,6 @@
</span><span class="cx">                                 case SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION:
</span><span class="cx">                                         //DEBUGA_SKYPE (&quot;\n\n\tIf I do not (almost) immediately connect to Skype API,\n\tplease give the Skype client authorization to be connected \n\tby Asterisk and to not ask you again.\n\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">                                         celliax_sleep(5000);
</span><del>-#if 0
-                                        if (!tech_pvt-&gt;SkypiaxHandles.currentuserhandle) {
-                                                SendMessage(HWND_BROADCAST,
-                                                                        tech_pvt-&gt;SkypiaxHandles.
-                                                                        win32_uiGlobal_MsgID_SkypeControlAPIDiscover, (WPARAM) tech_pvt-&gt;SkypiaxHandles.win32_hInit_MainWindowHandle, 0);
-                                        }
-#endif
</del><span class="cx">                                         break;
</span><span class="cx">                                 case SKYPECONTROLAPI_ATTACH_REFUSED:
</span><span class="cx">                                         ERRORA(&quot;Skype client refused to be connected by Skypiax!\n&quot;, SKYPIAX_P_LOG);
</span><span class="lines">@@ -1121,13 +1117,6 @@
</span><span class="cx">                                 case SKYPECONTROLAPI_ATTACH_API_AVAILABLE:
</span><span class="cx">                                         DEBUGA_SKYPE(&quot;Skype API available\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">                                         celliax_sleep(5000);
</span><del>-#if 0
-                                        if (!tech_pvt-&gt;SkypiaxHandles.currentuserhandle) {
-                                                SendMessage(HWND_BROADCAST,
-                                                                        tech_pvt-&gt;SkypiaxHandles.
-                                                                        win32_uiGlobal_MsgID_SkypeControlAPIDiscover, (WPARAM) tech_pvt-&gt;SkypiaxHandles.win32_hInit_MainWindowHandle, 0);
-                                        }
-#endif
</del><span class="cx">                                         break;
</span><span class="cx">                                 default:
</span><span class="cx">                                         WARNINGA(&quot;GOT AN UNKNOWN SKYPE WINDOWS MSG\n&quot;, SKYPIAX_P_LOG);
</span><span class="lines">@@ -1406,144 +1395,11 @@
</span><span class="cx"> {
</span><span class="cx"> 
</span><span class="cx">         private_t *tech_pvt = obj;
</span><del>-#if 0
-        struct SkypiaxHandles *SkypiaxHandles;
-        char buf[512];
-        Display *disp = NULL;
-        Window root = -1;
-        Window win = -1;
-
-        if (!strlen(tech_pvt-&gt;X11_display))
-                strcpy(tech_pvt-&gt;X11_display, getenv(&quot;DISPLAY&quot;));
-
-        if (!tech_pvt-&gt;tcp_srv_port)
-                tech_pvt-&gt;tcp_srv_port = 10160;
-
-        if (!tech_pvt-&gt;tcp_cli_port)
-                tech_pvt-&gt;tcp_cli_port = 10161;
-
-        if (pipe(tech_pvt-&gt;SkypiaxHandles.fdesc)) {
-                fcntl(tech_pvt-&gt;SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK);
-                fcntl(tech_pvt-&gt;SkypiaxHandles.fdesc[1], F_SETFL, O_NONBLOCK);
-        }
-        SkypiaxHandles = &amp;tech_pvt-&gt;SkypiaxHandles;
-        disp = XOpenDisplay(tech_pvt-&gt;X11_display);
-        if (!disp) {
-                ERRORA(&quot;Cannot open X Display '%s', exiting skype thread\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;X11_display);
-                running = 0;
-                return NULL;
-        } else {
-                DEBUGA_SKYPE(&quot;X Display '%s' opened\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;X11_display);
-        }
-
-        int xfd;
-        xfd = XConnectionNumber(disp);
-        fcntl(xfd, F_SETFD, FD_CLOEXEC);
-
-        SkypiaxHandles-&gt;disp = disp;
-
-#endif// 0
</del><span class="cx">         //if (celliax_present(SkypiaxHandles)) 
</span><span class="cx">         if (1) {
</span><del>-#if 0
-                root = DefaultRootWindow(disp);
-                win = XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0, BlackPixel(disp, DefaultScreen(disp)), BlackPixel(disp, DefaultScreen(disp)));
-
-                SkypiaxHandles-&gt;win = win;
-
-                snprintf(buf, 512, &quot;NAME celliax&quot;);
-
-                if (!celliax_send_message(SkypiaxHandles, buf)) {
-                        ERRORA(&quot;Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n&quot;, SKYPIAX_P_LOG);
-                        running = 0;
-                        return NULL;
-                }
-
-                snprintf(buf, 512, &quot;PROTOCOL 7&quot;);
-                if (!celliax_send_message(SkypiaxHandles, buf)) {
-                        ERRORA(&quot;Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n&quot;, SKYPIAX_P_LOG);
-                        running = 0;
-                        return NULL;
-                }
-
-                /* perform an events loop */
-                XEvent an_event;
-                char buf[21];                        /*  can't be longer */
-                char buffer[17000];
-                char *b;
-                int i;
-                int continue_is_broken = 0;
-                Atom atom_begin = XInternAtom(disp, &quot;SKYPECONTROLAPI_MESSAGE_BEGIN&quot;, False);
-                Atom atom_continue = XInternAtom(disp, &quot;SKYPECONTROLAPI_MESSAGE&quot;, False);
-
-                b = buffer;
-
-#endif // 0
</del><span class="cx">                 while (running) {
</span><span class="cx">                         celliax_sleep(1000000); //1 sec
</span><span class="cx">                         DEBUGA_SKYPE(&quot;ciao!\n&quot;, SKYPIAX_P_LOG);
</span><del>-#if 0
-                        XNextEvent(disp, &amp;an_event);
-                        if (!(running &amp;&amp; tech_pvt-&gt;running))
-                                break;
-                        switch (an_event.type) {
-                        case ClientMessage:
-
-                                if (an_event.xclient.format != 8)
-                                        break;
-
-                                for (i = 0; i &lt; 20 &amp;&amp; an_event.xclient.data.b[i] != '\0'; ++i)
-                                        buf[i] = an_event.xclient.data.b[i];
-
-                                buf[i] = '\0';
-
-                                //DEBUGA_SKYPE (&quot;BUF=|||%s|||\n&quot;, SKYPIAX_P_LOG, buf);
-
-                                if (an_event.xclient.message_type == atom_begin) {
-
-                                        if (strlen(buffer)) {
-                                                unsigned int howmany;
-                                                howmany = strlen(b) + 1;
-                                                howmany = write(SkypiaxHandles-&gt;fdesc[1], b, howmany);
-                                                DEBUGA_SKYPE(&quot;RECEIVED2=|||%s|||\n&quot;, SKYPIAX_P_LOG, buffer);
-                                                memset(buffer, '\0', 17000);
-                                        }
-                                }
-                                if (an_event.xclient.message_type == atom_continue) {
-
-                                        if (!strlen(buffer)) {
-                                                DEBUGA_SKYPE
-                                                        (&quot;Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||\n&quot;, SKYPIAX_P_LOG, buf);
-                                                continue_is_broken = 1;
-                                                if (!strncmp(buf, &quot;ognised identity&quot;, 15)) {
-                                                        WARNINGA
-                                                                (&quot;Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||. Let's introduce a 1 second delay.\n&quot;,
-                                                                 SKYPIAX_P_LOG, buf);
-                                                        celliax_sleep(1000000);        //1 sec
-                                                }
-                                                break;
-                                        }
-                                }
-
-                                strcat(buffer, buf);
-
-                                if (i &lt; 20 || continue_is_broken) {        /* last fragment */
-                                        unsigned int howmany;
-
-                                        howmany = strlen(b) + 1;
-
-                                        howmany = write(SkypiaxHandles-&gt;fdesc[1], b, howmany);
-                                        //DEBUGA_SKYPE (&quot;RECEIVED=|||%s|||\n&quot;, SKYPIAX_P_LOG, buffer);
-                                        memset(buffer, '\0', 17000);
-                                        XFlush(disp);
-                                        continue_is_broken = 0;
-                                }
-
-                                break;
-                        default:
-                                break;
-                        }
-#endif //0
</del><span class="cx">                 }
</span><span class="cx">         } else {
</span><span class="cx">                 ERRORA(&quot;Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypiax\n&quot;, SKYPIAX_P_LOG);
</span><span class="lines">@@ -1811,13 +1667,6 @@
</span><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx"> /* this take a lot of time to complete on devices with slow serial link (eg.: 9600bps) */
</span><del>-#if 0
-  /* ask for the list of supported AT commands, useful to implement new models and debugging */
-  res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT+CLAC&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CLAC failed, continue\n&quot;, SKYPIAX_P_LOG);
-  }
-#endif
</del><span class="cx">   /* signal incoming SMS with a +CMTI unsolicited msg */
</span><span class="cx">   res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT+CNMI=3,1,0,0,0&quot;);
</span><span class="cx">   if (res) {
</span><span class="lines">@@ -1990,1310 +1839,12 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-#ifdef NOTDEF
-int celliax_serial_getstatus(private_t * tech_pvt)
-{
-  if (tech_pvt-&gt;controldevprotocol == PROTOCOL_AT)
-    return celliax_serial_getstatus_AT(tech_pvt);
-#ifdef CELLIAX_FBUS2
-  if (tech_pvt-&gt;controldevprotocol == PROTOCOL_FBUS2)
-    return celliax_serial_getstatus_FBUS2(tech_pvt);
-#endif /* CELLIAX_FBUS2 */
-
-#ifdef CELLIAX_CVM
-  if (tech_pvt-&gt;controldevprotocol == PROTOCOL_CVM_BUSMAIL)
-    return celliax_serial_getstatus_CVM_BUSMAIL(tech_pvt);
-#endif /* CELLIAX_CVM */
-  return -1;
-}
-
-int celliax_serial_read(private_t * tech_pvt)
-{
-  if (tech_pvt-&gt;controldevprotocol == PROTOCOL_AT)
-    return celliax_serial_read_AT(tech_pvt, 0, 100000, 0, NULL, 1);    // a 10th of a second timeout
-#ifdef CELLIAX_FBUS2
-  if (tech_pvt-&gt;controldevprotocol == PROTOCOL_FBUS2)
-    return celliax_serial_read_FBUS2(tech_pvt);
-#endif /* CELLIAX_FBUS2 */
-#ifdef CELLIAX_CVM
-  if (tech_pvt-&gt;controldevprotocol == PROTOCOL_CVM_BUSMAIL)
-    return celliax_serial_read_CVM_BUSMAIL(tech_pvt);
-#endif /* CELLIAX_CVM */
-  return -1;
-}
-
-int celliax_serial_hangup(private_t * tech_pvt)
-{
-  if (tech_pvt-&gt;controldevprotocol == PROTOCOL_AT)
-    return celliax_serial_hangup_AT(tech_pvt);
-#ifdef CELLIAX_FBUS2
-  if (tech_pvt-&gt;controldevprotocol == PROTOCOL_FBUS2)
-    return celliax_serial_hangup_FBUS2(tech_pvt);
-#endif /* CELLIAX_FBUS2 */
-#ifdef CELLIAX_CVM
-  if (tech_pvt-&gt;controldevprotocol == PROTOCOL_CVM_BUSMAIL)
-    return celliax_serial_hangup_CVM_BUSMAIL(tech_pvt);
-#endif /* CELLIAX_CVM */
-  return -1;
-}
-
-int celliax_serial_answer(private_t * tech_pvt)
-{
-  if (tech_pvt-&gt;controldevprotocol == PROTOCOL_AT)
-    return celliax_serial_answer_AT(tech_pvt);
-#ifdef CELLIAX_FBUS2
-  if (tech_pvt-&gt;controldevprotocol == PROTOCOL_FBUS2)
-    return celliax_serial_answer_FBUS2(tech_pvt);
-#endif /* CELLIAX_FBUS2 */
-#ifdef CELLIAX_CVM
-  if (tech_pvt-&gt;controldevprotocol == PROTOCOL_CVM_BUSMAIL)
-    return celliax_serial_answer_CVM_BUSMAIL(tech_pvt);
-#endif /* CELLIAX_CVM */
-  return -1;
-}
-#endif //NOTDEF
-
-
-#undef CELLIAX_ADDITIONAL
-#ifdef CELLIAX_ADDITIONAL
-
-//indent -gnu -ts4 -br -brs -cdw -lp -ce -nbfda -npcs -nprs -npsl -nbbo -saf -sai -saw -cs -bbo -nhnl -nut -sob -l90 
-//#include &quot;celliax.h&quot;
-//#include &quot;iconv.h&quot;
-
-extern int celliax_debug;
-extern char *celliax_console_active;
-extern char celliax_type[];
-extern private_t *celliax_iflist;
-extern int celliax_dir_entry_extension;
-
-#ifndef GIOVA48
-//#define SAMPLES_PER_FRAME 160
-#else // GIOVA48
-#define SAMPLES_PER_FRAME 960
-#endif // GIOVA48
-
-#ifdef CELLIAX_ALSA
-/*! \brief ALSA pcm format, according to endianess  */
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-snd_pcm_format_t celliax_format = SND_PCM_FORMAT_S16_LE;
-#else
-snd_pcm_format_t celliax_format = SND_PCM_FORMAT_S16_BE;
-#endif
-
-/*!
- * \brief Initialize the ALSA soundcard channels (capture AND playback) used by one interface (a multichannel soundcard can be used by multiple interfaces) 
- * \param p the celliax_pvt of the interface
- *
- * This function call alsa_open_dev to initialize the ALSA soundcard for each channel (capture AND playback) used by one interface (a multichannel soundcard can be used by multiple interfaces). Called by sound_init
- *
- * \return zero on success, -1 on error.
- */
-int alsa_init(private_t * tech_pvt)
-{
-  tech_pvt-&gt;alsac = alsa_open_dev(p, SND_PCM_STREAM_CAPTURE);
-  if (!p-&gt;alsac) {
-    ERRORA(&quot;Failed opening ALSA capture device: %s\n&quot;, SKYPIAX_P_LOG, p-&gt;alsacname);
-    if (alsa_shutdown(p)) {
-      ERRORA(&quot;alsa_shutdown failed\n&quot;, SKYPIAX_P_LOG);
-      return -1;
-    }
-    return -1;
-  }
-  p-&gt;alsap = alsa_open_dev(p, SND_PCM_STREAM_PLAYBACK);
-  if (!p-&gt;alsap) {
-    ERRORA(&quot;Failed opening ALSA playback device: %s\n&quot;, SKYPIAX_P_LOG, p-&gt;alsapname);
-    if (alsa_shutdown(p)) {
-      ERRORA(&quot;alsa_shutdown failed\n&quot;, SKYPIAX_P_LOG);
-      return -1;
-    }
-    return -1;
-  }
-
-  /* make valgrind very happy */
-  snd_config_update_free_global();
-  return 0;
-}
-
-/*!
- * \brief Shutdown the ALSA soundcard channels (input and output) used by one interface (a multichannel soundcard can be used by multiple interfaces) 
- * \param p the celliax_pvt of the interface
- *
- * This function shutdown the ALSA soundcard channels (input and output) used by one interface (a multichannel soundcard can be used by multiple interfaces). Called by sound_init
- *
- * \return zero on success, -1 on error.
- */
-
-int alsa_shutdown(private_t * tech_pvt)
-{
-
-  int err;
-
-  if (p-&gt;alsap) {
-    err = snd_pcm_drop(p-&gt;alsap);
-    if (err &lt; 0) {
-      ERRORA(&quot;device [%s], snd_pcm_drop failed with error '%s'\n&quot;, SKYPIAX_P_LOG,
-             p-&gt;alsapname, snd_strerror(err));
-      return -1;
-    }
-    err = snd_pcm_close(p-&gt;alsap);
-    if (err &lt; 0) {
-      ERRORA(&quot;device [%s], snd_pcm_close failed with error '%s'\n&quot;, SKYPIAX_P_LOG,
-             p-&gt;alsapname, snd_strerror(err));
-      return -1;
-    }
-  }
-  if (p-&gt;alsac) {
-    err = snd_pcm_drop(p-&gt;alsac);
-    if (err &lt; 0) {
-      ERRORA(&quot;device [%s], snd_pcm_drop failed with error '%s'\n&quot;, SKYPIAX_P_LOG,
-             p-&gt;alsacname, snd_strerror(err));
-      return -1;
-    }
-    err = snd_pcm_close(p-&gt;alsac);
-    if (err &lt; 0) {
-      ERRORA(&quot;device [%s], snd_pcm_close failed with error '%s'\n&quot;, SKYPIAX_P_LOG,
-             p-&gt;alsacname, snd_strerror(err));
-      return -1;
-    }
-  }
-
-  return 0;
-}
-
-/*!
- * \brief Setup and open the ALSA device (capture OR playback) 
- * \param p the celliax_pvt of the interface
- * \param stream the ALSA capture/playback definition
- *
- * This function setup and open the ALSA device (capture OR playback). Called by alsa_init
- *
- * \return zero on success, -1 on error.
- */
-snd_pcm_t *alsa_open_dev(private_t * p, snd_pcm_stream_t stream)
-{
-
-  snd_pcm_t *handle = NULL;
-  snd_pcm_hw_params_t *params;
-  snd_pcm_sw_params_t *swparams;
-  snd_pcm_uframes_t buffer_size;
-  int err;
-  size_t n;
-  //snd_pcm_uframes_t xfer_align;
-  unsigned int rate;
-  snd_pcm_uframes_t start_threshold, stop_threshold;
-  snd_pcm_uframes_t period_size = 0;
-  snd_pcm_uframes_t chunk_size = 0;
-  int start_delay = 0;
-  int stop_delay = 0;
-  snd_pcm_state_t state;
-  snd_pcm_info_t *info;
-
-  period_size = p-&gt;alsa_period_size;
-
-  snd_pcm_hw_params_alloca(&amp;params);
-  snd_pcm_sw_params_alloca(&amp;swparams);
-
-  if (stream == SND_PCM_STREAM_CAPTURE) {
-    err = snd_pcm_open(&amp;handle, p-&gt;alsacname, stream, 0 | SND_PCM_NONBLOCK);
-  } else {
-    err = snd_pcm_open(&amp;handle, p-&gt;alsapname, stream, 0 | SND_PCM_NONBLOCK);
-  }
-  if (err &lt; 0) {
-    ERRORA
-      (&quot;snd_pcm_open failed with error '%s' on device '%s', if you are using a plughw:n device please change it to be a default:n device (so to allow it to be shared with other concurrent programs), or maybe you are using an ALSA voicemodem and slmodemd&quot;
-       &quot; is running?\n&quot;, SKYPIAX_P_LOG, snd_strerror(err),
-       stream == SND_PCM_STREAM_CAPTURE ? p-&gt;alsacname : p-&gt;alsapname);
-    return NULL;
-  }
-
-  snd_pcm_info_alloca(&amp;info);
-
-  if ((err = snd_pcm_info(handle, info)) &lt; 0) {
-    ERRORA(&quot;info error: %s&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-
-  err = snd_pcm_nonblock(handle, 1);
-  if (err &lt; 0) {
-    ERRORA(&quot;nonblock setting error: %s&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-
-  err = snd_pcm_hw_params_any(handle, params);
-  if (err &lt; 0) {
-    ERRORA(&quot;Broken configuration for this PCM, no configurations available: %s\n&quot;,
-           SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-
-  err = snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);
-  if (err &lt; 0) {
-    ERRORA(&quot;Access type not available: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-  err = snd_pcm_hw_params_set_format(handle, params, celliax_format);
-  if (err &lt; 0) {
-    ERRORA(&quot;Sample format non available: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-  err = snd_pcm_hw_params_set_channels(handle, params, 1);
-  if (err &lt; 0) {
-    DEBUGA_SOUND(&quot;Channels count set failed: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-  }
-#if 1
-  unsigned int chan_num;
-  err = snd_pcm_hw_params_get_channels(params, &amp;chan_num);
-  if (err &lt; 0) {
-    ERRORA(&quot;Channels count non available: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-  if (chan_num &lt; 1 || chan_num &gt; 2) {
-    ERRORA(&quot;Channels count MUST BE 1 or 2, it is: %d\n&quot;, SKYPIAX_P_LOG, chan_num);
-    ERRORA(&quot;Channels count MUST BE 1 or 2, it is: %d on %s %s\n&quot;, SKYPIAX_P_LOG, chan_num,
-           p-&gt;alsapname, p-&gt;alsacname);
-    return NULL;
-  } else {
-    if (chan_num == 1) {
-      if (stream == SND_PCM_STREAM_CAPTURE)
-        p-&gt;alsa_capture_is_mono = 1;
-      else
-        p-&gt;alsa_play_is_mono = 1;
-    } else {
-      if (stream == SND_PCM_STREAM_CAPTURE)
-        p-&gt;alsa_capture_is_mono = 0;
-      else
-        p-&gt;alsa_play_is_mono = 0;
-    }
-  }
-#else
-  p-&gt;alsa_capture_is_mono = 1;
-  p-&gt;alsa_play_is_mono = 1;
-#endif
-
-#if 0
-  unsigned int buffer_time = 0;
-  unsigned int period_time = 0;
-  snd_pcm_uframes_t period_frames = 0;
-  snd_pcm_uframes_t buffer_frames = 0;
-
-  if (buffer_time == 0 &amp;&amp; buffer_frames == 0) {
-    err = snd_pcm_hw_params_get_buffer_time_max(params, &amp;buffer_time, 0);
-    assert(err &gt;= 0);
-    if (buffer_time &gt; 500000)
-      buffer_time = 500000;
-  }
-  if (period_time == 0 &amp;&amp; period_frames == 0) {
-    if (buffer_time &gt; 0)
-      period_time = buffer_time / 4;
-    else
-      period_frames = buffer_frames / 4;
-  }
-  if (period_time &gt; 0)
-    err = snd_pcm_hw_params_set_period_time_near(handle, params, &amp;period_time, 0);
-  else
-    err = snd_pcm_hw_params_set_period_size_near(handle, params, &amp;period_frames, 0);
-  assert(err &gt;= 0);
-  if (buffer_time &gt; 0) {
-    err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &amp;buffer_time, 0);
-  } else {
-    err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &amp;buffer_frames);
-  }
-#endif
-
-#if 1
-  rate = p-&gt;celliax_sound_rate;
-  err = snd_pcm_hw_params_set_rate_near(handle, params, &amp;rate, 0);
-  if ((float) p-&gt;celliax_sound_rate * 1.05 &lt; rate
-      || (float) p-&gt;celliax_sound_rate * 0.95 &gt; rate) {
-    WARNINGA(&quot;Rate is not accurate (requested = %iHz, got = %iHz)\n&quot;, SKYPIAX_P_LOG,
-             p-&gt;celliax_sound_rate, rate);
-  }
-
-  if (err &lt; 0) {
-    ERRORA(&quot;Error setting rate: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-  p-&gt;celliax_sound_rate = rate;
-
-  err = snd_pcm_hw_params_set_period_size_near(handle, params, &amp;period_size, 0);
-
-  if (err &lt; 0) {
-    ERRORA(&quot;Error setting period_size: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-
-  p-&gt;alsa_period_size = period_size;
-
-  p-&gt;alsa_buffer_size = p-&gt;alsa_period_size * p-&gt;alsa_periods_in_buffer;
-
-  err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &amp;p-&gt;alsa_buffer_size);
-
-  if (err &lt; 0) {
-    ERRORA(&quot;Error setting buffer_size: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-#endif
-
-  err = snd_pcm_hw_params(handle, params);
-  if (err &lt; 0) {
-    ERRORA(&quot;Unable to install hw params: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-
-  snd_pcm_hw_params_get_period_size(params, &amp;chunk_size, 0);
-  snd_pcm_hw_params_get_buffer_size(params, &amp;buffer_size);
-  if (chunk_size == buffer_size) {
-    ERRORA(&quot;Can't use period equal to buffer size (%lu == %lu)\n&quot;, SKYPIAX_P_LOG,
-           chunk_size, buffer_size);
-    return NULL;
-  }
-
-  snd_pcm_sw_params_current(handle, swparams);
-
-#if 0
-  err = snd_pcm_sw_params_get_xfer_align(swparams, &amp;xfer_align);
-  if (err &lt; 0) {
-    ERRORA(&quot;Unable to obtain xfer align: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-  }
-  NOTICA(&quot;xfer_align: %d\n&quot;, SKYPIAX_P_LOG, xfer_align);
-  /* for some reason, on some platforms, xfer_align here is zero, that gives a floating point exception later. So, let's try to force it to 160, the frame size used by celliax */
-  xfer_align = p-&gt;alsa_period_size;
-  NOTICA(&quot;xfer_align: %d\n&quot;, SKYPIAX_P_LOG, xfer_align);
-
-  err = snd_pcm_sw_params_set_xfer_align(handle, swparams, xfer_align);
-  if (err &lt; 0) {
-    ERRORA(&quot;Error setting xfer_align: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-  }
-  NOTICA(&quot;xfer_align: %d\n&quot;, SKYPIAX_P_LOG, xfer_align);
-
-  err = snd_pcm_sw_params_get_xfer_align(swparams, &amp;xfer_align);
-  if (err &lt; 0) {
-    ERRORA(&quot;Unable to obtain xfer align: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-  }
-  NOTICA(&quot;xfer_align: %d\n&quot;, SKYPIAX_P_LOG, xfer_align);
-#endif
-
-  /*
-     if (sleep_min)
-     xfer_align = 1;
-     err = snd_pcm_sw_params_set_sleep_min(handle, swparams,
-     0);
-
-     if (err &lt; 0) {
-     ERRORA(&quot;Error setting slep_min: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-     }
-   */
-  n = chunk_size;
-  err = snd_pcm_sw_params_set_avail_min(handle, swparams, n);
-  if (err &lt; 0) {
-    ERRORA(&quot;Error setting avail_min: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-  }
-#if 0
-  /* round up to closest transfer boundary */
-  if (xfer_align == 0) {        //so to avoid floating point exception ????
-    xfer_align = 160;
-  }
-  //original n = (buffer_size / xfer_align) * xfer_align;
-  n = (chunk_size / xfer_align) * xfer_align;
-#endif
-  if (stream == SND_PCM_STREAM_CAPTURE) {
-    start_delay = 1;
-  }
-  if (start_delay &lt;= 0) {
-    start_threshold = n + (double) rate *start_delay / 1000000;
-  } else {
-    start_threshold = (double) rate *start_delay / 1000000;
-  }
-  if (start_threshold &lt; 1)
-    start_threshold = 1;
-  if (start_threshold &gt; n)
-    start_threshold = n;
-  err = snd_pcm_sw_params_set_start_threshold(handle, swparams, start_threshold);
-  if (err &lt; 0) {
-    ERRORA(&quot;Error setting start_threshold: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-  }
-
-  if (stop_delay &lt;= 0)
-    stop_threshold = buffer_size + (double) rate *stop_delay / 1000000;
-  else
-    stop_threshold = (double) rate *stop_delay / 1000000;
-
-  if (stream == SND_PCM_STREAM_CAPTURE) {
-    stop_threshold = -1;
-  }
-
-  err = snd_pcm_sw_params_set_stop_threshold(handle, swparams, stop_threshold);
-
-  if (err &lt; 0) {
-    ERRORA(&quot;Error setting stop_threshold: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-  }
-#if 0
-  err = snd_pcm_sw_params_set_xfer_align(handle, swparams, xfer_align);
-
-  if (err &lt; 0) {
-    ERRORA(&quot;Error setting xfer_align: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-  }
-#endif
-
-  if (snd_pcm_sw_params(handle, swparams) &lt; 0) {
-    ERRORA(&quot;Error installing software parameters: %s\n&quot;, SKYPIAX_P_LOG,
-           snd_strerror(err));
-  }
-
-  err = snd_pcm_poll_descriptors_count(handle);
-  if (err &lt;= 0) {
-    ERRORA(&quot;Unable to get a poll descriptors count, error is %s\n&quot;, SKYPIAX_P_LOG,
-           snd_strerror(err));
-    return NULL;
-  }
-
-  if (err != 1) {               //number of poll descriptors
-    DEBUGA_SOUND(&quot;Can't handle more than one device\n&quot;, SKYPIAX_P_LOG);
-    return NULL;
-  }
-
-  err = snd_pcm_poll_descriptors(handle, &amp;p-&gt;pfd, err);
-  if (err != 1) {
-    ERRORA(&quot;snd_pcm_poll_descriptors failed, %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-  DEBUGA_SOUND(&quot;Acquired fd %d from the poll descriptor\n&quot;, SKYPIAX_P_LOG, p-&gt;pfd.fd);
-
-  if (stream == SND_PCM_STREAM_CAPTURE) {
-    p-&gt;celliax_sound_capt_fd = p-&gt;pfd.fd;
-  }
-
-  state = snd_pcm_state(handle);
-
-  if (state != SND_PCM_STATE_RUNNING) {
-    if (state != SND_PCM_STATE_PREPARED) {
-      err = snd_pcm_prepare(handle);
-      if (err) {
-        ERRORA(&quot;snd_pcm_prepare failed, %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-        return NULL;
-      }
-      DEBUGA_SOUND(&quot;prepared!\n&quot;, SKYPIAX_P_LOG);
-    }
-    if (stream == SND_PCM_STREAM_CAPTURE) {
-      err = snd_pcm_start(handle);
-      if (err) {
-        ERRORA(&quot;snd_pcm_start failed, %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-        return NULL;
-      }
-      DEBUGA_SOUND(&quot;started!\n&quot;, SKYPIAX_P_LOG);
-    }
-  }
-  if (option_debug &gt; 1) {
-    snd_output_t *output = NULL;
-    err = snd_output_stdio_attach(&amp;output, stdout, 0);
-    if (err &lt; 0) {
-      ERRORA(&quot;snd_output_stdio_attach failed: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(err));
-    }
-    snd_pcm_dump(handle, output);
-  }
-  if (option_debug &gt; 1)
-    DEBUGA_SOUND(&quot;ALSA handle = %ld\n&quot;, SKYPIAX_P_LOG, (long int) handle);
-  return handle;
-
-}
-
-/*! \brief Read audio frames from interface */
-
-struct ast_frame *alsa_read(private_t * tech_pvt)
-{
-  static struct ast_frame f;
-  static short __buf[CELLIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2];
-  static short __buf2[(CELLIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2) * 2];
-  short *buf;
-  short *buf2;
-  static int readpos = 0;
-  static int left = CELLIAX_FRAME_SIZE;
-  snd_pcm_state_t state;
-  int r = 0;
-  int off = 0;
-  int error = 0;
-  //time_t now_timestamp;
-
-  //memset(&amp;f, 0, sizeof(struct ast_frame)); //giova
-
-  f.frametype = AST_FRAME_NULL;
-  f.subclass = 0;
-  f.samples = 0;
-  f.datalen = 0;
-  f.data = NULL;
-  f.offset = 0;
-  f.src = celliax_type;
-  f.mallocd = 0;
-  f.delivery.tv_sec = 0;
-  f.delivery.tv_usec = 0;
-
-  state = snd_pcm_state(p-&gt;alsac);
-  if (state != SND_PCM_STATE_RUNNING) {
-    DEBUGA_SOUND(&quot;ALSA read state is not SND_PCM_STATE_RUNNING\n&quot;, SKYPIAX_P_LOG);
-
-    if (state != SND_PCM_STATE_PREPARED) {
-      error = snd_pcm_prepare(p-&gt;alsac);
-      if (error) {
-        ERRORA(&quot;snd_pcm_prepare failed, %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(error));
-        return &amp;f;
-      }
-      DEBUGA_SOUND(&quot;prepared!\n&quot;, SKYPIAX_P_LOG);
-    }
-    usleep(1000);
-    error = snd_pcm_start(p-&gt;alsac);
-    if (error) {
-      ERRORA(&quot;snd_pcm_start failed, %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(error));
-      return &amp;f;
-    }
-    DEBUGA_SOUND(&quot;started!\n&quot;, SKYPIAX_P_LOG);
-    usleep(1000);
-  }
-
-  buf = __buf + AST_FRIENDLY_OFFSET / 2;
-  buf2 = __buf2 + ((AST_FRIENDLY_OFFSET / 2) * 2);
-
-  if (p-&gt;alsa_capture_is_mono) {
-    r = snd_pcm_readi(p-&gt;alsac, buf + readpos, left);
-  } else {
-    r = snd_pcm_readi(p-&gt;alsac, buf2 + (readpos * 2), left);
-
-    int a = 0;
-    int i = 0;
-    for (i = 0; i &lt; (CELLIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2) * 2;) {
-      __buf[a] = (__buf2[i] + __buf2[i + 1]) / 2;   //comment out this line to use only left
-      //__buf[a] = __buf2[i]; // enable this line to use only left
-      a++;
-      i++;
-      i++;
-    }
-  }
-
-  if (r == -EPIPE) {
-    ERRORA(&quot;XRUN read\n\n\n\n\n&quot;, SKYPIAX_P_LOG);
-    return &amp;f;
-  } else if (r == -ESTRPIPE) {
-    ERRORA(&quot;-ESTRPIPE\n&quot;, SKYPIAX_P_LOG);
-    return &amp;f;
-
-  } else if (r == -EAGAIN) {
-    DEBUGA_SOUND(&quot;ALSA read -EAGAIN, the soundcard is not ready to be read by celliax\n&quot;,
-                 SKYPIAX_P_LOG);
-    while (r == -EAGAIN) {
-      usleep(1000);
-
-      if (p-&gt;alsa_capture_is_mono) {
-        r = snd_pcm_readi(p-&gt;alsac, buf + readpos, left);
-      } else {
-        r = snd_pcm_readi(p-&gt;alsac, buf2 + (readpos * 2), left);
-
-        int a = 0;
-        int i = 0;
-        for (i = 0; i &lt; (CELLIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2) * 2;) {
-          __buf[a] = (__buf2[i] + __buf2[i + 1]) / 2;
-          a++;
-          i++;
-          i++;
-        }
-      }
-
-    }
-  } else if (r &lt; 0) {
-    WARNINGA(&quot;ALSA Read error: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(r));
-  } else if (r &gt;= 0) {
-    //DEBUGA_SOUND(&quot;read: r=%d, readpos=%d, left=%d, off=%d\n&quot;, SKYPIAX_P_LOG, r, readpos, left, off);
-    off -= r;                   //what is the meaning of this? a leftover, probably
-  }
-  /* Update positions */
-  readpos += r;
-  left -= r;
-
-  if (readpos &gt;= CELLIAX_FRAME_SIZE) {
-    /* A real frame */
-    readpos = 0;
-    left = CELLIAX_FRAME_SIZE;
-
-    f.frametype = AST_FRAME_VOICE;
-    f.subclass = AST_FORMAT_SLINEAR;
-    f.samples = CELLIAX_FRAME_SIZE;
-    f.datalen = CELLIAX_FRAME_SIZE * 2;
-    f.data = buf;
-    f.offset = AST_FRIENDLY_OFFSET;
-    f.src = celliax_type;
-    f.mallocd = 0;
-#ifdef ALSA_MONITOR
-    alsa_monitor_read((char *) buf, CELLIAX_FRAME_SIZE * 2);
-#endif
-
-  }
-  return &amp;f;
-}
-
-/*! \brief Write audio frames to interface */
-int alsa_write(private_t * tech_pvt, struct ast_frame *f)
-{
-  static char sizbuf[8000];
-  static char sizbuf2[16000];
-  static char silencebuf[8000];
-  static int sizpos = 0;
-  int len = sizpos;
-  int pos;
-  int res = 0;
-  time_t now_timestamp;
-  /* size_t frames = 0; */
-  snd_pcm_state_t state;
-  snd_pcm_sframes_t delayp1;
-  snd_pcm_sframes_t delayp2;
-
-  /* We have to digest the frame in 160-byte portions */
-  if (f-&gt;datalen &gt; sizeof(sizbuf) - sizpos) {
-    ERRORA(&quot;Frame too large\n&quot;, SKYPIAX_P_LOG);
-    res = -1;
-  } else {
-    memcpy(sizbuf + sizpos, f-&gt;data, f-&gt;datalen);
-    len += f-&gt;datalen;
-    pos = 0;
-#ifdef ALSA_MONITOR
-    alsa_monitor_write(sizbuf, len);
-#endif
-    state = snd_pcm_state(p-&gt;alsap);
-    if (state == SND_PCM_STATE_XRUN) {
-      int i;
-
-      DEBUGA_SOUND
-        (&quot;You've got an ALSA write XRUN in the past (celliax can't fill the soundcard buffer fast enough). If this happens often (not after silence or after a pause in the speech, that's OK), and appear to damage the sound quality, first check if you have some IRQ problem, maybe sharing the soundcard IRQ with a broken or heavy loaded ethernet or graphic card. Then consider to increase the alsa_periods_in_buffer (now is set to %d) for this interface in the config file\n&quot;,
-         SKYPIAX_P_LOG, p-&gt;alsa_periods_in_buffer);
-      res = snd_pcm_prepare(p-&gt;alsap);
-      if (res) {
-        ERRORA(&quot;audio play prepare failed: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(res));
-      } else {
-        res = snd_pcm_format_set_silence(celliax_format, silencebuf, len / 2);
-        if (res &lt; 0) {
-          DEBUGA_SOUND(&quot;Silence error %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(res));
-          res = -1;
-        }
-        for (i = 0; i &lt; (p-&gt;alsa_periods_in_buffer - 1); i++) {
-          res = snd_pcm_writei(p-&gt;alsap, silencebuf, len / 2);
-          if (res != len / 2) {
-            DEBUGA_SOUND(&quot;Write returned a different quantity: %d\n&quot;, SKYPIAX_P_LOG, res);
-            res = -1;
-          } else if (res &lt; 0) {
-            DEBUGA_SOUND(&quot;Write error %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(res));
-            res = -1;
-          }
-        }
-      }
-
-    }
-
-    res = snd_pcm_delay(p-&gt;alsap, &amp;delayp1);
-    if (res &lt; 0) {
-      DEBUGA_SOUND(&quot;Error %d on snd_pcm_delay: \&quot;%s\&quot;\n&quot;, SKYPIAX_P_LOG, res,
-                   snd_strerror(res));
-      res = snd_pcm_prepare(p-&gt;alsap);
-      if (res) {
-        DEBUGA_SOUND(&quot;snd_pcm_prepare failed: '%s'\n&quot;, SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      res = snd_pcm_delay(p-&gt;alsap, &amp;delayp1);
-    }
-
-    delayp2 = snd_pcm_avail_update(p-&gt;alsap);
-    if (delayp2 &lt; 0) {
-      DEBUGA_SOUND(&quot;Error %d on snd_pcm_avail_update: \&quot;%s\&quot;\n&quot;, SKYPIAX_P_LOG,
-                   (int) delayp2, snd_strerror(delayp2));
-
-      res = snd_pcm_prepare(p-&gt;alsap);
-      if (res) {
-        DEBUGA_SOUND(&quot;snd_pcm_prepare failed: '%s'\n&quot;, SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      delayp2 = snd_pcm_avail_update(p-&gt;alsap);
-    }
-
-    if (                        /* delayp1 != 0 &amp;&amp; delayp1 != 160 */
-         delayp1 &lt; 160 || delayp2 &gt; p-&gt;alsa_buffer_size) {
-
-      res = snd_pcm_prepare(p-&gt;alsap);
-      if (res) {
-        DEBUGA_SOUND
-          (&quot;snd_pcm_prepare failed while trying to prevent an ALSA write XRUN: %s, delayp1=%d, delayp2=%d\n&quot;,
-           SKYPIAX_P_LOG, snd_strerror(res), (int) delayp1, (int) delayp2);
-      } else {
-
-        int i;
-        for (i = 0; i &lt; (p-&gt;alsa_periods_in_buffer - 1); i++) {
-          res = snd_pcm_format_set_silence(celliax_format, silencebuf, len / 2);
-          if (res &lt; 0) {
-            DEBUGA_SOUND(&quot;Silence error %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(res));
-            res = -1;
-          }
-          res = snd_pcm_writei(p-&gt;alsap, silencebuf, len / 2);
-          if (res &lt; 0) {
-            DEBUGA_SOUND(&quot;Write error %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(res));
-            res = -1;
-          } else if (res != len / 2) {
-            DEBUGA_SOUND(&quot;Write returned a different quantity: %d\n&quot;, SKYPIAX_P_LOG, res);
-            res = -1;
-          }
-        }
-
-        DEBUGA_SOUND
-          (&quot;PREVENTING an ALSA write XRUN (celliax can't fill the soundcard buffer fast enough). If this happens often (not after silence or after a pause in the speech, that's OK), and appear to damage the sound quality, first check if you have some IRQ problem, maybe sharing the soundcard IRQ with a broken or heavy loaded ethernet or graphic card. Then consider to increase the alsa_periods_in_buffer (now is set to %d) for this interface in the config file. delayp1=%d, delayp2=%d\n&quot;,
-           SKYPIAX_P_LOG, p-&gt;alsa_periods_in_buffer, (int) delayp1, (int) delayp2);
-      }
-
-    }
-
-    memset(sizbuf2, 0, sizeof(sizbuf2));
-    if (p-&gt;alsa_play_is_mono) {
-      res = snd_pcm_writei(p-&gt;alsap, sizbuf, len / 2);
-    } else {
-      int a = 0;
-      int i = 0;
-      for (i = 0; i &lt; 8000;) {
-        sizbuf2[a] = sizbuf[i];
-        a++;
-        i++;
-        sizbuf2[a] = sizbuf[i];
-        a++;
-        i--;
-        sizbuf2[a] = sizbuf[i]; // comment out this line to use only left 
-        a++;
-        i++;
-        sizbuf2[a] = sizbuf[i]; // comment out this line to use only left
-        a++;
-        i++;
-      }
-      res = snd_pcm_writei(p-&gt;alsap, sizbuf2, len);
-    }
-    if (res == -EPIPE) {
-      DEBUGA_SOUND
-        (&quot;ALSA write EPIPE (XRUN) (celliax can't fill the soundcard buffer fast enough). If this happens often (not after silence or after a pause in the speech, that's OK), and appear to damage the sound quality, first check if you have some IRQ problem, maybe sharing the soundcard IRQ with a broken or heavy loaded ethernet or graphic card. Then consider to increase the alsa_periods_in_buffer (now is set to %d) for this interface in the config file. delayp1=%d, delayp2=%d\n&quot;,
-         SKYPIAX_P_LOG, p-&gt;alsa_periods_in_buffer, (int) delayp1, (int) delayp2);
-      res = snd_pcm_prepare(p-&gt;alsap);
-      if (res) {
-        ERRORA(&quot;audio play prepare failed: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(res));
-      } else {
-
-        if (p-&gt;alsa_play_is_mono) {
-          res = snd_pcm_writei(p-&gt;alsap, sizbuf, len / 2);
-        } else {
-          int a = 0;
-          int i = 0;
-          for (i = 0; i &lt; 8000;) {
-            sizbuf2[a] = sizbuf[i];
-            a++;
-            i++;
-            sizbuf2[a] = sizbuf[i];
-            a++;
-            i--;
-            sizbuf2[a] = sizbuf[i];
-            a++;
-            i++;
-            sizbuf2[a] = sizbuf[i];
-            a++;
-            i++;
-          }
-          res = snd_pcm_writei(p-&gt;alsap, sizbuf2, len);
-        }
-
-      }
-
-    } else {
-      if (res == -ESTRPIPE) {
-        ERRORA(&quot;You've got some big problems\n&quot;, SKYPIAX_P_LOG);
-      } else if (res == -EAGAIN) {
-        res = 0;
-      } else if (res &lt; 0) {
-        ERRORA(&quot;Error %d on audio write: \&quot;%s\&quot;\n&quot;, SKYPIAX_P_LOG, res,
-               snd_strerror(res));
-      }
-    }
-  }
-
-  if (p-&gt;audio_play_reset_period) {
-    time(&amp;now_timestamp);
-    if ((now_timestamp - p-&gt;audio_play_reset_timestamp) &gt; p-&gt;audio_play_reset_period) {
-      if (option_debug)
-        DEBUGA_SOUND(&quot;reset audio play\n&quot;, SKYPIAX_P_LOG);
-      res = snd_pcm_wait(p-&gt;alsap, 1000);
-      if (res &lt; 0) {
-        ERRORA(&quot;audio play wait failed: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      res = snd_pcm_drop(p-&gt;alsap);
-      if (res) {
-        ERRORA(&quot;audio play drop failed: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      res = snd_pcm_prepare(p-&gt;alsap);
-      if (res) {
-        ERRORA(&quot;audio play prepare failed: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      res = snd_pcm_wait(p-&gt;alsap, 1000);
-      if (res &lt; 0) {
-        ERRORA(&quot;audio play wait failed: %s\n&quot;, SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      time(&amp;p-&gt;audio_play_reset_timestamp);
-    }
-  }
-  res = 0;
-  if (res &gt; 0)
-    res = 0;
-  return res;
-}
-
-
-/*! \brief Write audio frames to interface */
-#endif /* CELLIAX_ALSA */
-
-#ifdef CELLIAX_PORTAUDIO
-int celliax_portaudio_devlist(private_t * tech_pvt)
-{
-  int i, numDevices;
-  const PaDeviceInfo *deviceInfo;
-
-  numDevices = Pa_GetDeviceCount();
-  if (numDevices &lt; 0) {
-    return 0;
-  }
-  for (i = 0; i &lt; numDevices; i++) {
-    deviceInfo = Pa_GetDeviceInfo(i);
-    NOTICA
-      (&quot;Found PORTAUDIO device: id=%d\tname=%s\tmax input channels=%d\tmax output channels=%d\n&quot;,
-       SKYPIAX_P_LOG, i, deviceInfo-&gt;name, deviceInfo-&gt;maxInputChannels,
-       deviceInfo-&gt;maxOutputChannels);
-  }
-
-  return numDevices;
-}
-
-int celliax_portaudio_init(private_t * tech_pvt)
-{
-  PaError err;
-  int c;
-  PaStreamParameters inputParameters, outputParameters;
-  int numdevices;
-  const PaDeviceInfo *deviceInfo;
-
-#ifndef GIOVA48
-  setenv(&quot;PA_ALSA_PLUGHW&quot;, &quot;1&quot;, 1);
-#endif // GIOVA48
-
-  err = Pa_Initialize();
-  if (err != paNoError)
-    return err;
-
-  numdevices = celliax_portaudio_devlist(p);
-
-  if (p-&gt;portaudiocindex &gt; (numdevices - 1)) {
-    ERRORA(&quot;Portaudio Capture id=%d is out of range: valid id are from 0 to %d\n&quot;,
-           SKYPIAX_P_LOG, p-&gt;portaudiocindex, (numdevices - 1));
-    return -1;
-  }
-
-  if (p-&gt;portaudiopindex &gt; (numdevices - 1)) {
-    ERRORA(&quot;Portaudio Playback id=%d is out of range: valid id are from 0 to %d\n&quot;,
-           SKYPIAX_P_LOG, p-&gt;portaudiopindex, (numdevices - 1));
-    return -1;
-  }
-  //inputParameters.device = 0;
-  if (p-&gt;portaudiocindex != -1) {
-    inputParameters.device = p-&gt;portaudiocindex;
-  } else {
-    inputParameters.device = Pa_GetDefaultInputDevice();
-  }
-  deviceInfo = Pa_GetDeviceInfo(inputParameters.device);
-  NOTICA
-    (&quot;Using INPUT PORTAUDIO device: id=%d\tname=%s\tmax input channels=%d\tmax output channels=%d\n&quot;,
-     SKYPIAX_P_LOG, inputParameters.device, deviceInfo-&gt;name,
-     deviceInfo-&gt;maxInputChannels, deviceInfo-&gt;maxOutputChannels);
-  if (deviceInfo-&gt;maxInputChannels == 0) {
-    ERRORA
-      (&quot;No INPUT channels on device: id=%d\tname=%s\tmax input channels=%d\tmax output channels=%d\n&quot;,
-       SKYPIAX_P_LOG, inputParameters.device, deviceInfo-&gt;name,
-       deviceInfo-&gt;maxInputChannels, deviceInfo-&gt;maxOutputChannels);
-    return -1;
-  }
-  inputParameters.channelCount = 1;
-  inputParameters.sampleFormat = paInt16;
-  //inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)-&gt;defaultHighInputLatency;
-  inputParameters.suggestedLatency = 0.1;
-  inputParameters.hostApiSpecificStreamInfo = NULL;
-
-  //outputParameters.device = 3;
-  if (p-&gt;portaudiopindex != -1) {
-    outputParameters.device = p-&gt;portaudiopindex;
-  } else {
-    outputParameters.device = Pa_GetDefaultOutputDevice();
-  }
-  deviceInfo = Pa_GetDeviceInfo(outputParameters.device);
-  NOTICA
-    (&quot;Using OUTPUT PORTAUDIO device: id=%d\tname=%s\tmax input channels=%d\tmax output channels=%d\n&quot;,
-     SKYPIAX_P_LOG, outputParameters.device, deviceInfo-&gt;name,
-     deviceInfo-&gt;maxInputChannels, deviceInfo-&gt;maxOutputChannels);
-  if (deviceInfo-&gt;maxOutputChannels == 0) {
-    ERRORA
-      (&quot;No OUTPUT channels on device: id=%d\tname=%s\tmax input channels=%d\tmax output channels=%d\n&quot;,
-       SKYPIAX_P_LOG, inputParameters.device, deviceInfo-&gt;name,
-       deviceInfo-&gt;maxInputChannels, deviceInfo-&gt;maxOutputChannels);
-    return -1;
-  }
-#ifndef GIOVA48
-  outputParameters.channelCount = 1;
-#else // GIOVA48
-  outputParameters.channelCount = 2;
-#endif // GIOVA48
-  outputParameters.sampleFormat = paInt16;
-  //outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)-&gt;defaultHighOutputLatency;
-  outputParameters.suggestedLatency = 0.1;
-  outputParameters.hostApiSpecificStreamInfo = NULL;
-
-/* build the pipe that will be polled on by pbx */
-  c = pipe(p-&gt;audiopipe);
-  if (c) {
-    ERRORA(&quot;Unable to create audio pipe\n&quot;, SKYPIAX_P_LOG);
-    return -1;
-  }
-  fcntl(p-&gt;audiopipe[0], F_SETFL, O_NONBLOCK);
-  fcntl(p-&gt;audiopipe[1], F_SETFL, O_NONBLOCK);
-
-  err =
-#ifndef GIOVA48
-    OpenAudioStream(&amp;p-&gt;stream, &amp;inputParameters, &amp;outputParameters, 8000,
-                    paDitherOff | paClipOff, SAMPLES_PER_FRAME, p-&gt;audiopipe[1],
-                    &amp;p-&gt;speexecho, &amp;p-&gt;speexpreprocess, &amp;p-&gt;owner);
-
-#else // GIOVA48
-    OpenAudioStream(&amp;p-&gt;stream, &amp;inputParameters, &amp;outputParameters, 48000,
-                    paDitherOff | paClipOff, SAMPLES_PER_FRAME, p-&gt;audiopipe[1],
-                    &amp;p-&gt;speexecho, &amp;p-&gt;speexpreprocess, &amp;p-&gt;owner);
-
-#endif // GIOVA48
-  if (err != paNoError) {
-    ERRORA(&quot;Unable to open audio stream: %s\n&quot;, SKYPIAX_P_LOG, Pa_GetErrorText(err));
-    return -1;
-  }
-
-/* the pipe is our audio fd for pbx to poll on */
-  p-&gt;celliax_sound_capt_fd = p-&gt;audiopipe[0];
-
-  return 0;
-}
-
-int celliax_portaudio_write(private_t * tech_pvt, struct ast_frame *f)
-{
-  int samples;
-#ifdef GIOVA48
-  //short buf[CELLIAX_FRAME_SIZE * 2];
-  short buf[3840];
-  short *buf2;
-
-  //ERRORA(&quot;1 f-&gt;datalen=: %d\n&quot;, SKYPIAX_P_LOG, f-&gt;datalen);
-
-  memset(buf, '\0', CELLIAX_FRAME_SIZE * 2);
-
-  buf2 = f-&gt;data;
-
-  int i = 0, a = 0;
-
-  for (i = 0; i &lt; f-&gt;datalen / sizeof(short); i++) {
-//stereo, 2 chan 48 -&gt; mono 8
-    buf[a] = buf2[i];
-    a++;
-    buf[a] = buf2[i];
-    a++;
-    buf[a] = buf2[i];
-    a++;
-    buf[a] = buf2[i];
-    a++;
-    buf[a] = buf2[i];
-    a++;
-    buf[a] = buf2[i];
-    a++;
-    buf[a] = buf2[i];
-    a++;
-    buf[a] = buf2[i];
-    a++;
-    buf[a] = buf2[i];
-    a++;
-    buf[a] = buf2[i];
-    a++;
-    buf[a] = buf2[i];
-    a++;
-    buf[a] = buf2[i];
-    a++;
-    /*
-     */
-  }
-  f-&gt;data = &amp;buf;
-  f-&gt;datalen = f-&gt;datalen * 6;
-  //ERRORA(&quot;2 f-&gt;datalen=: %d\n&quot;, SKYPIAX_P_LOG, f-&gt;datalen);
-  //f-&gt;datalen = f-&gt;datalen;
-#endif // GIOVA48
-
-#ifdef ASTERISK_VERSION_1_6_0_1
-  samples =
-    WriteAudioStream(p-&gt;stream, (short *) f-&gt;data.ptr,
-                     (int) (f-&gt;datalen / sizeof(short)));
-#else
-  samples =
-    WriteAudioStream(p-&gt;stream, (short *) f-&gt;data, (int) (f-&gt;datalen / sizeof(short)));
-#endif /* ASTERISK_VERSION_1_6_0_1 */
-
-  if (samples != (int) (f-&gt;datalen / sizeof(short)))
-    ERRORA(&quot;WriteAudioStream wrote: %d of %d\n&quot;, SKYPIAX_P_LOG, samples,
-           (int) (f-&gt;datalen / sizeof(short)));
-
-  return 0;
-}
-
-struct ast_frame *celliax_portaudio_read(private_t * tech_pvt)
-{
-  static struct ast_frame f;
-  static short __buf[CELLIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2];
-  short *buf;
-  static short __buf2[CELLIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2];
-  short *buf2;
-  int samples;
-  char c;
-
-  memset(__buf, '\0', (CELLIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2));
-
-  buf = __buf + AST_FRIENDLY_OFFSET / 2;
-
-  memset(__buf2, '\0', (CELLIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2));
-
-  buf2 = __buf2 + AST_FRIENDLY_OFFSET / 2;
-
-  f.frametype = AST_FRAME_NULL;
-  f.subclass = 0;
-  f.samples = 0;
-  f.datalen = 0;
-
-#ifdef ASTERISK_VERSION_1_6_0_1
-  f.data.ptr = NULL;
-#else
-  f.data = NULL;
-#endif /* ASTERISK_VERSION_1_6_0_1 */
-  f.offset = 0;
-  f.src = celliax_type;
-  f.mallocd = 0;
-  f.delivery.tv_sec = 0;
-  f.delivery.tv_usec = 0;
-
-  if ((samples = ReadAudioStream(p-&gt;stream, buf, SAMPLES_PER_FRAME)) == 0) {
-    //do nothing
-  } else {
-#ifdef GIOVA48
-    int i = 0, a = 0;
-
-    samples = samples / 6;
-    for (i = 0; i &lt; samples; i++) {
-      buf2[i] = buf[a];
-      a = a + 6;                //mono, 1 chan 48 -&gt; 8
-    }
-    buf = buf2;
-
-    /* A real frame */
-    f.frametype = AST_FRAME_VOICE;
-    f.subclass = AST_FORMAT_SLINEAR;
-    f.samples = CELLIAX_FRAME_SIZE / 6;
-    f.datalen = CELLIAX_FRAME_SIZE * 2 / 6;
-#else // GIOVA48
-    /* A real frame */
-    f.frametype = AST_FRAME_VOICE;
-    f.subclass = AST_FORMAT_SLINEAR;
-    f.samples = CELLIAX_FRAME_SIZE;
-    f.datalen = CELLIAX_FRAME_SIZE * 2;
-#endif // GIOVA48
-
-#ifdef ASTERISK_VERSION_1_6_0_1
-    f.data.ptr = buf;
-#else
-    f.data = buf;
-#endif /* ASTERISK_VERSION_1_6_0_1 */
-    f.offset = AST_FRIENDLY_OFFSET;
-    f.src = celliax_type;
-    f.mallocd = 0;
-  }
-
-  read(p-&gt;audiopipe[0], &amp;c, 1);
-
-  return &amp;f;
-}
-
-int celliax_portaudio_shutdown(private_t * tech_pvt)
-{
-  PaError err;
-
-  err = CloseAudioStream(p-&gt;stream);
-
-  if (err != paNoError)
-    ERRORA(&quot;not able to CloseAudioStream\n&quot;, SKYPIAX_P_LOG);
-
-  Pa_Terminate();
-  return 0;
-}
-#endif // CELLIAX_PORTAUDIO
-
</del><span class="cx"> int celliax_serial_sync_AT(private_t * tech_pvt)
</span><span class="cx"> {
</span><span class="cx">   usleep(10000);                /* 10msec */
</span><del>-  time(&amp;p-&gt;celliax_serial_synced_timestamp);
</del><ins>+  time(&amp;tech_pvt-&gt;celliax_serial_synced_timestamp);
</ins><span class="cx">   return 0;
</span><span class="cx"> }
</span><del>-
-int celliax_serial_getstatus_AT(private_t * tech_pvt)
-{
-  int res;
-
-  if (p-&gt;owner) {
-    if (p-&gt;owner-&gt;_state != AST_STATE_UP &amp;&amp; p-&gt;owner-&gt;_state != AST_STATE_DOWN) {
-      DEBUGA_SKYPE(&quot;No getstatus, we're neither UP nor DOWN\n&quot;, SKYPIAX_P_LOG);
-      return 0;
-    }
-  }
-
-  PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  LOKKA(&amp;p-&gt;controldev_lock);
-  res = celliax_serial_write_AT_ack(p, &quot;AT&quot;);
-  if (res) {
-    ERRORA(&quot;AT was not acknowledged, continuing but maybe there is a problem\n&quot;,
-           SKYPIAX_P_LOG);
-  }
-  usleep(1000);
-
-  if (strlen(p-&gt;at_query_battchg)) {
-    res =
-      celliax_serial_write_AT_expect(p, p-&gt;at_query_battchg, p-&gt;at_query_battchg_expect);
-    if (res) {
-      WARNINGA(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
-               p-&gt;at_query_battchg, p-&gt;at_query_battchg_expect);
-    }
-    usleep(1000);
-  }
-
-  if (strlen(p-&gt;at_query_signal)) {
-    res =
-      celliax_serial_write_AT_expect(p, p-&gt;at_query_signal, p-&gt;at_query_signal_expect);
-    if (res) {
-      WARNINGA(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
-               p-&gt;at_query_signal, p-&gt;at_query_signal_expect);
-    }
-    usleep(1000);
-  }
-  //FIXME all the following commands in config!
-
-  if (p-&gt;sms_cnmi_not_supported) {
-    res = celliax_serial_write_AT_ack(p, &quot;AT+MMGL=\&quot;HEADER ONLY\&quot;&quot;);
-    if (res) {
-      WARNINGA
-        (&quot;%s does not get %s from the modem, maybe a long msg is incoming. If this cellmodem is not a Motorola, you are arriving here because your cellmodem do not supports CNMI kind of incoming SMS alert; please let it know to the developers of Celliax. If this cellmodem is a Motorola and this message keeps repeating, and you cannot correctly receive SMSs from this interface, please manually clean all messages from the cellmodem/SIM. Continuing.\n&quot;,
-         SKYPIAX_P_LOG, &quot;AT+MMGL=\&quot;HEADER ONLY\&quot;&quot;, &quot;OK&quot;);
-    } else {
-      usleep(1000);
-      if (p-&gt;unread_sms_msg_id) {
-        char at_command[256];
-
-        if (p-&gt;no_ucs2 == 0) {
-          res = celliax_serial_write_AT_ack(p, &quot;AT+CSCS=\&quot;UCS2\&quot;&quot;);
-          if (res) {
-            ERRORA
-              (&quot;AT+CSCS=\&quot;UCS2\&quot; (set TE messages to ucs2)  do not got OK from the phone\n&quot;,
-               SKYPIAX_P_LOG);
-            memset(p-&gt;sms_message, 0, sizeof(p-&gt;sms_message));
-          }
-        }
-
-        memset(at_command, 0, sizeof(at_command));
-        sprintf(at_command, &quot;AT+CMGR=%d&quot;, p-&gt;unread_sms_msg_id);
-        memset(p-&gt;sms_message, 0, sizeof(p-&gt;sms_message));
-
-        p-&gt;reading_sms_msg = 1;
-        res = celliax_serial_write_AT_ack(p, at_command);
-        p-&gt;reading_sms_msg = 0;
-        if (res) {
-          ERRORA
-            (&quot;AT+CMGR (read SMS) do not got OK from the phone, message sent was:|||%s|||\n&quot;,
-             SKYPIAX_P_LOG, at_command);
-        }
-        res = celliax_serial_write_AT_ack(p, &quot;AT+CSCS=\&quot;GSM\&quot;&quot;);
-        if (res) {
-          ERRORA
-            (&quot;AT+CSCS=\&quot;GSM\&quot; (set TE messages to GSM) do not got OK from the phone\n&quot;,
-             SKYPIAX_P_LOG);
-        }
-        memset(at_command, 0, sizeof(at_command));
-        sprintf(at_command, &quot;AT+CMGD=%d&quot;, p-&gt;unread_sms_msg_id);    /* delete the message */
-        p-&gt;unread_sms_msg_id = 0;
-        res = celliax_serial_write_AT_ack(p, at_command);
-        if (res) {
-          ERRORA
-            (&quot;AT+CMGD (Delete SMS) do not got OK from the phone, message sent was:|||%s|||\n&quot;,
-             SKYPIAX_P_LOG, at_command);
-        }
-
-        if (strlen(p-&gt;sms_message)) {
-
-          manager_event(EVENT_FLAG_SYSTEM, &quot;CELLIAXincomingsms&quot;,
-                        &quot;Interface: %s\r\nSMS_Message: %s\r\n&quot;, p-&gt;name, p-&gt;sms_message);
-
-          if (strlen(p-&gt;sms_receiving_program)) {
-            int fd1[2];
-            pid_t pid1;
-            char *arg1[] = { p-&gt;sms_receiving_program, (char *) NULL };
-            int i;
-
-            NOTICA(&quot;incoming SMS message:&gt;&gt;&gt;%s&lt;&lt;&lt;\n&quot;, SKYPIAX_P_LOG, p-&gt;sms_message);
-            pipe(fd1);
-            pid1 = fork();
-
-            if (pid1 == 0) {    //child
-              int err;
-
-              dup2(fd1[0], 0);  // Connect stdin to pipe output
-              close(fd1[1]);    // close input pipe side
-              setsid();         //session id
-              err = execvp(arg1[0], arg1);  //exec our program, with stdin connected to pipe output
-              if (err) {
-                ERRORA
-                  (&quot;'sms_receiving_program' is set in config file to '%s', and it gave us back this error: %d, (%s). SMS received was:---%s---\n&quot;,
-                   SKYPIAX_P_LOG, p-&gt;sms_receiving_program, err, strerror(errno),
-                   p-&gt;sms_message);
-              }
-              close(fd1[0]);    // close output pipe side
-            }                   //starting here continue the parent
-            close(fd1[0]);      // close output pipe side
-            // write the msg on the pipe input
-            for (i = 0; i &lt; strlen(p-&gt;sms_message); i++) {
-              write(fd1[1], &amp;p-&gt;sms_message[i], 1);
-            }
-            close(fd1[1]);      // close pipe input, let our program know we've finished
-          } else {
-            ERRORA
-              (&quot;got SMS incoming message, but 'sms_receiving_program' is not set in config file. SMS received was:---%s---\n&quot;,
-               SKYPIAX_P_LOG, p-&gt;sms_message);
-          }
-        }
-#if 1                           //is this one needed? maybe it can interrupt an incoming call that is just to announce itself
-        if (p-&gt;phone_callflow == CALLFLOW_CALL_IDLE
-            &amp;&amp; p-&gt;interface_state == AST_STATE_DOWN &amp;&amp; p-&gt;owner == NULL) {
-          /* we're not in a call, neither calling */
-          res = celliax_serial_write_AT_ack(p, &quot;AT+CKPD=\&quot;EEE\&quot;&quot;);
-          if (res) {
-            ERRORA
-              (&quot;AT+CKPD=\&quot;EEE\&quot; (cellphone screen back to user) do not got OK from the phone\n&quot;,
-               SKYPIAX_P_LOG);
-          }
-        }
-#endif
-      }
-    }
-  }
-
-  UNLOCKA(&amp;p-&gt;controldev_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  return 0;
-}
-
</del><span class="cx"> int celliax_serial_read_AT(private_t * tech_pvt, int look_for_ack, int timeout_usec,
</span><span class="cx">                            int timeout_sec, const char *expected_string, int expect_crlf)
</span><span class="cx"> {
</span><span class="lines">@@ -3312,33 +1863,33 @@
</span><span class="cx">   int la_read = 0;
</span><span class="cx"> 
</span><span class="cx">   FD_ZERO(&amp;read_fds);
</span><del>-  FD_SET(p-&gt;controldevfd, &amp;read_fds);
</del><ins>+  FD_SET(tech_pvt-&gt;controldevfd, &amp;read_fds);
</ins><span class="cx"> 
</span><del>-  //NOTICA (&quot; INSIDE this celliax_serial_device %s \n&quot;, SKYPIAX_P_LOG, p-&gt;controldevice_name);
</del><ins>+  //NOTICA (&quot; INSIDE this celliax_serial_device %s \n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;controldevice_name);
</ins><span class="cx">   tmp_answer_ptr = tmp_answer;
</span><span class="cx">   memset(tmp_answer, 0, sizeof(char) * AT_BUFSIZ);
</span><span class="cx"> 
</span><span class="cx">   timeout.tv_sec = timeout_sec;
</span><span class="cx">   timeout.tv_usec = timeout_usec;
</span><del>-  PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  LOKKA(&amp;p-&gt;controldev_lock);
</del><ins>+  PUSHA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  LOKKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx"> 
</span><del>-  while ((select_err = select(p-&gt;controldevfd + 1, &amp;read_fds, NULL, NULL, &amp;timeout)) &gt; 0) {
</del><ins>+  while ((select_err = select(tech_pvt-&gt;controldevfd + 1, &amp;read_fds, NULL, NULL, &amp;timeout)) &gt; 0) {
</ins><span class="cx">     timeout.tv_sec = timeout_sec;   //reset the timeout, linux modify it
</span><span class="cx">     timeout.tv_usec = timeout_usec; //reset the timeout, linux modify it
</span><span class="cx">     read_count =
</span><del>-      read(p-&gt;controldevfd, tmp_answer_ptr, AT_BUFSIZ - (tmp_answer_ptr - tmp_answer));
</del><ins>+      read(tech_pvt-&gt;controldevfd, tmp_answer_ptr, AT_BUFSIZ - (tmp_answer_ptr - tmp_answer));
</ins><span class="cx"> 
</span><span class="cx">     if (read_count == 0) {
</span><span class="cx">       ERRORA
</span><span class="cx">         (&quot;read 0 bytes!!! Nenormalno! Marking this celliax_serial_device %s as dead, andif it is owned by a channel, hanging up. Maybe the phone is stuck, switched off, power down or battery exhausted\n&quot;,
</span><del>-         SKYPIAX_P_LOG, p-&gt;controldevice_name);
-      p-&gt;controldev_dead = 1;
-      close(p-&gt;controldevfd);
-      UNLOCKA(&amp;p-&gt;controldev_lock);
-      if (p-&gt;owner) {
-        p-&gt;owner-&gt;hangupcause = AST_CAUSE_FAILURE;
-        celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
</del><ins>+         SKYPIAX_P_LOG, tech_pvt-&gt;controldevice_name);
+      tech_pvt-&gt;controldev_dead = 1;
+      close(tech_pvt-&gt;controldevfd);
+      UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+      if (tech_pvt-&gt;owner) {
+        tech_pvt-&gt;owner-&gt;hangupcause = SKYPIAX_CAUSE_FAILURE;
+        celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_HANGUP);
</ins><span class="cx">       }
</span><span class="cx">       return -1;
</span><span class="cx">     }
</span><span class="lines">@@ -3356,20 +1907,20 @@
</span><span class="cx">     strcpy(tmp_answer2, tmp_answer);
</span><span class="cx">     if ((token_ptr = strtok(tmp_answer2, &quot;\n\r&quot;))) {
</span><span class="cx">       last_line_ptr = token_ptr;
</span><del>-      strncpy(p-&gt;line_array.result[la_counter], token_ptr, AT_MESG_MAX_LENGTH);
</del><ins>+      strncpy(tech_pvt-&gt;line_array.result[la_counter], token_ptr, AT_MESG_MAX_LENGTH);
</ins><span class="cx">       if (strlen(token_ptr) &gt; AT_MESG_MAX_LENGTH) {
</span><span class="cx">         WARNINGA
</span><span class="cx">           (&quot;AT mesg longer than buffer, original message was: |%s|, in buffer only: |%s|\n&quot;,
</span><del>-           SKYPIAX_P_LOG, token_ptr, p-&gt;line_array.result[la_counter]);
</del><ins>+           SKYPIAX_P_LOG, token_ptr, tech_pvt-&gt;line_array.result[la_counter]);
</ins><span class="cx">       }
</span><span class="cx">       la_counter++;
</span><span class="cx">       while ((token_ptr = strtok(NULL, &quot;\n\r&quot;))) {
</span><span class="cx">         last_line_ptr = token_ptr;
</span><del>-        strncpy(p-&gt;line_array.result[la_counter], token_ptr, AT_MESG_MAX_LENGTH);
</del><ins>+        strncpy(tech_pvt-&gt;line_array.result[la_counter], token_ptr, AT_MESG_MAX_LENGTH);
</ins><span class="cx">         if (strlen(token_ptr) &gt; AT_MESG_MAX_LENGTH) {
</span><span class="cx">           WARNINGA
</span><span class="cx">             (&quot;AT mesg longer than buffer, original message was: |%s|, in buffer only: |%s|\n&quot;,
</span><del>-             SKYPIAX_P_LOG, token_ptr, p-&gt;line_array.result[la_counter]);
</del><ins>+             SKYPIAX_P_LOG, token_ptr, tech_pvt-&gt;line_array.result[la_counter]);
</ins><span class="cx">         }
</span><span class="cx">         la_counter++;
</span><span class="cx">       }
</span><span class="lines">@@ -3389,7 +1940,7 @@
</span><span class="cx">     if (expected_string &amp;&amp; !expect_crlf
</span><span class="cx">         &amp;&amp; !memcmp(last_line_ptr, expected_string, strlen(expected_string))
</span><span class="cx">       ) {
</span><del>-      strncpy(p-&gt;line_array.result[la_counter], last_line_ptr, AT_MESG_MAX_LENGTH);
</del><ins>+      strncpy(tech_pvt-&gt;line_array.result[la_counter], last_line_ptr, AT_MESG_MAX_LENGTH);
</ins><span class="cx">       // match expected string -&gt; accept it withtout CRLF
</span><span class="cx">       la_counter++;
</span><span class="cx"> 
</span><span class="lines">@@ -3402,194 +1953,194 @@
</span><span class="cx">     /* let's list the complete lines read so far, without re-listing the lines that has yet been listed */
</span><span class="cx">     if (option_debug &gt; 1) {
</span><span class="cx">       for (i = la_read; i &lt; la_counter; i++)
</span><del>-        DEBUGA_SKYPE(&quot;Read line %d: |%s|\n&quot;, SKYPIAX_P_LOG, i, p-&gt;line_array.result[i]);
</del><ins>+        DEBUGA_SKYPE(&quot;Read line %d: |%s|\n&quot;, SKYPIAX_P_LOG, i, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     /* let's interpret the complete lines read so far (WITHOUT looking for OK, ERROR, and EXPECTED_STRING), without re-interpreting the lines that has been yet interpreted, so we're sure we don't miss anything */
</span><span class="cx">     for (i = la_read; i &lt; la_counter; i++) {
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], &quot;RING&quot;) == 0)) {
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], &quot;RING&quot;) == 0)) {
</ins><span class="cx">         /* with first RING we wait for callid */
</span><del>-        gettimeofday(&amp;(p-&gt;ringtime), NULL);
</del><ins>+        gettimeofday(&amp;(tech_pvt-&gt;ringtime), NULL);
</ins><span class="cx">         /* give CALLID (+CLIP) a chance, wait for the next RING before answering */
</span><del>-        if (p-&gt;phone_callflow == CALLFLOW_INCOMING_RING) {
</del><ins>+        if (tech_pvt-&gt;phone_callflow == CALLFLOW_INCOMING_RING) {
</ins><span class="cx">           /* we're at the second ring, set the interface state, will be answered by celliax_do_monitor */
</span><del>-          DEBUGA_SKYPE(&quot;|%s| got second RING\n&quot;, SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
-          p-&gt;interface_state = AST_STATE_RING;
</del><ins>+          DEBUGA_SKYPE(&quot;|%s| got second RING\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
+          tech_pvt-&gt;interface_state = SKYPIAX_STATE_RING;
</ins><span class="cx">         } else {
</span><span class="cx">           /* we're at the first ring, so there is no CALLID yet thus clean the previous one 
</span><span class="cx">              just in case we don't receive the caller identification in this new call */
</span><del>-          memset(p-&gt;callid_name, 0, sizeof(p-&gt;callid_name));
-          memset(p-&gt;callid_number, 0, sizeof(p-&gt;callid_number));
</del><ins>+          memset(tech_pvt-&gt;callid_name, 0, sizeof(tech_pvt-&gt;callid_name));
+          memset(tech_pvt-&gt;callid_number, 0, sizeof(tech_pvt-&gt;callid_number));
</ins><span class="cx">           /* only send AT+CLCC? if the device previously reported its support */
</span><del>-          if (p-&gt;at_has_clcc != 0) {
</del><ins>+          if (tech_pvt-&gt;at_has_clcc != 0) {
</ins><span class="cx">             /* we're at the first ring, try to get CALLID (with +CLCC) */
</span><span class="cx">             DEBUGA_SKYPE(&quot;|%s| got first RING, sending AT+CLCC?\n&quot;, SKYPIAX_P_LOG,
</span><del>-                      p-&gt;line_array.result[i]);
-            res = celliax_serial_write_AT_noack(p, &quot;AT+CLCC?&quot;);
</del><ins>+                      tech_pvt-&gt;line_array.result[i]);
+            res = celliax_serial_write_AT_noack(tech_pvt, &quot;AT+CLCC?&quot;);
</ins><span class="cx">             if (res) {
</span><span class="cx">               ERRORA(&quot;AT+CLCC? (call list) was not correctly sent to the phone\n&quot;,
</span><span class="cx">                      SKYPIAX_P_LOG);
</span><span class="cx">             }
</span><span class="cx">           } else {
</span><span class="cx">             DEBUGA_SKYPE(&quot;|%s| got first RING, but not sending AT+CLCC? as this device &quot;
</span><del>-                      &quot;seems not to support\n&quot;, SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
</del><ins>+                      &quot;seems not to support\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">           }
</span><span class="cx">         }
</span><del>-        p-&gt;phone_callflow = CALLFLOW_INCOMING_RING;
</del><ins>+        tech_pvt-&gt;phone_callflow = CALLFLOW_INCOMING_RING;
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;+CLCC&quot;, 5) == 0)) {
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CLCC&quot;, 5) == 0)) {
</ins><span class="cx">         /* with clcc we wait for clip */
</span><del>-        memset(p-&gt;callid_name, 0, sizeof(p-&gt;callid_name));
-        memset(p-&gt;callid_number, 0, sizeof(p-&gt;callid_number));
</del><ins>+        memset(tech_pvt-&gt;callid_name, 0, sizeof(tech_pvt-&gt;callid_name));
+        memset(tech_pvt-&gt;callid_number, 0, sizeof(tech_pvt-&gt;callid_number));
</ins><span class="cx">         int commacount = 0;
</span><span class="cx">         int a = 0;
</span><span class="cx">         int b = 0;
</span><span class="cx">         int c = 0;
</span><span class="cx"> 
</span><del>-        for (a = 0; a &lt; strlen(p-&gt;line_array.result[i]); a++) {
</del><ins>+        for (a = 0; a &lt; strlen(tech_pvt-&gt;line_array.result[i]); a++) {
</ins><span class="cx"> 
</span><del>-          if (p-&gt;line_array.result[i][a] == ',') {
</del><ins>+          if (tech_pvt-&gt;line_array.result[i][a] == ',') {
</ins><span class="cx">             commacount++;
</span><span class="cx">           }
</span><span class="cx">           if (commacount == 5) {
</span><del>-            if (p-&gt;line_array.result[i][a] != ',' &amp;&amp; p-&gt;line_array.result[i][a] != '&quot;') {
-              p-&gt;callid_number[b] = p-&gt;line_array.result[i][a];
</del><ins>+            if (tech_pvt-&gt;line_array.result[i][a] != ',' &amp;&amp; tech_pvt-&gt;line_array.result[i][a] != '&quot;') {
+              tech_pvt-&gt;callid_number[b] = tech_pvt-&gt;line_array.result[i][a];
</ins><span class="cx">               b++;
</span><span class="cx">             }
</span><span class="cx">           }
</span><span class="cx">           if (commacount == 7) {
</span><del>-            if (p-&gt;line_array.result[i][a] != ',' &amp;&amp; p-&gt;line_array.result[i][a] != '&quot;') {
-              p-&gt;callid_name[c] = p-&gt;line_array.result[i][a];
</del><ins>+            if (tech_pvt-&gt;line_array.result[i][a] != ',' &amp;&amp; tech_pvt-&gt;line_array.result[i][a] != '&quot;') {
+              tech_pvt-&gt;callid_name[c] = tech_pvt-&gt;line_array.result[i][a];
</ins><span class="cx">               c++;
</span><span class="cx">             }
</span><span class="cx">           }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        p-&gt;phone_callflow = CALLFLOW_INCOMING_RING;
</del><ins>+        tech_pvt-&gt;phone_callflow = CALLFLOW_INCOMING_RING;
</ins><span class="cx">         DEBUGA_SKYPE(&quot;|%s| CLCC CALLID: name is %s, number is %s\n&quot;, SKYPIAX_P_LOG,
</span><del>-                  p-&gt;line_array.result[i],
-                  p-&gt;callid_name[0] ? p-&gt;callid_name : &quot;not available&quot;,
-                  p-&gt;callid_number[0] ? p-&gt;callid_number : &quot;not available&quot;);
</del><ins>+                  tech_pvt-&gt;line_array.result[i],
+                  tech_pvt-&gt;callid_name[0] ? tech_pvt-&gt;callid_name : &quot;not available&quot;,
+                  tech_pvt-&gt;callid_number[0] ? tech_pvt-&gt;callid_number : &quot;not available&quot;);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;+CLIP&quot;, 5) == 0)) {
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CLIP&quot;, 5) == 0)) {
</ins><span class="cx">         /* with CLIP, we want to answer right away */
</span><del>-        memset(p-&gt;callid_name, 0, sizeof(p-&gt;callid_name));
-        memset(p-&gt;callid_number, 0, sizeof(p-&gt;callid_number));
</del><ins>+        memset(tech_pvt-&gt;callid_name, 0, sizeof(tech_pvt-&gt;callid_name));
+        memset(tech_pvt-&gt;callid_number, 0, sizeof(tech_pvt-&gt;callid_number));
</ins><span class="cx"> 
</span><span class="cx">         int commacount = 0;
</span><span class="cx">         int a = 0;
</span><span class="cx">         int b = 0;
</span><span class="cx">         int c = 0;
</span><span class="cx"> 
</span><del>-        for (a = 7; a &lt; strlen(p-&gt;line_array.result[i]); a++) {
-          if (p-&gt;line_array.result[i][a] == ',') {
</del><ins>+        for (a = 7; a &lt; strlen(tech_pvt-&gt;line_array.result[i]); a++) {
+          if (tech_pvt-&gt;line_array.result[i][a] == ',') {
</ins><span class="cx">             commacount++;
</span><span class="cx">           }
</span><span class="cx">           if (commacount == 0) {
</span><del>-            if (p-&gt;line_array.result[i][a] != ',' &amp;&amp; p-&gt;line_array.result[i][a] != '&quot;') {
-              p-&gt;callid_number[b] = p-&gt;line_array.result[i][a];
</del><ins>+            if (tech_pvt-&gt;line_array.result[i][a] != ',' &amp;&amp; tech_pvt-&gt;line_array.result[i][a] != '&quot;') {
+              tech_pvt-&gt;callid_number[b] = tech_pvt-&gt;line_array.result[i][a];
</ins><span class="cx">               b++;
</span><span class="cx">             }
</span><span class="cx">           }
</span><span class="cx">           if (commacount == 4) {
</span><del>-            if (p-&gt;line_array.result[i][a] != ',' &amp;&amp; p-&gt;line_array.result[i][a] != '&quot;') {
-              p-&gt;callid_name[c] = p-&gt;line_array.result[i][a];
</del><ins>+            if (tech_pvt-&gt;line_array.result[i][a] != ',' &amp;&amp; tech_pvt-&gt;line_array.result[i][a] != '&quot;') {
+              tech_pvt-&gt;callid_name[c] = tech_pvt-&gt;line_array.result[i][a];
</ins><span class="cx">               c++;
</span><span class="cx">             }
</span><span class="cx">           }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if (p-&gt;interface_state != AST_STATE_RING) {
-          gettimeofday(&amp;(p-&gt;call_incoming_time), NULL);
-          DEBUGA_SKYPE(&quot;AST_STATE_RING call_incoming_time.tv_sec=%ld\n&quot;,
-                    SKYPIAX_P_LOG, p-&gt;call_incoming_time.tv_sec);
</del><ins>+        if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_RING) {
+          gettimeofday(&amp;(tech_pvt-&gt;call_incoming_time), NULL);
+          DEBUGA_SKYPE(&quot;SKYPIAX_STATE_RING call_incoming_time.tv_sec=%ld\n&quot;,
+                    SKYPIAX_P_LOG, tech_pvt-&gt;call_incoming_time.tv_sec);
</ins><span class="cx"> 
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        p-&gt;interface_state = AST_STATE_RING;
-        p-&gt;phone_callflow = CALLFLOW_INCOMING_RING;
</del><ins>+        tech_pvt-&gt;interface_state = SKYPIAX_STATE_RING;
+        tech_pvt-&gt;phone_callflow = CALLFLOW_INCOMING_RING;
</ins><span class="cx">         DEBUGA_SKYPE(&quot;|%s| CLIP INCOMING CALLID: name is %s, number is %s\n&quot;, SKYPIAX_P_LOG,
</span><del>-                  p-&gt;line_array.result[i],
-                  p-&gt;callid_name[0] != 1 ? p-&gt;callid_name : &quot;not available&quot;,
-                  p-&gt;callid_number[0] ? p-&gt;callid_number : &quot;not available&quot;);
</del><ins>+                  tech_pvt-&gt;line_array.result[i],
+                  tech_pvt-&gt;callid_name[0] != 1 ? tech_pvt-&gt;callid_name : &quot;not available&quot;,
+                  tech_pvt-&gt;callid_number[0] ? tech_pvt-&gt;callid_number : &quot;not available&quot;);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], &quot;BUSY&quot;) == 0)) {
-        p-&gt;phone_callflow = CALLFLOW_CALL_LINEBUSY;
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], &quot;BUSY&quot;) == 0)) {
+        tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_LINEBUSY;
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| CALLFLOW_CALL_LINEBUSY\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
-        if (p-&gt;interface_state != AST_STATE_DOWN &amp;&amp; p-&gt;owner) {
-          ast_setstate(p-&gt;owner, AST_STATE_BUSY);
-          celliax_queue_control(p-&gt;owner, AST_CONTROL_BUSY);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
+        if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN &amp;&amp; tech_pvt-&gt;owner) {
+          ast_setstate(tech_pvt-&gt;owner, SKYPIAX_STATE_BUSY);
+          celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_BUSY);
</ins><span class="cx">         } else {
</span><span class="cx">           ERRORA(&quot;Why BUSY now?\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">         }
</span><span class="cx">       }
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], &quot;NO ANSWER&quot;) == 0)) {
-        p-&gt;phone_callflow = CALLFLOW_CALL_NOANSWER;
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], &quot;NO ANSWER&quot;) == 0)) {
+        tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_NOANSWER;
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| CALLFLOW_CALL_NOANSWER\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
-        if (p-&gt;interface_state != AST_STATE_DOWN &amp;&amp; p-&gt;owner) {
-          p-&gt;owner-&gt;hangupcause = AST_CAUSE_NO_ANSWER;
-          celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
+        if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN &amp;&amp; tech_pvt-&gt;owner) {
+          tech_pvt-&gt;owner-&gt;hangupcause = SKYPIAX_CAUSE_NO_ANSWER;
+          celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_HANGUP);
</ins><span class="cx">         } else {
</span><span class="cx">           ERRORA(&quot;Why NO ANSWER now?\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">         }
</span><span class="cx">       }
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], &quot;NO CARRIER&quot;) == 0)) {
-        p-&gt;phone_callflow = CALLFLOW_CALL_NOCARRIER;
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], &quot;NO CARRIER&quot;) == 0)) {
+        tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_NOCARRIER;
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| CALLFLOW_CALL_NOCARRIER\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
-        if (p-&gt;interface_state != AST_STATE_DOWN &amp;&amp; p-&gt;owner) {
-          p-&gt;owner-&gt;hangupcause = AST_CAUSE_FAILURE;
-          celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
+        if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN &amp;&amp; tech_pvt-&gt;owner) {
+          tech_pvt-&gt;owner-&gt;hangupcause = SKYPIAX_CAUSE_FAILURE;
+          celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_HANGUP);
</ins><span class="cx">         } else {
</span><span class="cx">           ERRORA(&quot;Why NO CARRIER now?\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">         }
</span><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;+CBC:&quot;, 5) == 0)) {
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CBC:&quot;, 5) == 0)) {
</ins><span class="cx">         int power_supply, battery_strenght, err;
</span><span class="cx"> 
</span><span class="cx">         power_supply = battery_strenght = 0;
</span><span class="cx"> 
</span><span class="cx">         err =
</span><del>-          sscanf(&amp;p-&gt;line_array.result[i][6], &quot;%d,%d&quot;, &amp;power_supply, &amp;battery_strenght);
</del><ins>+          sscanf(&amp;tech_pvt-&gt;line_array.result[i][6], &quot;%d,%d&quot;, &amp;power_supply, &amp;battery_strenght);
</ins><span class="cx">         if (err &lt; 2) {
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| is not formatted as: |+CBC: xx,yy| now trying  |+CBC:xx,yy|\n&quot;,
</span><del>-                    SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
</del><ins>+                    SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx"> 
</span><span class="cx">           err =
</span><del>-            sscanf(&amp;p-&gt;line_array.result[i][5], &quot;%d,%d&quot;, &amp;power_supply,
</del><ins>+            sscanf(&amp;tech_pvt-&gt;line_array.result[i][5], &quot;%d,%d&quot;, &amp;power_supply,
</ins><span class="cx">                    &amp;battery_strenght);
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| +CBC: Powered by %s, battery strenght=%d\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i], power_supply ? &quot;power supply&quot; : &quot;battery&quot;,
</del><ins>+                    tech_pvt-&gt;line_array.result[i], power_supply ? &quot;power supply&quot; : &quot;battery&quot;,
</ins><span class="cx">                     battery_strenght);
</span><span class="cx"> 
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if (err &lt; 2) {
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| is not formatted as: |+CBC:xx,yy| giving up\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         else {
</span><span class="cx">           if (option_debug &gt; 1)
</span><span class="cx">             DEBUGA_SKYPE(&quot;|%s| +CBC: Powered by %s, battery strenght=%d\n&quot;, SKYPIAX_P_LOG,
</span><del>-                      p-&gt;line_array.result[i], power_supply ? &quot;power supply&quot; : &quot;battery&quot;,
</del><ins>+                      tech_pvt-&gt;line_array.result[i], power_supply ? &quot;power supply&quot; : &quot;battery&quot;,
</ins><span class="cx">                       battery_strenght);
</span><span class="cx">           if (!power_supply) {
</span><span class="cx">             if (battery_strenght &lt; 10) {
</span><span class="cx">               ERRORA(&quot;|%s| BATTERY ALMOST EXHAUSTED\n&quot;, SKYPIAX_P_LOG,
</span><del>-                     p-&gt;line_array.result[i]);
</del><ins>+                     tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">             } else if (battery_strenght &lt; 20) {
</span><del>-              WARNINGA(&quot;|%s| BATTERY LOW\n&quot;, SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
</del><ins>+              WARNINGA(&quot;|%s| BATTERY LOW\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx"> 
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="lines">@@ -3598,197 +2149,197 @@
</span><span class="cx"> 
</span><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;+CSQ:&quot;, 5) == 0)) {
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CSQ:&quot;, 5) == 0)) {
</ins><span class="cx">         int signal_quality, ber, err;
</span><span class="cx"> 
</span><span class="cx">         signal_quality = ber = 0;
</span><span class="cx"> 
</span><del>-        err = sscanf(&amp;p-&gt;line_array.result[i][6], &quot;%d,%d&quot;, &amp;signal_quality, &amp;ber);
</del><ins>+        err = sscanf(&amp;tech_pvt-&gt;line_array.result[i][6], &quot;%d,%d&quot;, &amp;signal_quality, &amp;ber);
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| +CSQ: Signal Quality: %d, Error Rate=%d\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i], signal_quality, ber);
</del><ins>+                    tech_pvt-&gt;line_array.result[i], signal_quality, ber);
</ins><span class="cx">         if (err &lt; 2) {
</span><span class="cx">           ERRORA(&quot;|%s| is not formatted as: |+CSQ: xx,yy|\n&quot;, SKYPIAX_P_LOG,
</span><del>-                 p-&gt;line_array.result[i]);
</del><ins>+                 tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">         } else {
</span><span class="cx">           if (signal_quality &lt; 11 || signal_quality == 99) {
</span><span class="cx">             WARNINGA
</span><span class="cx">               (&quot;|%s| CELLPHONE GETS ALMOST NO SIGNAL, consider to move it or additional antenna\n&quot;,
</span><del>-               SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
</del><ins>+               SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">           } else if (signal_quality &lt; 15) {
</span><span class="cx">             WARNINGA(&quot;|%s| CELLPHONE GETS SIGNAL LOW\n&quot;, SKYPIAX_P_LOG,
</span><del>-                     p-&gt;line_array.result[i]);
</del><ins>+                     tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx"> 
</span><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">       }
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;+CMGW:&quot;, 6) == 0)) {
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CMGW:&quot;, 6) == 0)) {
</ins><span class="cx">         int err;
</span><span class="cx"> 
</span><del>-        err = sscanf(&amp;p-&gt;line_array.result[i][7], &quot;%s&quot;, p-&gt;at_cmgw);
-        DEBUGA_SKYPE(&quot;|%s| +CMGW: %s\n&quot;, SKYPIAX_P_LOG, p-&gt;line_array.result[i], p-&gt;at_cmgw);
</del><ins>+        err = sscanf(&amp;tech_pvt-&gt;line_array.result[i][7], &quot;%s&quot;, tech_pvt-&gt;at_cmgw);
+        DEBUGA_SKYPE(&quot;|%s| +CMGW: %s\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_cmgw);
</ins><span class="cx">         if (err &lt; 1) {
</span><span class="cx">           ERRORA(&quot;|%s| is not formatted as: |+CMGW: xxxx|\n&quot;, SKYPIAX_P_LOG,
</span><del>-                 p-&gt;line_array.result[i]);
</del><ins>+                 tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">       }
</span><span class="cx"> 
</span><span class="cx">       /* at_call_* are unsolicited messages sent by the modem to signal us about call processing activity and events */
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_call_idle) == 0)) {
-        p-&gt;phone_callflow = CALLFLOW_CALL_IDLE;
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_call_idle) == 0)) {
+        tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_IDLE;
</ins><span class="cx">         if (option_debug &gt; 1)
</span><del>-          DEBUGA_SKYPE(&quot;|%s| CALLFLOW_CALL_IDLE\n&quot;, SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
-        if (p-&gt;interface_state != AST_STATE_DOWN &amp;&amp; p-&gt;owner) {
</del><ins>+          DEBUGA_SKYPE(&quot;|%s| CALLFLOW_CALL_IDLE\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
+        if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN &amp;&amp; tech_pvt-&gt;owner) {
</ins><span class="cx">           DEBUGA_SKYPE(&quot;just received a remote HANGUP\n&quot;, SKYPIAX_P_LOG);
</span><del>-          p-&gt;owner-&gt;hangupcause = AST_CAUSE_NORMAL;
-          celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
-          DEBUGA_SKYPE(&quot;just sent AST_CONTROL_HANGUP\n&quot;, SKYPIAX_P_LOG);
</del><ins>+          tech_pvt-&gt;owner-&gt;hangupcause = SKYPIAX_CAUSE_NORMAL;
+          celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_HANGUP);
+          DEBUGA_SKYPE(&quot;just sent SKYPIAX_CONTROL_HANGUP\n&quot;, SKYPIAX_P_LOG);
</ins><span class="cx">         }
</span><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_call_incoming) == 0)) {
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_call_incoming) == 0)) {
</ins><span class="cx"> 
</span><span class="cx">         //char list_command[64];
</span><span class="cx"> 
</span><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| CALLFLOW_CALL_INCOMING\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx"> 
</span><del>-        if (p-&gt;phone_callflow != CALLFLOW_CALL_INCOMING
-            &amp;&amp; p-&gt;phone_callflow != CALLFLOW_INCOMING_RING) {
</del><ins>+        if (tech_pvt-&gt;phone_callflow != CALLFLOW_CALL_INCOMING
+            &amp;&amp; tech_pvt-&gt;phone_callflow != CALLFLOW_INCOMING_RING) {
</ins><span class="cx">           //mark the time of CALLFLOW_CALL_INCOMING
</span><del>-          gettimeofday(&amp;(p-&gt;call_incoming_time), NULL);
-          p-&gt;phone_callflow = CALLFLOW_CALL_INCOMING;
</del><ins>+          gettimeofday(&amp;(tech_pvt-&gt;call_incoming_time), NULL);
+          tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_INCOMING;
</ins><span class="cx">           DEBUGA_SKYPE(&quot;CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld\n&quot;,
</span><del>-                    SKYPIAX_P_LOG, p-&gt;call_incoming_time.tv_sec);
</del><ins>+                    SKYPIAX_P_LOG, tech_pvt-&gt;call_incoming_time.tv_sec);
</ins><span class="cx"> 
</span><span class="cx">         }
</span><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_call_active) == 0)) {
-        p-&gt;phone_callflow = CALLFLOW_CALL_ACTIVE;
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_call_active) == 0)) {
+        tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_ACTIVE;
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| CALLFLOW_CALL_ACTIVE\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx"> 
</span><del>-        if (p-&gt;owner &amp;&amp; p-&gt;interface_state == CALLFLOW_CALL_DIALING) {
</del><ins>+        if (tech_pvt-&gt;owner &amp;&amp; tech_pvt-&gt;interface_state == CALLFLOW_CALL_DIALING) {
</ins><span class="cx">           DEBUGA_PBX(&quot;just received a remote ANSWER\n&quot;, SKYPIAX_P_LOG);
</span><del>-          if (p-&gt;owner-&gt;_state != AST_STATE_UP) {
-            celliax_queue_control(p-&gt;owner, AST_CONTROL_RINGING);
-            DEBUGA_PBX(&quot;just sent AST_CONTROL_RINGING\n&quot;, SKYPIAX_P_LOG);
-            DEBUGA_PBX(&quot;going to send AST_CONTROL_ANSWER\n&quot;, SKYPIAX_P_LOG);
-            celliax_queue_control(p-&gt;owner, AST_CONTROL_ANSWER);
-            DEBUGA_PBX(&quot;just sent AST_CONTROL_ANSWER\n&quot;, SKYPIAX_P_LOG);
</del><ins>+          if (tech_pvt-&gt;owner-&gt;_state != SKYPIAX_STATE_UP) {
+            celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_RINGING);
+            DEBUGA_PBX(&quot;just sent SKYPIAX_CONTROL_RINGING\n&quot;, SKYPIAX_P_LOG);
+            DEBUGA_PBX(&quot;going to send SKYPIAX_CONTROL_ANSWER\n&quot;, SKYPIAX_P_LOG);
+            celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_ANSWER);
+            DEBUGA_PBX(&quot;just sent SKYPIAX_CONTROL_ANSWER\n&quot;, SKYPIAX_P_LOG);
</ins><span class="cx">           }
</span><span class="cx">         } else {
</span><span class="cx">         }
</span><del>-        p-&gt;interface_state = AST_STATE_UP;
</del><ins>+        tech_pvt-&gt;interface_state = SKYPIAX_STATE_UP;
</ins><span class="cx">         DEBUGA_PBX(&quot;just interface_state UP\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_call_calling) == 0)) {
-        p-&gt;phone_callflow = CALLFLOW_CALL_DIALING;
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_call_calling) == 0)) {
+        tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_DIALING;
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| CALLFLOW_CALL_DIALING\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_call_failed) == 0)) {
-        p-&gt;phone_callflow = CALLFLOW_CALL_FAILED;
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_call_failed) == 0)) {
+        tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_FAILED;
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| CALLFLOW_CALL_FAILED\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
-        if (p-&gt;interface_state != AST_STATE_DOWN &amp;&amp; p-&gt;owner) {
-          p-&gt;owner-&gt;hangupcause = AST_CAUSE_FAILURE;
-          celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
+        if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN &amp;&amp; tech_pvt-&gt;owner) {
+          tech_pvt-&gt;owner-&gt;hangupcause = SKYPIAX_CAUSE_FAILURE;
+          celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_HANGUP);
</ins><span class="cx">         }
</span><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;+CSCA:&quot;, 6) == 0)) {   //TODO SMS FIXME in config!
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CSCA:&quot;, 6) == 0)) {   //TODO SMS FIXME in config!
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| +CSCA: Message Center Address!\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;+CMGF:&quot;, 6) == 0)) {   //TODO SMS FIXME in config!
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CMGF:&quot;, 6) == 0)) {   //TODO SMS FIXME in config!
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| +CMGF: Message Format!\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;+CMTI:&quot;, 6) == 0)) {   //TODO SMS FIXME in config!
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CMTI:&quot;, 6) == 0)) {   //TODO SMS FIXME in config!
</ins><span class="cx">         int err;
</span><span class="cx">         int pos;
</span><span class="cx"> 
</span><span class="cx">         //FIXME all the following commands in config!
</span><span class="cx">         if (option_debug)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| +CMTI: Incoming SMS!\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx"> 
</span><del>-        err = sscanf(&amp;p-&gt;line_array.result[i][12], &quot;%d&quot;, &amp;pos);
</del><ins>+        err = sscanf(&amp;tech_pvt-&gt;line_array.result[i][12], &quot;%d&quot;, &amp;pos);
</ins><span class="cx">         if (err &lt; 1) {
</span><span class="cx">           ERRORA(&quot;|%s| is not formatted as: |+CMTI: \&quot;MT\&quot;,xx|\n&quot;, SKYPIAX_P_LOG,
</span><del>-                 p-&gt;line_array.result[i]);
</del><ins>+                 tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">         } else {
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| +CMTI: Incoming SMS in position: %d!\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i], pos);
-          p-&gt;unread_sms_msg_id = pos;
</del><ins>+                    tech_pvt-&gt;line_array.result[i], pos);
+          tech_pvt-&gt;unread_sms_msg_id = pos;
</ins><span class="cx">           usleep(1000);
</span><span class="cx"> 
</span><del>-          if (p-&gt;unread_sms_msg_id) {
</del><ins>+          if (tech_pvt-&gt;unread_sms_msg_id) {
</ins><span class="cx">             char at_command[256];
</span><span class="cx"> 
</span><del>-            if (p-&gt;no_ucs2 == 0) {
-              res = celliax_serial_write_AT_ack(p, &quot;AT+CSCS=\&quot;UCS2\&quot;&quot;);
</del><ins>+            if (tech_pvt-&gt;no_ucs2 == 0) {
+              res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT+CSCS=\&quot;UCS2\&quot;&quot;);
</ins><span class="cx">               if (res) {
</span><span class="cx">                 ERRORA
</span><span class="cx">                   (&quot;AT+CSCS=\&quot;UCS2\&quot; (set TE messages to ucs2)  do not got OK from the phone, continuing\n&quot;,
</span><span class="cx">                    SKYPIAX_P_LOG);
</span><del>-                //memset(p-&gt;sms_message, 0, sizeof(p-&gt;sms_message));
</del><ins>+                //memset(tech_pvt-&gt;sms_message, 0, sizeof(tech_pvt-&gt;sms_message));
</ins><span class="cx">               }
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             memset(at_command, 0, sizeof(at_command));
</span><del>-            sprintf(at_command, &quot;AT+CMGR=%d&quot;, p-&gt;unread_sms_msg_id);
-            memset(p-&gt;sms_message, 0, sizeof(p-&gt;sms_message));
</del><ins>+            sprintf(at_command, &quot;AT+CMGR=%d&quot;, tech_pvt-&gt;unread_sms_msg_id);
+            memset(tech_pvt-&gt;sms_message, 0, sizeof(tech_pvt-&gt;sms_message));
</ins><span class="cx"> 
</span><del>-            p-&gt;reading_sms_msg = 1;
-            res = celliax_serial_write_AT_ack(p, at_command);
-            p-&gt;reading_sms_msg = 0;
</del><ins>+            tech_pvt-&gt;reading_sms_msg = 1;
+            res = celliax_serial_write_AT_ack(tech_pvt, at_command);
+            tech_pvt-&gt;reading_sms_msg = 0;
</ins><span class="cx">             if (res) {
</span><span class="cx">               ERRORA
</span><span class="cx">                 (&quot;AT+CMGR (read SMS) do not got OK from the phone, message sent was:|||%s|||\n&quot;,
</span><span class="cx">                  SKYPIAX_P_LOG, at_command);
</span><span class="cx">             }
</span><del>-            res = celliax_serial_write_AT_ack(p, &quot;AT+CSCS=\&quot;GSM\&quot;&quot;);
</del><ins>+            res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT+CSCS=\&quot;GSM\&quot;&quot;);
</ins><span class="cx">             if (res) {
</span><span class="cx">               ERRORA
</span><span class="cx">                 (&quot;AT+CSCS=\&quot;GSM\&quot; (set TE messages to GSM) do not got OK from the phone\n&quot;,
</span><span class="cx">                  SKYPIAX_P_LOG);
</span><span class="cx">             }
</span><span class="cx">             memset(at_command, 0, sizeof(at_command));
</span><del>-            sprintf(at_command, &quot;AT+CMGD=%d&quot;, p-&gt;unread_sms_msg_id);    /* delete the message */
-            p-&gt;unread_sms_msg_id = 0;
-            res = celliax_serial_write_AT_ack(p, at_command);
</del><ins>+            sprintf(at_command, &quot;AT+CMGD=%d&quot;, tech_pvt-&gt;unread_sms_msg_id);    /* delete the message */
+            tech_pvt-&gt;unread_sms_msg_id = 0;
+            res = celliax_serial_write_AT_ack(tech_pvt, at_command);
</ins><span class="cx">             if (res) {
</span><span class="cx">               ERRORA
</span><span class="cx">                 (&quot;AT+CMGD (Delete SMS) do not got OK from the phone, message sent was:|||%s|||\n&quot;,
</span><span class="cx">                  SKYPIAX_P_LOG, at_command);
</span><span class="cx">             }
</span><span class="cx"> 
</span><del>-            if (strlen(p-&gt;sms_message)) {
-              manager_event(EVENT_FLAG_SYSTEM, &quot;CELLIAXincomingsms&quot;,
-                            &quot;Interface: %s\r\nSMS_Message: %s\r\n&quot;, p-&gt;name,
-                            p-&gt;sms_message);
-              if (strlen(p-&gt;sms_receiving_program)) {
</del><ins>+            if (strlen(tech_pvt-&gt;sms_message)) {
+              //FIXME manager_event(EVENT_FLAG_SYSTEM, &quot;CELLIAXincomingsms&quot;,
+                            //FIXME &quot;Interface: %s\r\nSMS_Message: %s\r\n&quot;, tech_pvt-&gt;name,
+                            //FIXME tech_pvt-&gt;sms_message);
+              if (strlen(tech_pvt-&gt;sms_receiving_program)) {
</ins><span class="cx">                 int fd1[2];
</span><span class="cx">                 pid_t pid1;
</span><del>-                char *arg1[] = { p-&gt;sms_receiving_program, (char *) NULL };
</del><ins>+                char *arg1[] = { tech_pvt-&gt;sms_receiving_program, (char *) NULL };
</ins><span class="cx">                 int i;
</span><span class="cx"> 
</span><del>-                NOTICA(&quot;incoming SMS message:&gt;&gt;&gt;%s&lt;&lt;&lt;\n&quot;, SKYPIAX_P_LOG, p-&gt;sms_message);
</del><ins>+                NOTICA(&quot;incoming SMS message:&gt;&gt;&gt;%s&lt;&lt;&lt;\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;sms_message);
</ins><span class="cx">                 pipe(fd1);
</span><span class="cx">                 pid1 = fork();
</span><span class="cx"> 
</span><span class="lines">@@ -3797,35 +2348,35 @@
</span><span class="cx"> 
</span><span class="cx">                   dup2(fd1[0], 0);  // Connect stdin to pipe output
</span><span class="cx">                   close(fd1[1]);    // close input pipe side
</span><del>-                close(p-&gt;controldevfd);
</del><ins>+                close(tech_pvt-&gt;controldevfd);
</ins><span class="cx">                   setsid();     //session id
</span><span class="cx">                   err = execvp(arg1[0], arg1);  //exec our program, with stdin connected to pipe output
</span><span class="cx">                   if (err) {
</span><span class="cx">                     ERRORA
</span><span class="cx">                       (&quot;'sms_receiving_program' is set in config file to '%s', and it gave us back this error: %d, (%s). SMS received was:---%s---\n&quot;,
</span><del>-                       SKYPIAX_P_LOG, p-&gt;sms_receiving_program, err, strerror(errno),
-                       p-&gt;sms_message);
</del><ins>+                       SKYPIAX_P_LOG, tech_pvt-&gt;sms_receiving_program, err, strerror(errno),
+                       tech_pvt-&gt;sms_message);
</ins><span class="cx">                   }
</span><span class="cx">                   close(fd1[0]);    // close output pipe side
</span><span class="cx">                 }
</span><span class="cx"> //starting here continue the parent
</span><span class="cx">                 close(fd1[0]);  // close output pipe side
</span><span class="cx">                 // write the msg on the pipe input
</span><del>-                for (i = 0; i &lt; strlen(p-&gt;sms_message); i++) {
-                  write(fd1[1], &amp;p-&gt;sms_message[i], 1);
</del><ins>+                for (i = 0; i &lt; strlen(tech_pvt-&gt;sms_message); i++) {
+                  write(fd1[1], &amp;tech_pvt-&gt;sms_message[i], 1);
</ins><span class="cx">                 }
</span><span class="cx">                 close(fd1[1]);  // close pipe input, let our program know we've finished
</span><span class="cx">               } else {
</span><span class="cx">                 ERRORA
</span><span class="cx">                   (&quot;got SMS incoming message, but 'sms_receiving_program' is not set in config file. SMS received was:---%s---\n&quot;,
</span><del>-                   SKYPIAX_P_LOG, p-&gt;sms_message);
</del><ins>+                   SKYPIAX_P_LOG, tech_pvt-&gt;sms_message);
</ins><span class="cx">               }
</span><span class="cx">             }
</span><span class="cx"> #if 1                           //is this one needed? maybe it can interrupt an incoming call that is just to announce itself
</span><del>-            if (p-&gt;phone_callflow == CALLFLOW_CALL_IDLE
-                &amp;&amp; p-&gt;interface_state == AST_STATE_DOWN &amp;&amp; p-&gt;owner == NULL) {
</del><ins>+            if (tech_pvt-&gt;phone_callflow == CALLFLOW_CALL_IDLE
+                &amp;&amp; tech_pvt-&gt;interface_state == SKYPIAX_STATE_DOWN &amp;&amp; tech_pvt-&gt;owner == NULL) {
</ins><span class="cx">               /* we're not in a call, neither calling */
</span><del>-              res = celliax_serial_write_AT_ack(p, &quot;AT+CKPD=\&quot;EEE\&quot;&quot;);
</del><ins>+              res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT+CKPD=\&quot;EEE\&quot;&quot;);
</ins><span class="cx">               if (res) {
</span><span class="cx">                 ERRORA
</span><span class="cx">                   (&quot;AT+CKPD=\&quot;EEE\&quot; (cellphone screen back to user) do not got OK from the phone\n&quot;,
</span><span class="lines">@@ -3839,127 +2390,127 @@
</span><span class="cx"> 
</span><span class="cx">       }                         //CMTI
</span><span class="cx"> 
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;+MMGL:&quot;, 6) == 0)) {   //TODO MOTOROLA SMS FIXME in config!
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+MMGL:&quot;, 6) == 0)) {   //TODO MOTOROLA SMS FIXME in config!
</ins><span class="cx">         int err = 0;
</span><span class="cx">         //int unread_msg_id=0;
</span><span class="cx"> 
</span><span class="cx">         if (option_debug)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| +MMGL: Listing Motorola SMSs!\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx"> 
</span><del>-        err = sscanf(&amp;p-&gt;line_array.result[i][7], &quot;%d&quot;, &amp;p-&gt;unread_sms_msg_id);
</del><ins>+        err = sscanf(&amp;tech_pvt-&gt;line_array.result[i][7], &quot;%d&quot;, &amp;tech_pvt-&gt;unread_sms_msg_id);
</ins><span class="cx">         if (err &lt; 1) {
</span><span class="cx">           ERRORA(&quot;|%s| is not formatted as: |+MMGL: xx|\n&quot;, SKYPIAX_P_LOG,
</span><del>-                 p-&gt;line_array.result[i]);
</del><ins>+                 tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">         }
</span><span class="cx">       }
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;+CMGL:&quot;, 6) == 0)) {   //TODO  SMS FIXME in config!
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CMGL:&quot;, 6) == 0)) {   //TODO  SMS FIXME in config!
</ins><span class="cx">         if (option_debug)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| +CMGL: Listing SMSs!\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;+MMGR:&quot;, 6) == 0)) {   //TODO MOTOROLA SMS FIXME in config!
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+MMGR:&quot;, 6) == 0)) {   //TODO MOTOROLA SMS FIXME in config!
</ins><span class="cx">         if (option_debug)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| +MMGR: Reading Motorola SMS!\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
-        if (p-&gt;reading_sms_msg)
-          p-&gt;reading_sms_msg++;
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
+        if (tech_pvt-&gt;reading_sms_msg)
+          tech_pvt-&gt;reading_sms_msg++;
</ins><span class="cx">       }
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;+CMGR: \&quot;STO U&quot;, 13) == 0)) {  //TODO  SMS FIXME in config!
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CMGR: \&quot;STO U&quot;, 13) == 0)) {  //TODO  SMS FIXME in config!
</ins><span class="cx">         if (option_debug)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| +CMGR: Reading stored UNSENT SMS!\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
-      } else if ((strncmp(p-&gt;line_array.result[i], &quot;+CMGR: \&quot;STO S&quot;, 13) == 0)) {   //TODO  SMS FIXME in config!
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
+      } else if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CMGR: \&quot;STO S&quot;, 13) == 0)) {   //TODO  SMS FIXME in config!
</ins><span class="cx">         if (option_debug)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| +CMGR: Reading stored SENT SMS!\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
-      } else if ((strncmp(p-&gt;line_array.result[i], &quot;+CMGR: \&quot;REC R&quot;, 13) == 0)) {   //TODO  SMS FIXME in config!
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
+      } else if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CMGR: \&quot;REC R&quot;, 13) == 0)) {   //TODO  SMS FIXME in config!
</ins><span class="cx">         if (option_debug)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| +CMGR: Reading received READ SMS!\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
-      } else if ((strncmp(p-&gt;line_array.result[i], &quot;+CMGR: \&quot;REC U&quot;, 13) == 0)) {   //TODO  SMS FIXME in config!
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
+      } else if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CMGR: \&quot;REC U&quot;, 13) == 0)) {   //TODO  SMS FIXME in config!
</ins><span class="cx">         if (option_debug)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| +CMGR: Reading received UNREAD SMS!\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
-        if (p-&gt;reading_sms_msg)
-          p-&gt;reading_sms_msg++;
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
+        if (tech_pvt-&gt;reading_sms_msg)
+          tech_pvt-&gt;reading_sms_msg++;
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], &quot;+MCST: 17&quot;) == 0)) {    /* motorola call processing unsolicited messages */
-        p-&gt;phone_callflow = CALLFLOW_CALL_INFLUX;
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], &quot;+MCST: 17&quot;) == 0)) {    /* motorola call processing unsolicited messages */
+        tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_INFLUX;
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| CALLFLOW_CALL_INFLUX\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], &quot;+MCST: 68&quot;) == 0)) {    /* motorola call processing unsolicited messages */
-        p-&gt;phone_callflow = CALLFLOW_CALL_NOSERVICE;
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], &quot;+MCST: 68&quot;) == 0)) {    /* motorola call processing unsolicited messages */
+        tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_NOSERVICE;
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| CALLFLOW_CALL_NOSERVICE\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
-        if (p-&gt;interface_state != AST_STATE_DOWN &amp;&amp; p-&gt;owner) {
-          p-&gt;owner-&gt;hangupcause = AST_CAUSE_FAILURE;
-          celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
+        if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN &amp;&amp; tech_pvt-&gt;owner) {
+          tech_pvt-&gt;owner-&gt;hangupcause = SKYPIAX_CAUSE_FAILURE;
+          celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_HANGUP);
</ins><span class="cx">         }
</span><span class="cx">       }
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], &quot;+MCST: 70&quot;) == 0)) {    /* motorola call processing unsolicited messages */
-        p-&gt;phone_callflow = CALLFLOW_CALL_OUTGOINGRESTRICTED;
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], &quot;+MCST: 70&quot;) == 0)) {    /* motorola call processing unsolicited messages */
+        tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_OUTGOINGRESTRICTED;
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| CALLFLOW_CALL_OUTGOINGRESTRICTED\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
-        if (p-&gt;interface_state != AST_STATE_DOWN &amp;&amp; p-&gt;owner) {
-          p-&gt;owner-&gt;hangupcause = AST_CAUSE_FAILURE;
-          celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
+        if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN &amp;&amp; tech_pvt-&gt;owner) {
+          tech_pvt-&gt;owner-&gt;hangupcause = SKYPIAX_CAUSE_FAILURE;
+          celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_HANGUP);
</ins><span class="cx">         }
</span><span class="cx">       }
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], &quot;+MCST: 72&quot;) == 0)) {    /* motorola call processing unsolicited messages */
-        p-&gt;phone_callflow = CALLFLOW_CALL_SECURITYFAIL;
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], &quot;+MCST: 72&quot;) == 0)) {    /* motorola call processing unsolicited messages */
+        tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_SECURITYFAIL;
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| CALLFLOW_CALL_SECURITYFAIL\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
-        if (p-&gt;interface_state != AST_STATE_DOWN &amp;&amp; p-&gt;owner) {
-          p-&gt;owner-&gt;hangupcause = AST_CAUSE_FAILURE;
-          celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
+        if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN &amp;&amp; tech_pvt-&gt;owner) {
+          tech_pvt-&gt;owner-&gt;hangupcause = SKYPIAX_CAUSE_FAILURE;
+          celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_HANGUP);
</ins><span class="cx">         }
</span><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;+CPBR&quot;, 5) == 0)) {    /* phonebook stuff begins */
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CPBR&quot;, 5) == 0)) {    /* phonebook stuff begins */
</ins><span class="cx"> 
</span><del>-        if (p-&gt;phonebook_querying) {    /* probably phonebook struct begins */
</del><ins>+        if (tech_pvt-&gt;phonebook_querying) {    /* probably phonebook struct begins */
</ins><span class="cx">           int err, first_entry, last_entry, number_lenght, text_lenght;
</span><span class="cx"> 
</span><span class="cx">           if (option_debug)
</span><del>-            DEBUGA_SKYPE(&quot;phonebook struct: |%s|\n&quot;, SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
</del><ins>+            DEBUGA_SKYPE(&quot;phonebook struct: |%s|\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx"> 
</span><span class="cx">           err =
</span><del>-            sscanf(&amp;p-&gt;line_array.result[i][8], &quot;%d-%d),%d,%d&quot;, &amp;first_entry, &amp;last_entry,
</del><ins>+            sscanf(&amp;tech_pvt-&gt;line_array.result[i][8], &quot;%d-%d),%d,%d&quot;, &amp;first_entry, &amp;last_entry,
</ins><span class="cx">                    &amp;number_lenght, &amp;text_lenght);
</span><span class="cx">           if (err &lt; 4) {
</span><span class="cx"> 
</span><span class="cx">             err =
</span><del>-              sscanf(&amp;p-&gt;line_array.result[i][7], &quot;%d-%d,%d,%d&quot;, &amp;first_entry,
</del><ins>+              sscanf(&amp;tech_pvt-&gt;line_array.result[i][7], &quot;%d-%d,%d,%d&quot;, &amp;first_entry,
</ins><span class="cx">                      &amp;last_entry, &amp;number_lenght, &amp;text_lenght);
</span><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">           if (err &lt; 4) {
</span><span class="cx">             ERRORA
</span><span class="cx">               (&quot;phonebook struct: |%s| is nor formatted as: |+CPBR: (1-750),40,14| neither as: |+CPBR: 1-750,40,14|\n&quot;,
</span><del>-               SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
</del><ins>+               SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">           } else {
</span><span class="cx"> 
</span><span class="cx">             if (option_debug)
</span><span class="cx">               DEBUGA_SKYPE
</span><span class="cx">                 (&quot;First entry: %d, last entry: %d, phone number max lenght: %d, text max lenght: %d\n&quot;,
</span><span class="cx">                  SKYPIAX_P_LOG, first_entry, last_entry, number_lenght, text_lenght);
</span><del>-            p-&gt;phonebook_first_entry = first_entry;
-            p-&gt;phonebook_last_entry = last_entry;
-            p-&gt;phonebook_number_lenght = number_lenght;
-            p-&gt;phonebook_text_lenght = text_lenght;
</del><ins>+            tech_pvt-&gt;phonebook_first_entry = first_entry;
+            tech_pvt-&gt;phonebook_last_entry = last_entry;
+            tech_pvt-&gt;phonebook_number_lenght = number_lenght;
+            tech_pvt-&gt;phonebook_text_lenght = text_lenght;
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">         } else {                /* probably phonebook entry begins */
</span><span class="cx"> 
</span><del>-          if (p-&gt;phonebook_listing) {
</del><ins>+          if (tech_pvt-&gt;phonebook_listing) {
</ins><span class="cx">             int err, entry_id, entry_type;
</span><span class="cx"> 
</span><span class="cx">             char entry_number[256];
</span><span class="lines">@@ -3967,40 +2518,40 @@
</span><span class="cx"> 
</span><span class="cx">             if (option_debug)
</span><span class="cx">               DEBUGA_SKYPE(&quot;phonebook entry: |%s|\n&quot;, SKYPIAX_P_LOG,
</span><del>-                        p-&gt;line_array.result[i]);
</del><ins>+                        tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx"> 
</span><span class="cx">             err =
</span><del>-              sscanf(&amp;p-&gt;line_array.result[i][7], &quot;%d,\&quot;%255[0-9+]\&quot;,%d,\&quot;%255[^\&quot;]\&quot;&quot;,
</del><ins>+              sscanf(&amp;tech_pvt-&gt;line_array.result[i][7], &quot;%d,\&quot;%255[0-9+]\&quot;,%d,\&quot;%255[^\&quot;]\&quot;&quot;,
</ins><span class="cx">                      &amp;entry_id, entry_number, &amp;entry_type, entry_text);
</span><span class="cx">             if (err &lt; 4) {
</span><span class="cx">               ERRORA
</span><span class="cx">                 (&quot;err=%d, phonebook entry: |%s| is not formatted as: |+CPBR: 504,\&quot;+39025458068\&quot;,145,\&quot;ciao a tutti\&quot;|\n&quot;,
</span><del>-                 SKYPIAX_P_LOG, err, p-&gt;line_array.result[i]);
</del><ins>+                 SKYPIAX_P_LOG, err, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">             } else {
</span><span class="cx">               //TODO: sanitize entry_text
</span><span class="cx">               if (option_debug)
</span><span class="cx">                 DEBUGA_SKYPE(&quot;Number: %s, Text: %s, Type: %d\n&quot;, SKYPIAX_P_LOG, entry_number,
</span><span class="cx">                           entry_text, entry_type);
</span><span class="cx">               /* write entry in phonebook file */
</span><del>-              if (p-&gt;phonebook_writing_fp) {
</del><ins>+              if (tech_pvt-&gt;phonebook_writing_fp) {
</ins><span class="cx">                 celliax_dir_entry_extension++;
</span><span class="cx"> 
</span><del>-                fprintf(p-&gt;phonebook_writing_fp,
</del><ins>+                fprintf(tech_pvt-&gt;phonebook_writing_fp,
</ins><span class="cx">                         &quot;%s  =&gt; ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromcell=%s|phonebook_entry_owner=%s\n&quot;,
</span><span class="cx">                         entry_number, entry_text, &quot;no&quot;,
</span><del>-                        p-&gt;celliax_dir_entry_extension_prefix, &quot;2&quot;,
</del><ins>+                        tech_pvt-&gt;celliax_dir_entry_extension_prefix, &quot;2&quot;,
</ins><span class="cx">                         celliax_dir_entry_extension, &quot;yes&quot;, &quot;not_specified&quot;);
</span><del>-                fprintf(p-&gt;phonebook_writing_fp,
</del><ins>+                fprintf(tech_pvt-&gt;phonebook_writing_fp,
</ins><span class="cx">                         &quot;%s  =&gt; ,%sDO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromcell=%s|phonebook_entry_owner=%s\n&quot;,
</span><span class="cx">                         entry_number, entry_text, &quot;no&quot;,
</span><del>-                        p-&gt;celliax_dir_entry_extension_prefix, &quot;3&quot;,
</del><ins>+                        tech_pvt-&gt;celliax_dir_entry_extension_prefix, &quot;3&quot;,
</ins><span class="cx">                         celliax_dir_entry_extension, &quot;yes&quot;, &quot;not_specified&quot;);
</span><span class="cx">               }
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">           }
</span><span class="cx"> 
</span><del>-          if (p-&gt;phonebook_listing_received_calls) {
</del><ins>+          if (tech_pvt-&gt;phonebook_listing_received_calls) {
</ins><span class="cx">             int err, entry_id, entry_type;
</span><span class="cx"> 
</span><span class="cx">             char entry_number[256] = &quot;&quot;;
</span><span class="lines">@@ -4008,203 +2559,203 @@
</span><span class="cx"> 
</span><span class="cx">             if (option_debug)
</span><span class="cx">               DEBUGA_SKYPE(&quot;phonebook entry: |%s|\n&quot;, SKYPIAX_P_LOG,
</span><del>-                        p-&gt;line_array.result[i]);
</del><ins>+                        tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx"> 
</span><span class="cx">             err =
</span><del>-              sscanf(&amp;p-&gt;line_array.result[i][7], &quot;%d,\&quot;%255[0-9+]\&quot;,%d,\&quot;%255[^\&quot;]\&quot;&quot;,
</del><ins>+              sscanf(&amp;tech_pvt-&gt;line_array.result[i][7], &quot;%d,\&quot;%255[0-9+]\&quot;,%d,\&quot;%255[^\&quot;]\&quot;&quot;,
</ins><span class="cx">                      &amp;entry_id, entry_number, &amp;entry_type, entry_text);
</span><span class="cx">             if (err &lt; 1) {      //we match only on the progressive id, maybe the remote party has not sent its number, and/or there is no corresponding text entry in the phone directory
</span><span class="cx">               ERRORA
</span><span class="cx">                 (&quot;err=%d, phonebook entry: |%s| is not formatted as: |+CPBR: 504,\&quot;+39025458068\&quot;,145,\&quot;ciao a tutti\&quot;|\n&quot;,
</span><del>-                 SKYPIAX_P_LOG, err, p-&gt;line_array.result[i]);
</del><ins>+                 SKYPIAX_P_LOG, err, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">             } else {
</span><span class="cx">               //TODO: sanitize entry_text
</span><span class="cx"> 
</span><span class="cx">               if (option_debug)
</span><span class="cx">                 DEBUGA_SKYPE(&quot;Number: %s, Text: %s, Type: %d\n&quot;, SKYPIAX_P_LOG, entry_number,
</span><span class="cx">                           entry_text, entry_type);
</span><del>-              memset(p-&gt;callid_name, 0, sizeof(p-&gt;callid_name));
-              memset(p-&gt;callid_number, 0, sizeof(p-&gt;callid_number));
-              strncpy(p-&gt;callid_name, entry_text, sizeof(p-&gt;callid_name));
-              strncpy(p-&gt;callid_number, entry_number, sizeof(p-&gt;callid_number));
</del><ins>+              memset(tech_pvt-&gt;callid_name, 0, sizeof(tech_pvt-&gt;callid_name));
+              memset(tech_pvt-&gt;callid_number, 0, sizeof(tech_pvt-&gt;callid_number));
+              strncpy(tech_pvt-&gt;callid_name, entry_text, sizeof(tech_pvt-&gt;callid_name));
+              strncpy(tech_pvt-&gt;callid_number, entry_number, sizeof(tech_pvt-&gt;callid_number));
</ins><span class="cx">               if (option_debug)
</span><span class="cx">                 DEBUGA_SKYPE(&quot;incoming callid: Text: %s, Number: %s\n&quot;, SKYPIAX_P_LOG,
</span><del>-                          p-&gt;callid_name, p-&gt;callid_number);
</del><ins>+                          tech_pvt-&gt;callid_name, tech_pvt-&gt;callid_number);
</ins><span class="cx"> 
</span><span class="cx">               DEBUGA_SKYPE(&quot;|%s| CPBR INCOMING CALLID: name is %s, number is %s\n&quot;,
</span><del>-                        SKYPIAX_P_LOG, p-&gt;line_array.result[i],
-                        p-&gt;callid_name[0] != 1 ? p-&gt;callid_name : &quot;not available&quot;,
-                        p-&gt;callid_number[0] ? p-&gt;callid_number : &quot;not available&quot;);
</del><ins>+                        SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i],
+                        tech_pvt-&gt;callid_name[0] != 1 ? tech_pvt-&gt;callid_name : &quot;not available&quot;,
+                        tech_pvt-&gt;callid_number[0] ? tech_pvt-&gt;callid_number : &quot;not available&quot;);
</ins><span class="cx"> 
</span><span class="cx">               /* mark the time of RING */
</span><del>-              gettimeofday(&amp;(p-&gt;ringtime), NULL);
-              p-&gt;interface_state = AST_STATE_RING;
-              p-&gt;phone_callflow = CALLFLOW_INCOMING_RING;
</del><ins>+              gettimeofday(&amp;(tech_pvt-&gt;ringtime), NULL);
+              tech_pvt-&gt;interface_state = SKYPIAX_STATE_RING;
+              tech_pvt-&gt;phone_callflow = CALLFLOW_INCOMING_RING;
</ins><span class="cx"> 
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">           else {
</span><del>-            DEBUGA_SKYPE(&quot;phonebook entry: |%s|\n&quot;, SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
</del><ins>+            DEBUGA_SKYPE(&quot;phonebook entry: |%s|\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx"> 
</span><span class="cx">           }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strncmp(p-&gt;line_array.result[i], &quot;*ECAV&quot;, 5) == 0) || (strncmp(p-&gt;line_array.result[i], &quot;*ECAM&quot;, 5) == 0)) { /* sony-ericsson call processing unsolicited messages */
</del><ins>+      if ((strncmp(tech_pvt-&gt;line_array.result[i], &quot;*ECAV&quot;, 5) == 0) || (strncmp(tech_pvt-&gt;line_array.result[i], &quot;*ECAM&quot;, 5) == 0)) { /* sony-ericsson call processing unsolicited messages */
</ins><span class="cx">         int res, ccid, ccstatus, calltype, processid, exitcause, number, type;
</span><span class="cx">         res = ccid = ccstatus = calltype = processid = exitcause = number = type = 0;
</span><span class="cx">         res =
</span><del>-          sscanf(&amp;p-&gt;line_array.result[i][6], &quot;%d,%d,%d,%d,%d,%d,%d&quot;, &amp;ccid, &amp;ccstatus,
</del><ins>+          sscanf(&amp;tech_pvt-&gt;line_array.result[i][6], &quot;%d,%d,%d,%d,%d,%d,%d&quot;, &amp;ccid, &amp;ccstatus,
</ins><span class="cx">                  &amp;calltype, &amp;processid, &amp;exitcause, &amp;number, &amp;type);
</span><span class="cx">         /* only changes the phone_callflow if enought parameters were parsed */
</span><span class="cx">         if (res &gt;= 3) {
</span><span class="cx">           switch (ccstatus) {
</span><span class="cx">           case 0:
</span><del>-            if (p-&gt;owner) {
-              ast_setstate(p-&gt;owner, AST_STATE_DOWN);
-              p-&gt;owner-&gt;hangupcause = AST_CAUSE_NORMAL;
-              celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
</del><ins>+            if (tech_pvt-&gt;owner) {
+              ast_setstate(tech_pvt-&gt;owner, SKYPIAX_STATE_DOWN);
+              tech_pvt-&gt;owner-&gt;hangupcause = SKYPIAX_CAUSE_NORMAL;
+              celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_HANGUP);
</ins><span class="cx">             }
</span><del>-            p-&gt;phone_callflow = CALLFLOW_CALL_IDLE;
-            p-&gt;interface_state = AST_STATE_DOWN;
</del><ins>+            tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_IDLE;
+            tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
</ins><span class="cx">             if (option_debug &gt; 1)
</span><span class="cx">               DEBUGA_SKYPE(&quot;|%s| Sony-Ericsson *ECAM/*ECAV: IDLE\n&quot;, SKYPIAX_P_LOG,
</span><del>-                        p-&gt;line_array.result[i]);
</del><ins>+                        tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">             break;
</span><span class="cx">           case 1:
</span><span class="cx">             if (option_debug &gt; 1)
</span><span class="cx">               DEBUGA_SKYPE(&quot;|%s| Sony-Ericsson *ECAM/*ECAV: CALLING\n&quot;, SKYPIAX_P_LOG,
</span><del>-                        p-&gt;line_array.result[i]);
</del><ins>+                        tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">             break;
</span><span class="cx">           case 2:
</span><del>-            if (p-&gt;owner) {
-              ast_setstate(p-&gt;owner, AST_STATE_DIALING);
</del><ins>+            if (tech_pvt-&gt;owner) {
+              ast_setstate(tech_pvt-&gt;owner, SKYPIAX_STATE_DIALING);
</ins><span class="cx">             }
</span><del>-            p-&gt;interface_state = CALLFLOW_CALL_DIALING;
</del><ins>+            tech_pvt-&gt;interface_state = CALLFLOW_CALL_DIALING;
</ins><span class="cx">             if (option_debug &gt; 1)
</span><span class="cx">               DEBUGA_SKYPE(&quot;|%s| Sony-Ericsson *ECAM/*ECAV: CONNECTING\n&quot;, SKYPIAX_P_LOG,
</span><del>-                        p-&gt;line_array.result[i]);
</del><ins>+                        tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">             break;
</span><span class="cx">           case 3:
</span><del>-            if (p-&gt;owner) {
-              ast_setstate(p-&gt;owner, AST_STATE_UP);
-              celliax_queue_control(p-&gt;owner, AST_CONTROL_ANSWER);
</del><ins>+            if (tech_pvt-&gt;owner) {
+              ast_setstate(tech_pvt-&gt;owner, SKYPIAX_STATE_UP);
+              celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_ANSWER);
</ins><span class="cx">             }
</span><del>-            p-&gt;phone_callflow = CALLFLOW_CALL_ACTIVE;
-            p-&gt;interface_state = AST_STATE_UP;
</del><ins>+            tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_ACTIVE;
+            tech_pvt-&gt;interface_state = SKYPIAX_STATE_UP;
</ins><span class="cx">             if (option_debug &gt; 1)
</span><span class="cx">               DEBUGA_SKYPE(&quot;|%s| Sony-Ericsson *ECAM/*ECAV: ACTIVE\n&quot;, SKYPIAX_P_LOG,
</span><del>-                        p-&gt;line_array.result[i]);
</del><ins>+                        tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">             break;
</span><span class="cx">           case 4:
</span><span class="cx">             if (option_debug &gt; 1)
</span><span class="cx">               DEBUGA_SKYPE
</span><span class="cx">                 (&quot;|%s| Sony-Ericsson *ECAM/*ECAV: don't know how to handle HOLD event\n&quot;,
</span><del>-                 SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
</del><ins>+                 SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">             break;
</span><span class="cx">           case 5:
</span><span class="cx">             if (option_debug &gt; 1)
</span><span class="cx">               DEBUGA_SKYPE
</span><span class="cx">                 (&quot;|%s| Sony-Ericsson *ECAM/*ECAV: don't know how to handle WAITING event\n&quot;,
</span><del>-                 SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
</del><ins>+                 SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">             break;
</span><span class="cx">           case 6:
</span><span class="cx">             if (option_debug &gt; 1)
</span><span class="cx">               DEBUGA_SKYPE
</span><span class="cx">                 (&quot;|%s| Sony-Ericsson *ECAM/*ECAV: don't know how to handle ALERTING event\n&quot;,
</span><del>-                 SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
</del><ins>+                 SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">             break;
</span><span class="cx">           case 7:
</span><del>-            if (p-&gt;owner) {
-              ast_setstate(p-&gt;owner, AST_STATE_BUSY);
-              celliax_queue_control(p-&gt;owner, AST_CONTROL_BUSY);
</del><ins>+            if (tech_pvt-&gt;owner) {
+              ast_setstate(tech_pvt-&gt;owner, SKYPIAX_STATE_BUSY);
+              celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_BUSY);
</ins><span class="cx">             }
</span><del>-            p-&gt;phone_callflow = CALLFLOW_CALL_LINEBUSY;
-            p-&gt;interface_state = AST_STATE_BUSY;
</del><ins>+            tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_LINEBUSY;
+            tech_pvt-&gt;interface_state = SKYPIAX_STATE_BUSY;
</ins><span class="cx">             if (option_debug &gt; 1)
</span><span class="cx">               DEBUGA_SKYPE(&quot;|%s| Sony-Ericsson *ECAM/*ECAV: BUSY\n&quot;, SKYPIAX_P_LOG,
</span><del>-                        p-&gt;line_array.result[i]);
</del><ins>+                        tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">             break;
</span><span class="cx">           }
</span><span class="cx">         } else {
</span><span class="cx">           if (option_debug &gt; 1)
</span><span class="cx">             DEBUGA_SKYPE(&quot;|%s| Sony-Ericsson *ECAM/*ECAV: could not parse parameters\n&quot;,
</span><del>-                      SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
</del><ins>+                      SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">       }
</span><span class="cx"> 
</span><span class="cx">       /* at_indicator_* are unsolicited messages sent by the phone to signal us that some of its visual indicators on its screen has changed, based on CIND CMER ETSI docs */
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_indicator_noservice_string) == 0)) {
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_indicator_noservice_string) == 0)) {
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           ERRORA(&quot;|%s| at_indicator_noservice_string\n&quot;, SKYPIAX_P_LOG,
</span><del>-                 p-&gt;line_array.result[i]);
</del><ins>+                 tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_indicator_nosignal_string) == 0)) {
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_indicator_nosignal_string) == 0)) {
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           ERRORA(&quot;|%s| at_indicator_nosignal_string\n&quot;, SKYPIAX_P_LOG,
</span><del>-                 p-&gt;line_array.result[i]);
</del><ins>+                 tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_indicator_lowsignal_string) == 0)) {
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_indicator_lowsignal_string) == 0)) {
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           WARNINGA(&quot;|%s| at_indicator_lowsignal_string\n&quot;, SKYPIAX_P_LOG,
</span><del>-                   p-&gt;line_array.result[i]);
</del><ins>+                   tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_indicator_lowbattchg_string) == 0)) {
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_indicator_lowbattchg_string) == 0)) {
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           WARNINGA(&quot;|%s| at_indicator_lowbattchg_string\n&quot;, SKYPIAX_P_LOG,
</span><del>-                   p-&gt;line_array.result[i]);
</del><ins>+                   tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_indicator_nobattchg_string) == 0)) {
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_indicator_nobattchg_string) == 0)) {
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           ERRORA(&quot;|%s| at_indicator_nobattchg_string\n&quot;, SKYPIAX_P_LOG,
</span><del>-                 p-&gt;line_array.result[i]);
</del><ins>+                 tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_indicator_callactive_string) == 0)) {
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_indicator_callactive_string) == 0)) {
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| at_indicator_callactive_string\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_indicator_nocallactive_string) == 0)) {
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_indicator_nocallactive_string) == 0)) {
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| at_indicator_nocallactive_string\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_indicator_nocallsetup_string) == 0)) {
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_indicator_nocallsetup_string) == 0)) {
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| at_indicator_nocallsetup_string\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_indicator_callsetupincoming_string) ==
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_indicator_callsetupincoming_string) ==
</ins><span class="cx">            0)) {
</span><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| at_indicator_callsetupincoming_string\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_indicator_callsetupoutgoing_string) ==
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_indicator_callsetupoutgoing_string) ==
</ins><span class="cx">            0)) {
</span><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| at_indicator_callsetupoutgoing_string\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], p-&gt;at_indicator_callsetupremoteringing_string)
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], tech_pvt-&gt;at_indicator_callsetupremoteringing_string)
</ins><span class="cx">            == 0)) {
</span><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;|%s| at_indicator_callsetupremoteringing_string\n&quot;, SKYPIAX_P_LOG,
</span><del>-                    p-&gt;line_array.result[i]);
</del><ins>+                    tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">       }
</span><span class="cx"> 
</span><span class="cx">     }
</span><span class="lines">@@ -4212,32 +2763,32 @@
</span><span class="cx">     /* let's look for OK, ERROR and EXPECTED_STRING in the complete lines read so far, without re-looking at the lines that has been yet looked at */
</span><span class="cx">     for (i = la_read; i &lt; la_counter; i++) {
</span><span class="cx">       if (expected_string) {
</span><del>-        if ((strncmp(p-&gt;line_array.result[i], expected_string, strlen(expected_string))
</del><ins>+        if ((strncmp(tech_pvt-&gt;line_array.result[i], expected_string, strlen(expected_string))
</ins><span class="cx">              == 0)) {
</span><span class="cx">           if (option_debug &gt; 1)
</span><del>-            DEBUGA_SKYPE(&quot;|%s| got what EXPECTED\n&quot;, SKYPIAX_P_LOG, p-&gt;line_array.result[i]);
</del><ins>+            DEBUGA_SKYPE(&quot;|%s| got what EXPECTED\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;line_array.result[i]);
</ins><span class="cx">           at_ack = AT_OK;
</span><span class="cx">         }
</span><span class="cx">       } else {
</span><del>-        if ((strcmp(p-&gt;line_array.result[i], &quot;OK&quot;) == 0)) {
</del><ins>+        if ((strcmp(tech_pvt-&gt;line_array.result[i], &quot;OK&quot;) == 0)) {
</ins><span class="cx">           if (option_debug &gt; 1)
</span><span class="cx">             DEBUGA_SKYPE(&quot;got OK\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">           at_ack = AT_OK;
</span><span class="cx">         }
</span><span class="cx">       }
</span><del>-      if ((strcmp(p-&gt;line_array.result[i], &quot;ERROR&quot;) == 0)) {
</del><ins>+      if ((strcmp(tech_pvt-&gt;line_array.result[i], &quot;ERROR&quot;) == 0)) {
</ins><span class="cx">         if (option_debug &gt; 1)
</span><span class="cx">           DEBUGA_SKYPE(&quot;got ERROR\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">         at_ack = AT_ERROR;
</span><span class="cx">       }
</span><span class="cx"> 
</span><span class="cx">       /* if we are reading an sms message from memory, put the line into the sms buffer if the line is not &quot;OK&quot; or &quot;ERROR&quot; */
</span><del>-      if (p-&gt;reading_sms_msg &gt; 1 &amp;&amp; at_ack == -1) {
</del><ins>+      if (tech_pvt-&gt;reading_sms_msg &gt; 1 &amp;&amp; at_ack == -1) {
</ins><span class="cx">         int c;
</span><span class="cx">         char sms_body[16000];
</span><span class="cx">         int err;
</span><span class="cx"> 
</span><del>-        if (strncmp(p-&gt;line_array.result[i], &quot;+CMGR&quot;, 5) == 0) {    /* we are reading the &quot;header&quot; of an SMS */
</del><ins>+        if (strncmp(tech_pvt-&gt;line_array.result[i], &quot;+CMGR&quot;, 5) == 0) {    /* we are reading the &quot;header&quot; of an SMS */
</ins><span class="cx">           char content[512];
</span><span class="cx">           char content2[512];
</span><span class="cx"> 
</span><span class="lines">@@ -4247,51 +2798,51 @@
</span><span class="cx">           int inside_quote = 0;
</span><span class="cx">           int d = 0;
</span><span class="cx"> 
</span><del>-          for (c = 0; c &lt; strlen(p-&gt;line_array.result[i]); c++) {
-            if (p-&gt;line_array.result[i][c] == ','
-                &amp;&amp; p-&gt;line_array.result[i][c - 1] != '\\' &amp;&amp; inside_quote == 0) {
</del><ins>+          for (c = 0; c &lt; strlen(tech_pvt-&gt;line_array.result[i]); c++) {
+            if (tech_pvt-&gt;line_array.result[i][c] == ','
+                &amp;&amp; tech_pvt-&gt;line_array.result[i][c - 1] != '\\' &amp;&amp; inside_quote == 0) {
</ins><span class="cx">               if (inside_comma) {
</span><span class="cx">                 inside_comma = 0;
</span><del>-                //NOTICA(&quot;inside_comma=%d, inside_quote=%d, we're at=%s\n&quot;, SKYPIAX_P_LOG, inside_comma, inside_quote, &amp;p-&gt;line_array.result[i][c]);
</del><ins>+                //NOTICA(&quot;inside_comma=%d, inside_quote=%d, we're at=%s\n&quot;, SKYPIAX_P_LOG, inside_comma, inside_quote, &amp;tech_pvt-&gt;line_array.result[i][c]);
</ins><span class="cx">               } else {
</span><span class="cx">                 inside_comma = 1;
</span><del>-                //NOTICA(&quot;inside_comma=%d, inside_quote=%d, we're at=%s\n&quot;, SKYPIAX_P_LOG, inside_comma, inside_quote, &amp;p-&gt;line_array.result[i][c]);
</del><ins>+                //NOTICA(&quot;inside_comma=%d, inside_quote=%d, we're at=%s\n&quot;, SKYPIAX_P_LOG, inside_comma, inside_quote, &amp;tech_pvt-&gt;line_array.result[i][c]);
</ins><span class="cx">               }
</span><span class="cx">             }
</span><del>-            if (p-&gt;line_array.result[i][c] == '&quot;'
-                &amp;&amp; p-&gt;line_array.result[i][c - 1] != '\\') {
</del><ins>+            if (tech_pvt-&gt;line_array.result[i][c] == '&quot;'
+                &amp;&amp; tech_pvt-&gt;line_array.result[i][c - 1] != '\\') {
</ins><span class="cx">               if (inside_quote) {
</span><span class="cx">                 inside_quote = 0;
</span><del>-                //ERRORA(&quot;END_CONTENT inside_comma=%d, inside_quote=%d, we're at=%s\n&quot;, SKYPIAX_P_LOG, inside_comma, inside_quote, &amp;p-&gt;line_array.result[i][c]);
</del><ins>+                //ERRORA(&quot;END_CONTENT inside_comma=%d, inside_quote=%d, we're at=%s\n&quot;, SKYPIAX_P_LOG, inside_comma, inside_quote, &amp;tech_pvt-&gt;line_array.result[i][c]);
</ins><span class="cx">                 DEBUGA_SKYPE(&quot;content=%s\n&quot;, SKYPIAX_P_LOG, content);
</span><span class="cx"> 
</span><del>-                strncat(p-&gt;sms_message, &quot;---&quot;,
-                        ((sizeof(p-&gt;sms_message) - strlen(p-&gt;sms_message)) - 1));
-                strncat(p-&gt;sms_message, content,
-                        ((sizeof(p-&gt;sms_message) - strlen(p-&gt;sms_message)) - 1));
-                strncat(p-&gt;sms_message, &quot;|||&quot;,
-                        ((sizeof(p-&gt;sms_message) - strlen(p-&gt;sms_message)) - 1));
</del><ins>+                strncat(tech_pvt-&gt;sms_message, &quot;---&quot;,
+                        ((sizeof(tech_pvt-&gt;sms_message) - strlen(tech_pvt-&gt;sms_message)) - 1));
+                strncat(tech_pvt-&gt;sms_message, content,
+                        ((sizeof(tech_pvt-&gt;sms_message) - strlen(tech_pvt-&gt;sms_message)) - 1));
+                strncat(tech_pvt-&gt;sms_message, &quot;|||&quot;,
+                        ((sizeof(tech_pvt-&gt;sms_message) - strlen(tech_pvt-&gt;sms_message)) - 1));
</ins><span class="cx"> 
</span><span class="cx">                 memset(content2, '\0', sizeof(content2));
</span><del>-                err = ucs2_to_utf8(p, content, content2, sizeof(content2));
</del><ins>+                err = ucs2_to_utf8(tech_pvt, content, content2, sizeof(content2));
</ins><span class="cx"> 
</span><del>-                strncat(p-&gt;sms_message, &quot;---&quot;,
-                        ((sizeof(p-&gt;sms_message) - strlen(p-&gt;sms_message)) - 1));
</del><ins>+                strncat(tech_pvt-&gt;sms_message, &quot;---&quot;,
+                        ((sizeof(tech_pvt-&gt;sms_message) - strlen(tech_pvt-&gt;sms_message)) - 1));
</ins><span class="cx">                 if (!err)
</span><del>-                  strncat(p-&gt;sms_message, content2,
-                          ((sizeof(p-&gt;sms_message) - strlen(p-&gt;sms_message)) - 1));
-                strncat(p-&gt;sms_message, &quot;|||&quot;,
-                        ((sizeof(p-&gt;sms_message) - strlen(p-&gt;sms_message)) - 1));
</del><ins>+                  strncat(tech_pvt-&gt;sms_message, content2,
+                          ((sizeof(tech_pvt-&gt;sms_message) - strlen(tech_pvt-&gt;sms_message)) - 1));
+                strncat(tech_pvt-&gt;sms_message, &quot;|||&quot;,
+                        ((sizeof(tech_pvt-&gt;sms_message) - strlen(tech_pvt-&gt;sms_message)) - 1));
</ins><span class="cx">                 memset(content, '\0', sizeof(content));
</span><span class="cx">                 d = 0;
</span><span class="cx">               } else {
</span><span class="cx">                 inside_quote = 1;
</span><del>-                //WARNINGA(&quot;START_CONTENT inside_comma=%d, inside_quote=%d, we're at=%s\n&quot;, SKYPIAX_P_LOG, inside_comma, inside_quote, &amp;p-&gt;line_array.result[i][c]);
</del><ins>+                //WARNINGA(&quot;START_CONTENT inside_comma=%d, inside_quote=%d, we're at=%s\n&quot;, SKYPIAX_P_LOG, inside_comma, inside_quote, &amp;tech_pvt-&gt;line_array.result[i][c]);
</ins><span class="cx">               }
</span><span class="cx">             }
</span><del>-            if (inside_quote &amp;&amp; p-&gt;line_array.result[i][c] != '&quot;') {
</del><ins>+            if (inside_quote &amp;&amp; tech_pvt-&gt;line_array.result[i][c] != '&quot;') {
</ins><span class="cx"> 
</span><del>-              content[d] = p-&gt;line_array.result[i][c];
</del><ins>+              content[d] = tech_pvt-&gt;line_array.result[i][c];
</ins><span class="cx">               d++;
</span><span class="cx"> 
</span><span class="cx">             }
</span><span class="lines">@@ -4299,25 +2850,25 @@
</span><span class="cx">           }
</span><span class="cx">         }                       //it was the +CMGR answer from the cellphone
</span><span class="cx">         else {
</span><del>-          strncat(p-&gt;sms_message, &quot;---&quot;,
-                  ((sizeof(p-&gt;sms_message) - strlen(p-&gt;sms_message)) - 1));
-          strncat(p-&gt;sms_message, p-&gt;line_array.result[i],
-                  ((sizeof(p-&gt;sms_message) - strlen(p-&gt;sms_message)) - 1));
-          strncat(p-&gt;sms_message, &quot;|||&quot;,
-                  ((sizeof(p-&gt;sms_message) - strlen(p-&gt;sms_message)) - 1));
</del><ins>+          strncat(tech_pvt-&gt;sms_message, &quot;---&quot;,
+                  ((sizeof(tech_pvt-&gt;sms_message) - strlen(tech_pvt-&gt;sms_message)) - 1));
+          strncat(tech_pvt-&gt;sms_message, tech_pvt-&gt;line_array.result[i],
+                  ((sizeof(tech_pvt-&gt;sms_message) - strlen(tech_pvt-&gt;sms_message)) - 1));
+          strncat(tech_pvt-&gt;sms_message, &quot;|||&quot;,
+                  ((sizeof(tech_pvt-&gt;sms_message) - strlen(tech_pvt-&gt;sms_message)) - 1));
</ins><span class="cx"> 
</span><span class="cx">           memset(sms_body, '\0', sizeof(sms_body));
</span><del>-          err = ucs2_to_utf8(p, p-&gt;line_array.result[i], sms_body, sizeof(sms_body));
</del><ins>+          err = ucs2_to_utf8(tech_pvt, tech_pvt-&gt;line_array.result[i], sms_body, sizeof(sms_body));
</ins><span class="cx"> 
</span><del>-          strncat(p-&gt;sms_message, &quot;---&quot;,
-                  ((sizeof(p-&gt;sms_message) - strlen(p-&gt;sms_message)) - 1));
</del><ins>+          strncat(tech_pvt-&gt;sms_message, &quot;---&quot;,
+                  ((sizeof(tech_pvt-&gt;sms_message) - strlen(tech_pvt-&gt;sms_message)) - 1));
</ins><span class="cx">           if (!err)
</span><del>-            strncat(p-&gt;sms_message, sms_body,
-                    ((sizeof(p-&gt;sms_message) - strlen(p-&gt;sms_message)) - 1));
-          strncat(p-&gt;sms_message, &quot;|||&quot;,
-                  ((sizeof(p-&gt;sms_message) - strlen(p-&gt;sms_message)) - 1));
</del><ins>+            strncat(tech_pvt-&gt;sms_message, sms_body,
+                    ((sizeof(tech_pvt-&gt;sms_message) - strlen(tech_pvt-&gt;sms_message)) - 1));
+          strncat(tech_pvt-&gt;sms_message, &quot;|||&quot;,
+                  ((sizeof(tech_pvt-&gt;sms_message) - strlen(tech_pvt-&gt;sms_message)) - 1));
</ins><span class="cx"> 
</span><del>-          DEBUGA_SKYPE(&quot;sms_message=%s\n&quot;, SKYPIAX_P_LOG, p-&gt;sms_message);
</del><ins>+          DEBUGA_SKYPE(&quot;sms_message=%s\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;sms_message);
</ins><span class="cx"> 
</span><span class="cx">         }                       //it was the UCS2 from cellphone
</span><span class="cx"> 
</span><span class="lines">@@ -4338,79 +2889,79 @@
</span><span class="cx">     }
</span><span class="cx">   }
</span><span class="cx"> 
</span><del>-  UNLOCKA(&amp;p-&gt;controldev_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
</del><ins>+  UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  POPPA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx">   if (select_err == -1) {
</span><span class="cx">     ERRORA(&quot;select returned -1 on %s, setting controldev_dead, error was: %s\n&quot;,
</span><del>-           SKYPIAX_P_LOG, p-&gt;controldevice_name, strerror(errno));
-    p-&gt;controldev_dead = 1;
-    close(p-&gt;controldevfd);
-    if (p-&gt;owner)
-      celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
</del><ins>+           SKYPIAX_P_LOG, tech_pvt-&gt;controldevice_name, strerror(errno));
+    tech_pvt-&gt;controldev_dead = 1;
+    close(tech_pvt-&gt;controldevfd);
+    if (tech_pvt-&gt;owner)
+      celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_HANGUP);
</ins><span class="cx">     return -1;
</span><span class="cx">   }
</span><span class="cx"> 
</span><del>-  if (p-&gt;phone_callflow == CALLFLOW_CALL_INCOMING &amp;&amp; p-&gt;call_incoming_time.tv_sec) {    //after three sec of CALLFLOW_CALL_INCOMING, we assume the phone is incapable of notifying RING (eg: motorola c350), so we try to answer
</del><ins>+  if (tech_pvt-&gt;phone_callflow == CALLFLOW_CALL_INCOMING &amp;&amp; tech_pvt-&gt;call_incoming_time.tv_sec) {    //after three sec of CALLFLOW_CALL_INCOMING, we assume the phone is incapable of notifying RING (eg: motorola c350), so we try to answer
</ins><span class="cx">     char list_command[64];
</span><span class="cx">     struct timeval call_incoming_timeout;
</span><span class="cx">     gettimeofday(&amp;call_incoming_timeout, NULL);
</span><span class="cx">     call_incoming_timeout.tv_sec -= 3;
</span><span class="cx">     DEBUGA_SKYPE
</span><span class="cx">       (&quot;CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld, call_incoming_timeout.tv_sec=%ld\n&quot;,
</span><del>-       SKYPIAX_P_LOG, p-&gt;call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
-    if (call_incoming_timeout.tv_sec &gt; p-&gt;call_incoming_time.tv_sec) {
</del><ins>+       SKYPIAX_P_LOG, tech_pvt-&gt;call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
+    if (call_incoming_timeout.tv_sec &gt; tech_pvt-&gt;call_incoming_time.tv_sec) {
</ins><span class="cx"> 
</span><del>-      p-&gt;call_incoming_time.tv_sec = 0;
-      p-&gt;call_incoming_time.tv_usec = 0;
</del><ins>+      tech_pvt-&gt;call_incoming_time.tv_sec = 0;
+      tech_pvt-&gt;call_incoming_time.tv_usec = 0;
</ins><span class="cx">       DEBUGA_SKYPE
</span><span class="cx">         (&quot;CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld, call_incoming_timeout.tv_sec=%ld\n&quot;,
</span><del>-         SKYPIAX_P_LOG, p-&gt;call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
-      res = celliax_serial_write_AT_ack(p, &quot;AT+CPBS=RC&quot;);
</del><ins>+         SKYPIAX_P_LOG, tech_pvt-&gt;call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
+      res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT+CPBS=RC&quot;);
</ins><span class="cx">       if (res) {
</span><span class="cx">         ERRORA
</span><span class="cx">           (&quot;AT+CPBS=RC (select memory of received calls) was not answered by the phone\n&quot;,
</span><span class="cx">            SKYPIAX_P_LOG);
</span><span class="cx">       }
</span><del>-      p-&gt;phonebook_querying = 1;
-      res = celliax_serial_write_AT_ack(p, &quot;AT+CPBR=?&quot;);
</del><ins>+      tech_pvt-&gt;phonebook_querying = 1;
+      res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT+CPBR=?&quot;);
</ins><span class="cx">       if (res) {
</span><span class="cx">         ERRORA
</span><span class="cx">           (&quot;AT+CPBS=RC (select memory of received calls) was not answered by the phone\n&quot;,
</span><span class="cx">            SKYPIAX_P_LOG);
</span><span class="cx">       }
</span><del>-      p-&gt;phonebook_querying = 0;
-      sprintf(list_command, &quot;AT+CPBR=%d,%d&quot;, p-&gt;phonebook_first_entry,
-              p-&gt;phonebook_last_entry);
-      p-&gt;phonebook_listing_received_calls = 1;
-      res = celliax_serial_write_AT_expect_longtime(p, list_command, &quot;OK&quot;);
</del><ins>+      tech_pvt-&gt;phonebook_querying = 0;
+      sprintf(list_command, &quot;AT+CPBR=%d,%d&quot;, tech_pvt-&gt;phonebook_first_entry,
+              tech_pvt-&gt;phonebook_last_entry);
+      tech_pvt-&gt;phonebook_listing_received_calls = 1;
+      res = celliax_serial_write_AT_expect_longtime(tech_pvt, list_command, &quot;OK&quot;);
</ins><span class="cx">       if (res) {
</span><span class="cx">         WARNINGA(&quot;AT+CPBR=%d,%d failed, continue\n&quot;, SKYPIAX_P_LOG,
</span><del>-                 p-&gt;phonebook_first_entry, p-&gt;phonebook_last_entry);
</del><ins>+                 tech_pvt-&gt;phonebook_first_entry, tech_pvt-&gt;phonebook_last_entry);
</ins><span class="cx">       }
</span><del>-      p-&gt;phonebook_listing_received_calls = 0;
</del><ins>+      tech_pvt-&gt;phonebook_listing_received_calls = 0;
</ins><span class="cx">     }
</span><span class="cx">   }
</span><span class="cx"> 
</span><del>-  if (p-&gt;phone_callflow == CALLFLOW_INCOMING_RING) {
</del><ins>+  if (tech_pvt-&gt;phone_callflow == CALLFLOW_INCOMING_RING) {
</ins><span class="cx">     struct timeval call_incoming_timeout;
</span><span class="cx">     gettimeofday(&amp;call_incoming_timeout, NULL);
</span><span class="cx">     call_incoming_timeout.tv_sec -= 10;
</span><span class="cx">     DEBUGA_SKYPE
</span><span class="cx">       (&quot;CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld, call_incoming_timeout.tv_sec=%ld\n&quot;,
</span><del>-       SKYPIAX_P_LOG, p-&gt;call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
-    if (call_incoming_timeout.tv_sec &gt; p-&gt;ringtime.tv_sec) {
</del><ins>+       SKYPIAX_P_LOG, tech_pvt-&gt;call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
+    if (call_incoming_timeout.tv_sec &gt; tech_pvt-&gt;ringtime.tv_sec) {
</ins><span class="cx">       ERRORA(&quot;Ringing stopped and I have not answered. Why?\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">       DEBUGA_SKYPE
</span><span class="cx">         (&quot;CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld, call_incoming_timeout.tv_sec=%ld\n&quot;,
</span><del>-         SKYPIAX_P_LOG, p-&gt;call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
-      if (p-&gt;owner) {
-        celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
-        p-&gt;owner-&gt;hangupcause = AST_CAUSE_FAILURE;
</del><ins>+         SKYPIAX_P_LOG, tech_pvt-&gt;call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
+      if (tech_pvt-&gt;owner) {
+        celliax_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_HANGUP);
+        tech_pvt-&gt;owner-&gt;hangupcause = SKYPIAX_CAUSE_FAILURE;
</ins><span class="cx">       }
</span><span class="cx">     }
</span><span class="cx">   }
</span><del>-  p-&gt;line_array.elemcount = la_counter;
-  //NOTICA (&quot; OUTSIDE this celliax_serial_device %s \n&quot;, SKYPIAX_P_LOG, p-&gt;controldevice_name);
</del><ins>+  tech_pvt-&gt;line_array.elemcount = la_counter;
+  //NOTICA (&quot; OUTSIDE this celliax_serial_device %s \n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;controldevice_name);
</ins><span class="cx">   if (look_for_ack)
</span><span class="cx">     return at_ack;
</span><span class="cx">   else
</span><span class="lines">@@ -4427,14 +2978,14 @@
</span><span class="cx">   howmany = strlen(data);
</span><span class="cx"> 
</span><span class="cx">   for (i = 0; i &lt; howmany; i++) {
</span><del>-    res = write(p-&gt;controldevfd, &amp;data[i], 1);
</del><ins>+    res = write(tech_pvt-&gt;controldevfd, &amp;data[i], 1);
</ins><span class="cx"> 
</span><span class="cx">     if (res != 1) {
</span><span class="cx">       DEBUGA_SKYPE(&quot;Error sending (%.1s): %d (%s)\n&quot;, SKYPIAX_P_LOG, &amp;data[i], res,
</span><span class="cx">                 strerror(errno));
</span><span class="cx">       usleep(100000);
</span><span class="cx">       for (count = 0; count &lt; 10; count++) {
</span><del>-        res = write(p-&gt;controldevfd, &amp;data[i], 1);
</del><ins>+        res = write(tech_pvt-&gt;controldevfd, &amp;data[i], 1);
</ins><span class="cx">         if (res == 1) {
</span><span class="cx">           DEBUGA_SKYPE(&quot;Successfully RE-sent (%.1s): %d %d (%s)\n&quot;, SKYPIAX_P_LOG, &amp;data[i],
</span><span class="cx">                     count, res, strerror(errno));
</span><span class="lines">@@ -4456,14 +3007,14 @@
</span><span class="cx">     usleep(1000);               /* release the cpu */
</span><span class="cx">   }
</span><span class="cx"> 
</span><del>-  res = write(p-&gt;controldevfd, &quot;\r&quot;, 1);
</del><ins>+  res = write(tech_pvt-&gt;controldevfd, &quot;\r&quot;, 1);
</ins><span class="cx"> 
</span><span class="cx">   if (res != 1) {
</span><span class="cx">     DEBUGA_SKYPE(&quot;Error sending (carriage return): %d (%s)\n&quot;, SKYPIAX_P_LOG, res,
</span><span class="cx">               strerror(errno));
</span><span class="cx">     usleep(100000);
</span><span class="cx">     for (count = 0; count &lt; 10; count++) {
</span><del>-      res = write(p-&gt;controldevfd, &quot;\r&quot;, 1);
</del><ins>+      res = write(tech_pvt-&gt;controldevfd, &quot;\r&quot;, 1);
</ins><span class="cx"> 
</span><span class="cx">       if (res == 1) {
</span><span class="cx">         DEBUGA_SKYPE(&quot;Successfully RE-sent carriage return: %d %d (%s)\n&quot;, SKYPIAX_P_LOG,
</span><span class="lines">@@ -4498,14 +3049,14 @@
</span><span class="cx">   howmany = strlen(data);
</span><span class="cx"> 
</span><span class="cx">   for (i = 0; i &lt; howmany; i++) {
</span><del>-    res = write(p-&gt;controldevfd, &amp;data[i], 1);
</del><ins>+    res = write(tech_pvt-&gt;controldevfd, &amp;data[i], 1);
</ins><span class="cx"> 
</span><span class="cx">     if (res != 1) {
</span><span class="cx">       DEBUGA_SKYPE(&quot;Error sending (%.1s): %d (%s)\n&quot;, SKYPIAX_P_LOG, &amp;data[i], res,
</span><span class="cx">                 strerror(errno));
</span><span class="cx">       usleep(100000);
</span><span class="cx">       for (count = 0; count &lt; 10; count++) {
</span><del>-        res = write(p-&gt;controldevfd, &amp;data[i], 1);
</del><ins>+        res = write(tech_pvt-&gt;controldevfd, &amp;data[i], 1);
</ins><span class="cx">         if (res == 1)
</span><span class="cx">           break;
</span><span class="cx">         else
</span><span class="lines">@@ -4536,16 +3087,16 @@
</span><span class="cx">   if (option_debug &gt; 1)
</span><span class="cx">     DEBUGA_SKYPE(&quot;celliax_serial_write_AT_noack: %s\n&quot;, SKYPIAX_P_LOG, data);
</span><span class="cx"> 
</span><del>-  PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  LOKKA(&amp;p-&gt;controldev_lock);
-  if (celliax_serial_write_AT(p, data) != strlen(data)) {
</del><ins>+  PUSHA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  LOKKA(&amp;tech_pvt-&gt;controldev_lock);
+  if (celliax_serial_write_AT(tech_pvt, data) != strlen(data)) {
</ins><span class="cx"> 
</span><span class="cx">     ERRORA(&quot;Error sending data... (%s)\n&quot;, SKYPIAX_P_LOG, strerror(errno));
</span><del>-    UNLOCKA(&amp;p-&gt;controldev_lock);
</del><ins>+    UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx">     return -1;
</span><span class="cx">   }
</span><del>-  UNLOCKA(&amp;p-&gt;controldev_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
</del><ins>+  UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  POPPA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx"> 
</span><span class="cx">   return 0;
</span><span class="cx"> }
</span><span class="lines">@@ -4554,19 +3105,19 @@
</span><span class="cx"> {
</span><span class="cx">   int at_result = AT_ERROR;
</span><span class="cx"> 
</span><del>-  PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  LOKKA(&amp;p-&gt;controldev_lock);
</del><ins>+  PUSHA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  LOKKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx">   if (option_debug &gt; 1)
</span><span class="cx">     DEBUGA_SKYPE(&quot;sending: %s\n&quot;, SKYPIAX_P_LOG, data);
</span><del>-  if (celliax_serial_write_AT(p, data) != strlen(data)) {
</del><ins>+  if (celliax_serial_write_AT(tech_pvt, data) != strlen(data)) {
</ins><span class="cx">     ERRORA(&quot;Error sending data... (%s) \n&quot;, SKYPIAX_P_LOG, strerror(errno));
</span><del>-    UNLOCKA(&amp;p-&gt;controldev_lock);
</del><ins>+    UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx">     return -1;
</span><span class="cx">   }
</span><span class="cx"> 
</span><del>-  at_result = celliax_serial_read_AT(p, 1, 500000, 2, NULL, 1); // 2.5 sec timeout
-  UNLOCKA(&amp;p-&gt;controldev_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
</del><ins>+  at_result = celliax_serial_read_AT(tech_pvt, 1, 500000, 2, NULL, 1); // 2.5 sec timeout
+  UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  POPPA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx"> 
</span><span class="cx">   return at_result;
</span><span class="cx"> 
</span><span class="lines">@@ -4576,19 +3127,19 @@
</span><span class="cx"> {
</span><span class="cx">   int at_result = AT_ERROR;
</span><span class="cx"> 
</span><del>-  PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  LOKKA(&amp;p-&gt;controldev_lock);
</del><ins>+  PUSHA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  LOKKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx">   if (option_debug &gt; 1)
</span><span class="cx">     DEBUGA_SKYPE(&quot;sending: %s\n&quot;, SKYPIAX_P_LOG, data);
</span><del>-  if (celliax_serial_write_AT_nocr(p, data) != strlen(data)) {
</del><ins>+  if (celliax_serial_write_AT_nocr(tech_pvt, data) != strlen(data)) {
</ins><span class="cx">     ERRORA(&quot;Error sending data... (%s) \n&quot;, SKYPIAX_P_LOG, strerror(errno));
</span><del>-    UNLOCKA(&amp;p-&gt;controldev_lock);
</del><ins>+    UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx">     return -1;
</span><span class="cx">   }
</span><span class="cx"> 
</span><del>-  at_result = celliax_serial_read_AT(p, 1, 500000, 20, NULL, 1);    // 20.5 sec timeout
-  UNLOCKA(&amp;p-&gt;controldev_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
</del><ins>+  at_result = celliax_serial_read_AT(tech_pvt, 1, 500000, 20, NULL, 1);    // 20.5 sec timeout
+  UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  POPPA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx"> 
</span><span class="cx">   return at_result;
</span><span class="cx"> 
</span><span class="lines">@@ -4600,19 +3151,19 @@
</span><span class="cx"> {
</span><span class="cx">   int at_result = AT_ERROR;
</span><span class="cx"> 
</span><del>-  PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  LOKKA(&amp;p-&gt;controldev_lock);
</del><ins>+  PUSHA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  LOKKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx">   if (option_debug &gt; 1)
</span><span class="cx">     DEBUGA_SKYPE(&quot;sending: %s, expecting: %s\n&quot;, SKYPIAX_P_LOG, data, expected_string);
</span><del>-  if (celliax_serial_write_AT(p, data) != strlen(data)) {
</del><ins>+  if (celliax_serial_write_AT(tech_pvt, data) != strlen(data)) {
</ins><span class="cx">     ERRORA(&quot;Error sending data... (%s) \n&quot;, SKYPIAX_P_LOG, strerror(errno));
</span><del>-    UNLOCKA(&amp;p-&gt;controldev_lock);
</del><ins>+    UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx">     return -1;
</span><span class="cx">   }
</span><span class="cx"> 
</span><del>-  at_result = celliax_serial_read_AT(p, 1, 500000, seconds, expected_string, expect_crlf);  // 20.5 sec timeout, used for querying the SIM and sending SMSs
-  UNLOCKA(&amp;p-&gt;controldev_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
</del><ins>+  at_result = celliax_serial_read_AT(tech_pvt, 1, 500000, seconds, expected_string, expect_crlf);  // 20.5 sec timeout, used for querying the SIM and sending SMSs
+  UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  POPPA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx"> 
</span><span class="cx">   return at_result;
</span><span class="cx"> 
</span><span class="lines">@@ -4623,14 +3174,14 @@
</span><span class="cx"> {
</span><span class="cx">   int at_result = AT_ERROR;
</span><span class="cx"> 
</span><del>-  PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  LOKKA(&amp;p-&gt;controldev_lock);
</del><ins>+  PUSHA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  LOKKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx">   if (option_debug &gt; 1)
</span><span class="cx">     DEBUGA_SKYPE(&quot;expecting: %s\n&quot;, SKYPIAX_P_LOG, expected_string);
</span><span class="cx"> 
</span><del>-  at_result = celliax_serial_read_AT(p, 1, 500000, seconds, expected_string, expect_crlf);  // 20.5 sec timeout, used for querying the SIM and sending SMSs
-  UNLOCKA(&amp;p-&gt;controldev_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
</del><ins>+  at_result = celliax_serial_read_AT(tech_pvt, 1, 500000, seconds, expected_string, expect_crlf);  // 20.5 sec timeout, used for querying the SIM and sending SMSs
+  UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  POPPA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx"> 
</span><span class="cx">   return at_result;
</span><span class="cx"> 
</span><span class="lines">@@ -4640,21 +3191,21 @@
</span><span class="cx"> {
</span><span class="cx">   int res;
</span><span class="cx"> 
</span><del>-  res = celliax_serial_write_AT_expect(p, p-&gt;at_answer, p-&gt;at_answer_expect);
</del><ins>+  res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt-&gt;at_answer, tech_pvt-&gt;at_answer_expect);
</ins><span class="cx">   if (res) {
</span><span class="cx">     DEBUGA_SKYPE
</span><span class="cx">       (&quot;at_answer command failed, command used: %s, expecting: %s, trying with AT+CKPD=\&quot;S\&quot;\n&quot;,
</span><del>-       SKYPIAX_P_LOG, p-&gt;at_answer, p-&gt;at_answer_expect);
</del><ins>+       SKYPIAX_P_LOG, tech_pvt-&gt;at_answer, tech_pvt-&gt;at_answer_expect);
</ins><span class="cx"> 
</span><del>-    res = celliax_serial_write_AT_ack(p, &quot;AT+CKPD=\&quot;S\&quot;&quot;);
</del><ins>+    res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT+CKPD=\&quot;S\&quot;&quot;);
</ins><span class="cx">     if (res) {
</span><span class="cx">       ERRORA(&quot;at_answer command failed, command used: 'AT+CKPD=\&quot;S\&quot;', giving up\n&quot;,
</span><span class="cx">              SKYPIAX_P_LOG);
</span><span class="cx">       return -1;
</span><span class="cx">     }
</span><span class="cx">   }
</span><del>-  //p-&gt;interface_state = AST_STATE_UP;
-  //p-&gt;phone_callflow = CALLFLOW_CALL_ACTIVE;
</del><ins>+  //tech_pvt-&gt;interface_state = SKYPIAX_STATE_UP;
+  //tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_ACTIVE;
</ins><span class="cx">   DEBUGA_SKYPE(&quot;AT: call answered\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">   return 0;
</span><span class="cx"> }
</span><span class="lines">@@ -4663,13 +3214,13 @@
</span><span class="cx"> {
</span><span class="cx">   int res;
</span><span class="cx"> 
</span><del>-  if (p-&gt;interface_state != AST_STATE_DOWN) {
-    res = celliax_serial_write_AT_expect(p, p-&gt;at_hangup, p-&gt;at_hangup_expect);
</del><ins>+  if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN) {
+    res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt-&gt;at_hangup, tech_pvt-&gt;at_hangup_expect);
</ins><span class="cx">     if (res) {
</span><span class="cx">       DEBUGA_SKYPE
</span><span class="cx">         (&quot;at_hangup command failed, command used: %s, trying to use AT+CKPD=\&quot;EEE\&quot;\n&quot;,
</span><del>-         SKYPIAX_P_LOG, p-&gt;at_hangup);
-      res = celliax_serial_write_AT_ack(p, &quot;AT+CKPD=\&quot;EEE\&quot;&quot;);
</del><ins>+         SKYPIAX_P_LOG, tech_pvt-&gt;at_hangup);
+      res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT+CKPD=\&quot;EEE\&quot;&quot;);
</ins><span class="cx">       if (res) {
</span><span class="cx">         ERRORA(&quot;at_hangup command failed, command used: 'AT+CKPD=\&quot;EEE\&quot;'\n&quot;,
</span><span class="cx">                SKYPIAX_P_LOG);
</span><span class="lines">@@ -4677,467 +3228,11 @@
</span><span class="cx">       }
</span><span class="cx">     }
</span><span class="cx">   }
</span><del>-  p-&gt;interface_state = AST_STATE_DOWN;
-  p-&gt;phone_callflow = CALLFLOW_CALL_IDLE;
</del><ins>+  tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
+  tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_IDLE;
</ins><span class="cx">   return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-int celliax_serial_config_AT(private_t * tech_pvt)
-{
-  int res;
-
-/* initial_pause? */
-  if (p-&gt;at_initial_pause) {
-    DEBUGA_SKYPE(&quot;sleeping for %d usec\n&quot;, SKYPIAX_P_LOG, p-&gt;at_initial_pause);
-    usleep(p-&gt;at_initial_pause);
-  }
-
-/* go until first empty preinit string, or last preinit string */
-  while (1) {
-
-    if (strlen(p-&gt;at_preinit_1)) {
-      res = celliax_serial_write_AT_expect(p, p-&gt;at_preinit_1, p-&gt;at_preinit_1_expect);
-      if (res) {
-        DEBUGA_SKYPE(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
-                  p-&gt;at_preinit_1, p-&gt;at_preinit_1_expect);
-      }
-    } else {
-      break;
-    }
-
-    if (strlen(p-&gt;at_preinit_2)) {
-      res = celliax_serial_write_AT_expect(p, p-&gt;at_preinit_2, p-&gt;at_preinit_2_expect);
-      if (res) {
-        DEBUGA_SKYPE(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
-                  p-&gt;at_preinit_2, p-&gt;at_preinit_2_expect);
-      }
-    } else {
-      break;
-    }
-
-    if (strlen(p-&gt;at_preinit_3)) {
-      res = celliax_serial_write_AT_expect(p, p-&gt;at_preinit_3, p-&gt;at_preinit_3_expect);
-      if (res) {
-        DEBUGA_SKYPE(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
-                  p-&gt;at_preinit_3, p-&gt;at_preinit_3_expect);
-      }
-    } else {
-      break;
-    }
-
-    if (strlen(p-&gt;at_preinit_4)) {
-      res = celliax_serial_write_AT_expect(p, p-&gt;at_preinit_4, p-&gt;at_preinit_4_expect);
-      if (res) {
-        DEBUGA_SKYPE(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
-                  p-&gt;at_preinit_4, p-&gt;at_preinit_4_expect);
-      }
-    } else {
-      break;
-    }
-
-    if (strlen(p-&gt;at_preinit_5)) {
-      res = celliax_serial_write_AT_expect(p, p-&gt;at_preinit_5, p-&gt;at_preinit_5_expect);
-      if (res) {
-        DEBUGA_SKYPE(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
-                  p-&gt;at_preinit_5, p-&gt;at_preinit_5_expect);
-      }
-    } else {
-      break;
-    }
-
-    break;
-  }
-
-/* after_preinit_pause? */
-  if (p-&gt;at_after_preinit_pause) {
-    DEBUGA_SKYPE(&quot;sleeping for %d usec\n&quot;, SKYPIAX_P_LOG, p-&gt;at_after_preinit_pause);
-    usleep(p-&gt;at_after_preinit_pause);
-  }
-
-  /* phone, brother, art you alive? */
-  res = celliax_serial_write_AT_ack(p, &quot;AT&quot;);
-  if (res) {
-    ERRORA(&quot;no response to AT\n&quot;, SKYPIAX_P_LOG);
-    return -1;
-  }
-  /* for motorola, bring it back to &quot;normal&quot; mode if it happens to be in another mode */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+mode=0&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+mode=0 does not get OK from the phone. If it is NOT Motorola,&quot;
-              &quot; no problem.\n&quot;, SKYPIAX_P_LOG);
-  }
-  usleep(50000);
-  /* for motorola end */
-
-  /* reset AT configuration to phone default */
-  res = celliax_serial_write_AT_ack(p, &quot;ATZ&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;ATZ failed\n&quot;, SKYPIAX_P_LOG);
-  }
-
-  /* disable AT command echo */
-  res = celliax_serial_write_AT_ack(p, &quot;ATE0&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;ATE0 failed\n&quot;, SKYPIAX_P_LOG);
-  }
-
-  /* disable extended error reporting */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CMEE=0&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CMEE failed\n&quot;, SKYPIAX_P_LOG);
-  }
-
-  /* various phone manufacturer identifier */
-  char at_command[5];
-  int i;
-  for (i = 0; i &lt; 10; i++) {
-    memset(at_command, 0, sizeof(at_command));
-    sprintf(at_command, &quot;ATI%d&quot;, i);
-    res = celliax_serial_write_AT_ack(p, at_command);
-    if (res) {
-      DEBUGA_SKYPE(&quot;ATI%d command failed, continue\n&quot;, SKYPIAX_P_LOG, i);
-    }
-  }
-
-  /* phone manufacturer */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CGMI&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CGMI failed\n&quot;, SKYPIAX_P_LOG);
-  }
-
-  /* phone model */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CGMM&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CGMM failed\n&quot;, SKYPIAX_P_LOG);
-  }
-
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CGSN&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CGSN failed\n&quot;, SKYPIAX_P_LOG);
-  }
-
-/* this take a lot of time to complete on devices with slow serial link (eg.: 9600bps) */
-#if 0
-  /* ask for the list of supported AT commands, useful to implement new models and debugging */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CLAC&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CLAC failed, continue\n&quot;, SKYPIAX_P_LOG);
-  }
-#endif
-  /* signal incoming SMS with a +CMTI unsolicited msg */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CNMI=3,1,0,0,0&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CNMI=3,1,0,0,0 failed, continue\n&quot;, SKYPIAX_P_LOG);
-    p-&gt;sms_cnmi_not_supported = 1;
-    p-&gt;celliax_serial_sync_period = 30;
-  }
-  /* what is the Message Center address (number) to which the SMS has to be sent? */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CSCA?&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CSCA? failed, continue\n&quot;, SKYPIAX_P_LOG);
-  }
-  /* what is the Message Format of SMSs? */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CMGF?&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CMGF? failed, continue\n&quot;, SKYPIAX_P_LOG);
-  }
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CMGF=1&quot;);    //TODO: support phones that only accept pdu mode
-  if (res) {
-    ERRORA(&quot;Error setting SMS sending mode to TEXT on the cellphone\n&quot;, SKYPIAX_P_LOG);
-    return RESULT_FAILURE;
-  }
-  /* what is the Charset of SMSs? */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CSCS?&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CSCS? failed, continue\n&quot;, SKYPIAX_P_LOG);
-  }
-
-  p-&gt;no_ucs2 = 0;
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CSCS=\&quot;UCS2\&quot;&quot;);
-  if (res) {
-    WARNINGA
-      (&quot;AT+CSCS=\&quot;UCS2\&quot; (set TE messages to ucs2)  do not got OK from the phone, let's try with 'GSM'\n&quot;,
-       SKYPIAX_P_LOG);
-    p-&gt;no_ucs2 = 1;
-  }
-
-  if (p-&gt;no_ucs2) {
-    res = celliax_serial_write_AT_ack(p, &quot;AT+CSCS=\&quot;GSM\&quot;&quot;);
-    if (res) {
-      WARNINGA(&quot;AT+CSCS=\&quot;GSM\&quot; (set TE messages to GSM)  do not got OK from the phone\n&quot;,
-               SKYPIAX_P_LOG);
-    }
-    //res = celliax_serial_write_AT_ack(p, &quot;AT+CSMP=17,167,0,16&quot;); //&quot;flash&quot;, class 0  sms 7 bit
-    res = celliax_serial_write_AT_ack(p, &quot;AT+CSMP=17,167,0,0&quot;); //normal, 7 bit message
-    if (res) {
-      WARNINGA(&quot;AT+CSMP do not got OK from the phone, continuing\n&quot;, SKYPIAX_P_LOG);
-    }
-  } else {
-    //res = celliax_serial_write_AT_ack(p, &quot;AT+CSMP=17,167,0,20&quot;); //&quot;flash&quot;, class 0 sms 16 bit unicode
-    res = celliax_serial_write_AT_ack(p, &quot;AT+CSMP=17,167,0,8&quot;); //unicode, 16 bit message
-    if (res) {
-      WARNINGA(&quot;AT+CSMP do not got OK from the phone, continuing\n&quot;, SKYPIAX_P_LOG);
-    }
-  }
-
-  /* is the unsolicited reporting of mobile equipment event supported? */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CMER=?&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CMER=? failed, continue\n&quot;, SKYPIAX_P_LOG);
-  }
-  /* request unsolicited reporting of mobile equipment indicators' events, to be screened by categories reported by +CIND=? */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CMER=3,0,0,1&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CMER=? failed, continue\n&quot;, SKYPIAX_P_LOG);
-  }
-
-  /* is the solicited reporting of mobile equipment indications supported? */
-
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CIND=?&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CIND=? failed, continue\n&quot;, SKYPIAX_P_LOG);
-  }
-
-  /* is the unsolicited reporting of call monitoring supported? sony-ericsson specific */
-  res = celliax_serial_write_AT_ack(p, &quot;AT*ECAM=?&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT*ECAM=? failed, continue\n&quot;, SKYPIAX_P_LOG);
-  }
-  /* enable the unsolicited reporting of call monitoring. sony-ericsson specific */
-  res = celliax_serial_write_AT_ack(p, &quot;AT*ECAM=1&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT*ECAM=1 failed, continue\n&quot;, SKYPIAX_P_LOG);
-    p-&gt;at_has_ecam = 0;
-  } else {
-    p-&gt;at_has_ecam = 1;
-  }
-
-  /* disable unsolicited signaling of call list */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CLCC=0&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CLCC=0 failed, continue\n&quot;, SKYPIAX_P_LOG);
-    p-&gt;at_has_clcc = 0;
-  } else {
-    p-&gt;at_has_clcc = 1;
-  }
-
-  /* give unsolicited caller id when incoming call */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+CLIP=1&quot;);
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+CLIP failed, continue\n&quot;, SKYPIAX_P_LOG);
-  }
-  /* for motorola */
-  res = celliax_serial_write_AT_ack(p, &quot;AT+MCST=1&quot;);    /* motorola call control codes
-                                                           (to know when call is disconnected (they
-                                                           don't give you &quot;no carrier&quot;) */
-  if (res) {
-    DEBUGA_SKYPE(&quot;AT+MCST=1 does not get OK from the phone. If it is NOT Motorola,&quot;
-              &quot; no problem.\n&quot;, SKYPIAX_P_LOG);
-  }
-  /* for motorola end */
-
-/* go until first empty postinit string, or last postinit string */
-  while (1) {
-
-    if (strlen(p-&gt;at_postinit_1)) {
-      res = celliax_serial_write_AT_expect(p, p-&gt;at_postinit_1, p-&gt;at_postinit_1_expect);
-      if (res) {
-        DEBUGA_SKYPE(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
-                  p-&gt;at_postinit_1, p-&gt;at_postinit_1_expect);
-      }
-    } else {
-      break;
-    }
-
-    if (strlen(p-&gt;at_postinit_2)) {
-      res = celliax_serial_write_AT_expect(p, p-&gt;at_postinit_2, p-&gt;at_postinit_2_expect);
-      if (res) {
-        DEBUGA_SKYPE(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
-                  p-&gt;at_postinit_2, p-&gt;at_postinit_2_expect);
-      }
-    } else {
-      break;
-    }
-
-    if (strlen(p-&gt;at_postinit_3)) {
-      res = celliax_serial_write_AT_expect(p, p-&gt;at_postinit_3, p-&gt;at_postinit_3_expect);
-      if (res) {
-        DEBUGA_SKYPE(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
-                  p-&gt;at_postinit_3, p-&gt;at_postinit_3_expect);
-      }
-    } else {
-      break;
-    }
-
-    if (strlen(p-&gt;at_postinit_4)) {
-      res = celliax_serial_write_AT_expect(p, p-&gt;at_postinit_4, p-&gt;at_postinit_4_expect);
-      if (res) {
-        DEBUGA_SKYPE(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
-                  p-&gt;at_postinit_4, p-&gt;at_postinit_4_expect);
-      }
-    } else {
-      break;
-    }
-
-    if (strlen(p-&gt;at_postinit_5)) {
-      res = celliax_serial_write_AT_expect(p, p-&gt;at_postinit_5, p-&gt;at_postinit_5_expect);
-      if (res) {
-        DEBUGA_SKYPE(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
-                  p-&gt;at_postinit_5, p-&gt;at_postinit_5_expect);
-      }
-    } else {
-      break;
-    }
-
-    break;
-  }
-
-  return 0;
-}
-
-int celliax_serial_call_AT(private_t * tech_pvt, char *dstr)
-{
-  int res;
-  char at_command[256];
-
-  if (option_debug)
-    DEBUGA_PBX(&quot;Dialing %s\n&quot;, SKYPIAX_P_LOG, dstr);
-  memset(at_command, 0, sizeof(at_command));
-  p-&gt;phone_callflow = CALLFLOW_CALL_DIALING;
-  p-&gt;interface_state = AST_STATE_DIALING;
-  ast_uri_decode(dstr);
-  size_t fixdstr = strspn(dstr, AST_DIGIT_ANYDIG);
-  if (fixdstr == 0) {
-    ERRORA(&quot;dial command failed because of invalid dial number. dial string was: %s\n&quot;,
-           SKYPIAX_P_LOG, dstr);
-    return -1;
-  }
-  dstr[fixdstr] = '\0';
-  sprintf(at_command, &quot;%s%s%s&quot;, p-&gt;at_dial_pre_number, dstr, p-&gt;at_dial_post_number);
-  res = celliax_serial_write_AT_expect(p, at_command, p-&gt;at_dial_expect);
-  if (res) {
-    ERRORA(&quot;dial command failed, dial string was: %s\n&quot;, SKYPIAX_P_LOG, at_command);
-    return -1;
-  }
-  // jet - early audio
-  if (p-&gt;at_early_audio) {
-    ast_queue_control(p-&gt;owner, AST_CONTROL_ANSWER);
-  }
-
-  return 0;
-}
-
-int celliax_console_at(int fd, int argc, char *argv[])
-{
-  private_t * tech_pvt = celliax_console_find_desc(celliax_console_active);
-  char at_cmd[1024];
-  int i, a, c;
-
-  if (argc == 1)
-    return RESULT_SHOWUSAGE;
-  if (!p) {
-    ast_cli(fd,
-            &quot;No \&quot;current\&quot; console for celliax_at, please enter 'help celliax_console'\n&quot;);
-    return RESULT_SUCCESS;
-  }
-  if (p-&gt;controldevprotocol != PROTOCOL_AT) {
-    ast_cli(fd,
-            &quot;The \&quot;current\&quot; console is not connected to an 'AT modem' (cellphone)\n&quot;);
-    return RESULT_SUCCESS;
-  }
-
-  memset(at_cmd, 0, sizeof(at_cmd));
-  c = 0;
-  for (i = 1; i &lt; argc; i++) {
-    for (a = 0; a &lt; strlen(argv[i]); a++) {
-      at_cmd[c] = argv[i][a];
-      c++;
-      if (c == 1022)
-        break;
-    }
-    if (i != argc - 1) {
-      at_cmd[c] = ' ';
-      c++;
-    }
-    if (c == 1023)
-      break;
-  }
-  celliax_serial_write_AT_noack(p, at_cmd);
-  return RESULT_SUCCESS;
-}
-
-#ifdef ASTERISK_VERSION_1_2
-int celliax_manager_sendsms(struct mansession *s, struct message *m)
-#endif //ASTERISK_VERSION_1_2
-#ifdef ASTERISK_VERSION_1_4
-int celliax_manager_sendsms(struct mansession *s, const struct message *m)
-#endif //ASTERISK_VERSION_1_4
-{
-  int ret;
-  char command[512];
-  const char *interfacename = astman_get_header(m, &quot;Interface&quot;);
-  const char *destinationnumber = astman_get_header(m, &quot;Number&quot;);
-  const char *text = astman_get_header(m, &quot;Text&quot;);
-  const char *action_id = astman_get_header(m, &quot;ActionID&quot;);
-
-  if (ast_strlen_zero(interfacename)) {
-    astman_send_error(s, m, &quot;Interface: missing.\n&quot;);
-    return 0;
-  }
-  if (ast_strlen_zero(destinationnumber)) {
-    astman_send_error(s, m, &quot;Number: missing.\n&quot;);
-    return 0;
-  }
-  if (ast_strlen_zero(text)) {
-    astman_send_error(s, m, &quot;Text: missing.\n&quot;);
-    return 0;
-  }
-  if (ast_strlen_zero(action_id)) {
-    astman_send_error(s, m, &quot;ActionID: missing.\n&quot;);
-    return 0;
-  }
-
-  memset(command, 0, sizeof(command));
-
-  sprintf(command, &quot;%s/%s|%s|&quot;, interfacename, destinationnumber, text);
-
-  ret = celliax_sendsms(NULL, (void *) &amp;command);
-
-#ifndef ASTERISK_VERSION_1_4
-  if (!ret) {
-    ast_cli(s-&gt;fd, &quot;Response: Success\r\n&quot;);
-    if (!ast_strlen_zero(action_id))
-      ast_cli(s-&gt;fd, &quot;ActionID: %s\r\n&quot;, action_id);
-    ast_cli(s-&gt;fd, &quot;\r\n&quot;);
-    return RESULT_SUCCESS;
-  } else {
-    ast_cli(s-&gt;fd, &quot;Response: Error\r\n&quot;);
-    if (!ast_strlen_zero(action_id))
-      ast_cli(s-&gt;fd, &quot;ActionID: %s\r\n&quot;, action_id);
-    ast_cli(s-&gt;fd, &quot;Message: celliax_manager_sendsms failed\r\n&quot;);
-    ast_cli(s-&gt;fd, &quot;\r\n&quot;);
-    return 0;
-  }
-#else /* ASTERISK_VERSION_1_4 */
-  if (!ret) {
-    astman_append(s, &quot;Response: Success\r\n&quot;);
-    if (!ast_strlen_zero(action_id))
-      astman_append(s, &quot;ActionID: %s\r\n&quot;, action_id);
-    astman_append(s, &quot;\r\n&quot;);
-    return RESULT_SUCCESS;
-  } else {
-    astman_append(s, &quot;Response: Error\r\n&quot;);
-    if (!ast_strlen_zero(action_id))
-      astman_append(s, &quot;ActionID: %s\r\n&quot;, action_id);
-    astman_append(s, &quot;Message: celliax_manager_sendsms failed\r\n&quot;);
-    astman_append(s, &quot;\r\n&quot;);
-    return 0;
-  }
-#endif /* ASTERISK_VERSION_1_4 */
-
-  return RESULT_SUCCESS;        //never reached
-}
-
</del><span class="cx"> int ucs2_to_utf8(private_t * tech_pvt, char *ucs2_in, char *utf8_out,
</span><span class="cx">                  size_t outbytesleft)
</span><span class="cx"> {
</span><span class="lines">@@ -5177,14 +3272,14 @@
</span><span class="cx">   iconv_res = iconv(iconv_format, &amp;inbuf, &amp;inbytesleft, &amp;outbuf, &amp;outbytesleft);
</span><span class="cx">   if (iconv_res == (size_t) - 1) {
</span><span class="cx">     DEBUGA_SKYPE(&quot;ciao in=%s, inleft=%d, out=%s, outleft=%d, converted=%s, utf8_out=%s\n&quot;,
</span><del>-              SKYPIAX_P_LOG, inbuf, inbytesleft, outbuf, outbytesleft, converted,
</del><ins>+              SKYPIAX_P_LOG, inbuf, (int)inbytesleft, outbuf, (int)outbytesleft, converted,
</ins><span class="cx">               utf8_out);
</span><span class="cx">     DEBUGA_SKYPE(&quot;error: %s %d\n&quot;, SKYPIAX_P_LOG, strerror(errno), errno);
</span><span class="cx">     return -1;
</span><span class="cx">   }
</span><span class="cx">   DEBUGA_SKYPE
</span><span class="cx">     (&quot;iconv_res=%d,  in=%s, inleft=%d, out=%s, outleft=%d, converted=%s, utf8_out=%s\n&quot;,
</span><del>-     SKYPIAX_P_LOG, iconv_res, inbuf, inbytesleft, outbuf, outbytesleft, converted,
</del><ins>+     SKYPIAX_P_LOG, iconv_res, inbuf, (int)inbytesleft, outbuf, (int)outbytesleft, converted,
</ins><span class="cx">      utf8_out);
</span><span class="cx">   iconv_close(iconv_format);
</span><span class="cx"> 
</span><span class="lines">@@ -5217,7 +3312,7 @@
</span><span class="cx">   outbytesleft = 16000;
</span><span class="cx"> 
</span><span class="cx">   DEBUGA_SKYPE(&quot;in=%s, inleft=%d, out=%s, outleft=%d, utf_in=%s, converted=%s\n&quot;,
</span><del>-            SKYPIAX_P_LOG, inbuf, inbytesleft, outbuf, outbytesleft, utf_in, converted);
</del><ins>+            SKYPIAX_P_LOG, inbuf, (int)inbytesleft, outbuf, (int)outbytesleft, utf_in, converted);
</ins><span class="cx">   iconv_res = iconv(iconv_format, &amp;inbuf, &amp;inbytesleft, &amp;outbuf, &amp;outbytesleft);
</span><span class="cx">   if (iconv_res == (size_t) - 1) {
</span><span class="cx">     ERRORA(&quot;error: %s %d\n&quot;, SKYPIAX_P_LOG, strerror(errno), errno);
</span><span class="lines">@@ -5225,7 +3320,7 @@
</span><span class="cx">   }
</span><span class="cx">   DEBUGA_SKYPE
</span><span class="cx">     (&quot;iconv_res=%d,  in=%s, inleft=%d, out=%s, outleft=%d, utf_in=%s, converted=%s\n&quot;,
</span><del>-     SKYPIAX_P_LOG, iconv_res, inbuf, inbytesleft, outbuf, outbytesleft, utf_in,
</del><ins>+     SKYPIAX_P_LOG, iconv_res, inbuf, (int)inbytesleft, outbuf, (int)outbytesleft, utf_in,
</ins><span class="cx">      converted);
</span><span class="cx">   iconv_close(iconv_format);
</span><span class="cx"> 
</span><span class="lines">@@ -5243,3843 +3338,234 @@
</span><span class="cx">   return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-int celliax_sendsms(struct ast_channel *c, void *data)
-{
-  char *idest = data;
-  char rdest[256];
-  private_t * tech_pvt = NULL;
-  char *device;
-  char *dest;
-  char *text;
-  char *stringp = NULL;
-  int found = 0;
-  int failed = 0;
</del><span class="cx"> 
</span><del>-  strncpy(rdest, idest, sizeof(rdest) - 1);
-  ast_log(LOG_DEBUG, &quot;CelliaxSendsms: %s\n&quot;, rdest);
-  ast_log(LOG_DEBUG, &quot;START\n&quot;);
-  /* we can use celliax_request to get the channel, but celliax_request would look for onowned channels, and probably we can send SMSs while a call is ongoing
-   *
-   */
</del><span class="cx"> 
</span><del>-  stringp = rdest;
-  device = strsep(&amp;stringp, &quot;/&quot;);
-  dest = strsep(&amp;stringp, &quot;|&quot;);
-  text = strsep(&amp;stringp, &quot;|&quot;);
</del><span class="cx"> 
</span><del>-  if (!device) {
-    ast_log(LOG_ERROR,
-            &quot;CelliaxSendsms app do not recognize '%s'. Requires a destination with slashes (interfacename/destinationnumber, TEXT)\n&quot;,
-            idest);
-    return -1;
-  }
-
-  if (!dest) {
-    ast_log(LOG_ERROR,
-            &quot;CelliaxSendsms app do not recognize '%s'. Requires a destination with slashes (interfacename/destinationnumber, TEXT)\n&quot;,
-            idest);
-    return -1;
-  }
-
-  if (!text) {
-    ast_log(LOG_ERROR,
-            &quot;CelliaxSendsms app do not recognize '%s'. Requires a destination with slashes (interfacename/destinationnumber, TEXT)\n&quot;,
-            idest);
-    return -1;
-  }
-
-  ast_log(LOG_DEBUG, &quot;interfacename:%s, destinationnumber:%s, text:%s\n&quot;, device, dest,
-          text);
-
-  /* lock the interfaces' list */
-  LOKKA(&amp;celliax_iflock);
-  /* make a pointer to the first interface in the interfaces list */
-  p = celliax_iflist;
-  /* Search for the requested interface and verify if is unowned */
-  //TODO implement groups a la chan_zap
-  while (p) {
-    size_t length = strlen(p-&gt;name);
-    /* is this the requested interface? */
-    if (strncmp(device, p-&gt;name, length) == 0) {
-      /* this is the requested interface! */
-      if (option_debug)
-        DEBUGA_SKYPE(&quot;FOUND! interfacename:%s, destinationnumber:%s, text:%s, p-&gt;name=%s\n&quot;,
-                  SKYPIAX_P_LOG, device, dest, text, p-&gt;name);
-      found = 1;
-      break;
-
-    }
-    /* not yet found, next please */
-    p = p-&gt;next;
-  }
-  /* unlock the interfaces' list */
-  UNLOCKA(&amp;celliax_iflock);
-
-  if (!found) {
-    ast_log(LOG_ERROR, &quot;Interface '%s' requested by CelliaxSendsms NOT FOUND\n&quot;, device);
-    return RESULT_FAILURE;
-  }
-
-  if (p-&gt;controldevprotocol != PROTOCOL_AT) {
-    ERRORA(&quot;CelliaxSendsms supports only AT command cellphones at the moment :-( !\n&quot;,
-           SKYPIAX_P_LOG);
-    return RESULT_FAILURE;
-  }
-
-  if (p-&gt;controldevprotocol == PROTOCOL_AT) {
-    int err = 0;
-    char smscommand[16000];
-    memset(smscommand, '\0', sizeof(smscommand));
-
-    PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-    LOKKA(&amp;p-&gt;controldev_lock);
-
-    if (p-&gt;no_ucs2) {
-      sprintf(smscommand, &quot;AT+CMGS=\&quot;%s\&quot;&quot;, dest);  //TODO: support phones that only accept pdu mode
-    } else {
-      char dest2[1048];
-
-          err = celliax_serial_write_AT_ack(p, &quot;AT+CSCS=\&quot;UCS2\&quot;&quot;);
-          if (err) {
-            ERRORA
-              (&quot;AT+CSCS=\&quot;UCS2\&quot; (set TE messages to ucs2)  do not got OK from the phone\n&quot;,
-               SKYPIAX_P_LOG);
-          }
-
-      memset(dest2, '\0', sizeof(dest2));
-      utf_to_ucs2(p, dest, strlen(dest), dest2, sizeof(dest2));
-      sprintf(smscommand, &quot;AT+CMGS=\&quot;%s\&quot;&quot;, dest2); //TODO: support phones that only accept pdu mode
-    }
-    //TODO: support phones that only accept pdu mode
-    //TODO would be better to lock controldev here
-    err = celliax_serial_write_AT_noack(p, smscommand);
-    if (err) {
-      ERRORA(&quot;Error sending SMS\n&quot;, SKYPIAX_P_LOG);
-      failed = 1;
-      goto uscita;
-    }
-    err = celliax_serial_AT_expect(p, &quot;&gt; &quot;, 0, 1);  // wait 1.5s for the prompt, no  crlf
-#if 1
-    if (err) {
-      DEBUGA_SKYPE
-        (&quot;Error or timeout getting prompt '&gt; ' for sending sms directly to the remote party. BTW, seems that we cannot do that with Motorola c350, so we'll write to cellphone memory, then send from memory\n&quot;,
-         SKYPIAX_P_LOG);
-
-      err = celliax_serial_write_AT_ack(p, &quot;ATE1&quot;); //motorola (at least c350) do not echo the '&gt;' prompt when in ATE0... go figure!!!!
-      if (err) {
-        ERRORA(&quot;Error activating echo from modem\n&quot;, SKYPIAX_P_LOG);
-      }
-      p-&gt;at_cmgw[0] = '\0';
-      sprintf(smscommand, &quot;AT+CMGW=\&quot;%s\&quot;&quot;, dest);  //TODO: support phones that only accept pdu mode
-      err = celliax_serial_write_AT_noack(p, smscommand);
-      if (err) {
-        ERRORA(&quot;Error writing SMS destination to the cellphone memory\n&quot;, SKYPIAX_P_LOG);
-        failed = 1;
-        goto uscita;
-      }
-      err = celliax_serial_AT_expect(p, &quot;&gt; &quot;, 0, 1);    // wait 1.5s for the prompt, no  crlf
-      if (err) {
-        ERRORA
-          (&quot;Error or timeout getting prompt '&gt; ' for writing sms text in cellphone memory\n&quot;,
-           SKYPIAX_P_LOG);
-        failed = 1;
-        goto uscita;
-      }
-    }
-#endif
-
-    //sprintf(text,&quot;ciao 123 belè новости לק ראת ﺎﻠﺠﻤﻋﺓ 人大&quot;); //let's test the beauty of utf
-    memset(smscommand, '\0', sizeof(smscommand));
-    if (p-&gt;no_ucs2) {
-      sprintf(smscommand, &quot;%s&quot;, text);
-    } else {
-      utf_to_ucs2(p, text, strlen(text), smscommand, sizeof(smscommand));
-    }
-
-    smscommand[strlen(smscommand)] = 0x1A;
-    DEBUGA_SKYPE(&quot;smscommand len is: %d, text is:|||%s|||\n&quot;, SKYPIAX_P_LOG,
-              strlen(smscommand), smscommand);
-
-    err = celliax_serial_write_AT_ack_nocr_longtime(p, smscommand);
-    //TODO would be better to unlock controldev here
-    if (err) {
-      ERRORA(&quot;Error writing SMS text to the cellphone memory\n&quot;, SKYPIAX_P_LOG);
-      //return RESULT_FAILURE;
-      failed = 1;
-      goto uscita;
-    }
-    if (p-&gt;at_cmgw[0]) {
-      sprintf(smscommand, &quot;AT+CMSS=%s&quot;, p-&gt;at_cmgw);
-      err = celliax_serial_write_AT_expect_longtime(p, smscommand, &quot;OK&quot;);
-      if (err) {
-        ERRORA(&quot;Error sending SMS from the cellphone memory\n&quot;, SKYPIAX_P_LOG);
-        //return RESULT_FAILURE;
-        failed = 1;
-        goto uscita;
-      }
-
-      err = celliax_serial_write_AT_ack(p, &quot;ATE0&quot;); //motorola (at least c350) do not echo the '&gt;' prompt when in ATE0... go figure!!!!
-      if (err) {
-        ERRORA(&quot;Error de-activating echo from modem\n&quot;, SKYPIAX_P_LOG);
-      }
-    }
-  uscita:
-    usleep(1000);
-
-    if (p-&gt;at_cmgw[0]) {
-
-      /* let's see what we've sent, just for check TODO: Motorola it's not reliable! Motorola c350 tells that all was sent, but is not true! It just sends how much it fits into one SMS FIXME: need an algorithm to calculate how many ucs2 chars fits into an SMS. It make difference based, probably, on the GSM alphabet translation, or so */
-      sprintf(smscommand, &quot;AT+CMGR=%s&quot;, p-&gt;at_cmgw);
-      err = celliax_serial_write_AT_ack(p, smscommand);
-      if (err) {
-        ERRORA(&quot;Error reading SMS back from the cellphone memory\n&quot;, SKYPIAX_P_LOG);
-      }
-
-      /* let's delete from cellphone memory what we've sent */
-      sprintf(smscommand, &quot;AT+CMGD=%s&quot;, p-&gt;at_cmgw);
-      err = celliax_serial_write_AT_ack(p, smscommand);
-      if (err) {
-        ERRORA(&quot;Error deleting SMS from the cellphone memory\n&quot;, SKYPIAX_P_LOG);
-      }
-
-      p-&gt;at_cmgw[0] = '\0';
-    }
-    //usleep(500000);             //.5 secs
-    UNLOCKA(&amp;p-&gt;controldev_lock);
-    POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  }
-
-  ast_log(LOG_DEBUG, &quot;FINISH\n&quot;);
-  if (failed)
-    return -1;
-  else
-    return RESULT_SUCCESS;
-}
-
-#ifdef CELLIAX_DIR
-/* For simplicity, I'm keeping the format compatible with the voicemail config,
-   but i'm open to suggestions for isolating it */
-#define CELLIAX_DIR_CONFIG &quot;directoriax.conf&quot;
-
-/* How many digits to read in */
-#define CELLIAX_DIR_NUMDIGITS 3
-
-struct ast_config *celliax_dir_realtime(char *context)
</del><ins>+#ifdef NOTDEF
+int celliax_serial_call_AT(private_t * tech_pvt, char *dstr)
</ins><span class="cx"> {
</span><del>-  //TODO: all the realtime stuff has to be re-made
-  struct ast_config *cfg;
-  private_t * tech_pvt = NULL;
-#ifdef ASTERISK_VERSION_1_6_0
-  struct ast_flags config_flags = { 0 };
-#endif /* ASTERISK_VERSION_1_6_0 */
-
-  /* Load flat file config. */
-#ifdef ASTERISK_VERSION_1_6_0
-  cfg = ast_config_load(CELLIAX_DIR_CONFIG, config_flags);
-#else
-  cfg = ast_config_load(CELLIAX_DIR_CONFIG);
-#endif /* ASTERISK_VERSION_1_6_0 */
-
-  if (!cfg) {
-    /* Loading config failed. */
-    WARNINGA
-      (&quot;Loading directoriax.conf config file failed. It's not necessary, continuing.\n&quot;,
-       SKYPIAX_P_LOG);
-    return NULL;
-  }
-  return cfg;
-}
-
-static char *celliax_dir_convert(char *lastname)
-{
-  char *tmp;
-  int lcount = 0;
-  tmp = malloc(CELLIAX_DIR_NUMDIGITS + 1);
-  if (tmp) {
-    while ((*lastname &gt; 32) &amp;&amp; lcount &lt; CELLIAX_DIR_NUMDIGITS) {
-      switch (toupper(*lastname)) {
-      case '1':
-        tmp[lcount++] = '1';
-        break;
-      case '2':
-      case 'A':
-      case 'B':
-      case 'C':
-        tmp[lcount++] = '2';
-        break;
-      case '3':
-      case 'D':
-      case 'E':
-      case 'F':
-        tmp[lcount++] = '3';
-        break;
-      case '4':
-      case 'G':
-      case 'H':
-      case 'I':
-        tmp[lcount++] = '4';
-        break;
-      case '5':
-      case 'J':
-      case 'K':
-      case 'L':
-        tmp[lcount++] = '5';
-        break;
-      case '6':
-      case 'M':
-      case 'N':
-      case 'O':
-        tmp[lcount++] = '6';
-        break;
-      case '7':
-      case 'P':
-      case 'Q':
-      case 'R':
-      case 'S':
-        tmp[lcount++] = '7';
-        break;
-      case '8':
-      case 'T':
-      case 'U':
-      case 'V':
-        tmp[lcount++] = '8';
-        break;
-      case '9':
-      case 'W':
-      case 'X':
-      case 'Y':
-      case 'Z':
-        tmp[lcount++] = '9';
-        break;
-      }
-      lastname++;
-    }
-    tmp[lcount] = '\0';
-  }
-  return tmp;
-}
-
-int celliax_console_celliax_dir_export(int fd, int argc, char *argv[])
-{
-  struct ast_config *cfg;
-
-  struct ast_variable *v;
-  char *start, *pos, *stringp, *space, *options = NULL, *conv = NULL;
-  private_t * tech_pvt = celliax_console_find_desc(celliax_console_active);
-  char *context = &quot;default&quot;;
-  char *s;
-  char *var, *value;
-  int fromcell = 0;
-  int fromskype = 0;
-  char name[256] = &quot;&quot;;
-  char phonebook_direct_calling_ext[7] = &quot;&quot;;
-  char write_entry_command[256] = &quot;&quot;;
-  char entry_number[256] = &quot;&quot;;
-  char entry_text[256] = &quot;&quot;;
-  char final_entry_text[256] = &quot;&quot;;
</del><span class="cx">   int res;
</span><del>-  int tocell = 0;
-#ifdef CELLIAX_LIBCSV
-  int tocsv = 0;
-  int tovcf = 0;
-#endif /* CELLIAX_LIBCSV */
</del><ins>+  char at_command[256];
</ins><span class="cx"> 
</span><del>-  if (argc &lt; 3 || argc &gt; 4)
-    return RESULT_SHOWUSAGE;
-  if (!p) {
-    ast_cli(fd, &quot;No \&quot;current\&quot; console ???, please enter 'help celliax_console'\n&quot;);
-    return RESULT_SUCCESS;
-  }
-
-  if (!strcasecmp(argv[1], &quot;tocell&quot;))
-    tocell = 1;
-#ifdef CELLIAX_LIBCSV
-  else if (!strcasecmp(argv[1], &quot;tocsv&quot;))
-    tocsv = 1;
-  else if (!strcasecmp(argv[1], &quot;tovcf&quot;))
-    tovcf = 1;
-#endif /* CELLIAX_LIBCSV */
-  else {
-    ast_cli(fd,
-#ifdef CELLIAX_LIBCSV
-            &quot;\n\nYou have neither specified 'tocell' nor 'tocsv'\n\n&quot;);
-#else /* CELLIAX_LIBCSV */
-            &quot;\n\nYou have not specified 'tocell'\n\n&quot;);
-#endif /* CELLIAX_LIBCSV */
-    return RESULT_SHOWUSAGE;
-  }
-  if (tocell)
-    if (p-&gt;controldevprotocol != PROTOCOL_AT) {
-      ast_cli(fd,
-              &quot;Exporting to the cellphone phonebook is currently supported only on \&quot;AT\&quot; cellphones :( !\n&quot;);
-      return RESULT_SUCCESS;
-    }
-#ifdef CELLIAX_LIBCSV
-  if (tocsv || tovcf)
-    if (argc != 4) {
-      ast_cli(fd, &quot;\n\nYou have to specify a filename with 'tocsv'\n\n&quot;);
-      return RESULT_SHOWUSAGE;
-    }
-#endif /* CELLIAX_LIBCSV */
-
</del><span class="cx">   if (option_debug)
</span><del>-    NOTICA(&quot;celliax_cellphonenumber is: %s\n&quot;, SKYPIAX_P_LOG, argv[2]);
-
-#ifdef CELLIAX_LIBCSV
-  if (tocsv) {
-    if (option_debug)
-      NOTICA(&quot;filename is: %s\n&quot;, SKYPIAX_P_LOG, argv[3]);
-    //ast_cli(fd, &quot;\n\nnot yet implemented :P \n&quot;);
-    //return RESULT_SUCCESS;
</del><ins>+    DEBUGA_PBX(&quot;Dialing %s\n&quot;, SKYPIAX_P_LOG, dstr);
+  memset(at_command, 0, sizeof(at_command));
+  tech_pvt-&gt;phone_callflow = CALLFLOW_CALL_DIALING;
+  tech_pvt-&gt;interface_state = SKYPIAX_STATE_DIALING;
+  ast_uri_decode(dstr);
+  size_t fixdstr = strspn(dstr, SKYPIAX_DIGIT_ANYDIG);
+  if (fixdstr == 0) {
+    ERRORA(&quot;dial command failed because of invalid dial number. dial string was: %s\n&quot;,
+           SKYPIAX_P_LOG, dstr);
+    return -1;
</ins><span class="cx">   }
</span><del>-  if (tovcf) {
-    if (option_debug)
-      NOTICA(&quot;filename is: %s\n&quot;, SKYPIAX_P_LOG, argv[3]);
-    ast_cli(fd, &quot;\n\nnot yet implemented :P \n&quot;);
-    return RESULT_SUCCESS;
-  }
-#endif /* CELLIAX_LIBCSV */
-
-  cfg = celliax_dir_realtime(context);
-  if (!cfg) {
</del><ins>+  dstr[fixdstr] = '\0';
+  sprintf(at_command, &quot;%s%s%s&quot;, tech_pvt-&gt;at_dial_pre_number, dstr, tech_pvt-&gt;at_dial_post_number);
+  res = celliax_serial_write_AT_expect(tech_pvt, at_command, tech_pvt-&gt;at_dial_expect);
+  if (res) {
+    ERRORA(&quot;dial command failed, dial string was: %s\n&quot;, SKYPIAX_P_LOG, at_command);
</ins><span class="cx">     return -1;
</span><span class="cx">   }
</span><del>-
-  if (tocell) {
-    /* which phonebook to use, use the SIM  */
-    res = celliax_serial_write_AT_ack(p, &quot;AT+CPBS=SM&quot;);
-    if (res) {
-      WARNINGA(&quot;AT+CPBS=SM failed, continue\n&quot;, SKYPIAX_P_LOG);
-    }
-    /* which phonebook to use, trying to use phone, not SIM  */
-    res = celliax_serial_write_AT_ack(p, &quot;AT+CPBS=ME&quot;);
-    if (res) {
-      WARNINGA(&quot;AT+CPBS=ME failed, continue\n&quot;, SKYPIAX_P_LOG);
-    }
-    /* retrieve the fields lenght in the selected phonebook  */
-    p-&gt;phonebook_querying = 1;
-    res = celliax_serial_write_AT_ack(p, &quot;AT+CPBR=?&quot;);
-    if (res) {
-      WARNINGA(&quot;AT+CPBR=? failed, continue\n&quot;, SKYPIAX_P_LOG);
-    }
-    p-&gt;phonebook_querying = 0;
-
-    v = ast_variable_browse(cfg, context);
-    /* Find all candidate extensions */
-    while (v) {
-      /* Find a candidate extension */
-      start = strdup(v-&gt;value);
-      if (strcasestr(start, &quot;fromcell=yes&quot;)) {
-        fromcell = 1;
-        fromskype = 0;
-
-      }
-      if (strcasestr(start, &quot;fromskype=yes&quot;)) {
-        fromcell = 0;
-        fromskype = 1;
-
-      }
-
-      if (start &amp;&amp; !strcasestr(start, &quot;hidefromdir=yes&quot;)) {
-        memset(name, 0, sizeof(name));
-        memset(phonebook_direct_calling_ext, 0, sizeof(phonebook_direct_calling_ext));
-        memset(write_entry_command, 0, sizeof(write_entry_command));
-        memset(entry_number, 0, sizeof(entry_number));
-        memset(entry_text, 0, sizeof(entry_text));
-        memset(final_entry_text, 0, sizeof(final_entry_text));
-
-        DEBUGA_SKYPE(&quot;v-&gt;name=%s\n&quot;, SKYPIAX_P_LOG, v-&gt;name);
-        DEBUGA_SKYPE(&quot;v-&gt;value=%s\n&quot;, SKYPIAX_P_LOG, v-&gt;value);
-
-        stringp = start;
-        strsep(&amp;stringp, &quot;,&quot;);
-        pos = strsep(&amp;stringp, &quot;,&quot;);
-        if (pos) {
-          ast_copy_string(name, pos, sizeof(name));
-          if (strchr(pos, ' ')) {
-            space = strchr(pos, ' ');
-            *space = '\0';
-          }
-          if (pos) {
-            conv = celliax_dir_convert(pos);
-            DEBUGA_SKYPE(&quot;&lt;pos=&gt;%s&lt;conv=&gt;%s&lt;\n&quot;, SKYPIAX_P_LOG, pos, conv);
-
-            options = strdup(v-&gt;value);
-            strsep(&amp;options, &quot;,&quot;);
-            strsep(&amp;options, &quot;,&quot;);
-            strsep(&amp;options, &quot;,&quot;);
-            strsep(&amp;options, &quot;,&quot;);
-            DEBUGA_SKYPE(&quot;options=%s\n&quot;, SKYPIAX_P_LOG, options);
-
-            while ((s = strsep(&amp;options, &quot;|&quot;))) {
-              value = s;
-              if ((var = strsep(&amp;value, &quot;=&quot;)) &amp;&amp; value) {
-                DEBUGA_SKYPE(&quot;var=%s value=%s\n&quot;, SKYPIAX_P_LOG, var, value);
-                if (!strcmp(var, &quot;phonebook_direct_calling_ext&quot;))
-                  strncpy(phonebook_direct_calling_ext, value, 6);
-              }
-            }
-
-            res =
-              snprintf(entry_number, p-&gt;phonebook_number_lenght + 1, &quot;%s%s%d%s%s&quot;,
-                       argv[2], &quot;p&quot;, p-&gt;celliax_dir_prefix, &quot;p&quot;,
-                       phonebook_direct_calling_ext);
-            if (res == (p-&gt;phonebook_number_lenght + 1)
-                || res &gt; (p-&gt;phonebook_number_lenght + 1)) {
-              ERRORA(&quot;entry_number truncated, was: '%s%s%d%s%s', now is: '%s'\n&quot;,
-                     SKYPIAX_P_LOG, argv[2], &quot;p&quot;, p-&gt;celliax_dir_prefix, &quot;p&quot;,
-                     phonebook_direct_calling_ext, entry_number);
-              //FIXME: abort ???
-
-            }
-
-            res = snprintf(final_entry_text, p-&gt;phonebook_text_lenght + 1, &quot;%s&quot;, name); //FIXME result not checked
-
-            res =
-              snprintf(write_entry_command, sizeof(write_entry_command) - 1,
-                       &quot;AT+CPBW=,\&quot;%s\&quot;,,\&quot;%s\&quot;&quot;, entry_number, final_entry_text);
-            if (res == (sizeof(write_entry_command) - 1)
-                || res &gt; (sizeof(write_entry_command) - 1)) {
-              WARNINGA
-                (&quot;write_entry_command truncated, was supposed: 'AT+CPBW=,\&quot;%s\&quot;,,\&quot;%s\&quot;', now is: '%s'\n&quot;,
-                 SKYPIAX_P_LOG, entry_number, final_entry_text, write_entry_command);
-            }
-            //if (option_debug)
-            NOTICA(&quot;%s\n&quot;, SKYPIAX_P_LOG, write_entry_command);
-          }
-        }
-        if (conv)
-          free(conv);
-        if (start)
-          free(start);
-        if (options)
-          free(options);
-      }
-      v = v-&gt;next;
-    }
</del><ins>+  // jet - early audio
+  if (tech_pvt-&gt;at_early_audio) {
+    ast_queue_control(tech_pvt-&gt;owner, SKYPIAX_CONTROL_ANSWER);
</ins><span class="cx">   }
</span><del>-#ifdef CELLIAX_LIBCSV
-  if (tocsv) {
</del><span class="cx"> 
</span><del>-    v = ast_variable_browse(cfg, context);
-    /* Find all candidate extensions */
-    while (v) {
-      /* Find a candidate extension */
-      start = strdup(v-&gt;value);
-      if (strcasestr(start, &quot;fromcell=yes&quot;)) {
-        fromcell = 1;
-        fromskype = 0;
-
-      }
-      if (strcasestr(start, &quot;fromskype=yes&quot;)) {
-        fromcell = 0;
-        fromskype = 1;
-
-      }
-
-      if (start &amp;&amp; !strcasestr(start, &quot;hidefromdir=yes&quot;)) {
-        memset(name, 0, sizeof(name));
-        memset(phonebook_direct_calling_ext, 0, sizeof(phonebook_direct_calling_ext));
-        memset(write_entry_command, 0, sizeof(write_entry_command));
-        memset(entry_number, 0, sizeof(entry_number));
-        memset(entry_text, 0, sizeof(entry_text));
-        memset(final_entry_text, 0, sizeof(final_entry_text));
-
-        DEBUGA_SKYPE(&quot;v-&gt;name=%s\n&quot;, SKYPIAX_P_LOG, v-&gt;name);
-        DEBUGA_SKYPE(&quot;v-&gt;value=%s\n&quot;, SKYPIAX_P_LOG, v-&gt;value);
-
-        stringp = start;
-        strsep(&amp;stringp, &quot;,&quot;);
-        pos = strsep(&amp;stringp, &quot;,&quot;);
-        if (pos) {
-          ast_copy_string(name, pos, sizeof(name));
-          if (strchr(pos, ' ')) {
-            space = strchr(pos, ' ');
-            *space = '\0';
-          }
-          if (pos) {
-            conv = celliax_dir_convert(pos);
-            DEBUGA_SKYPE(&quot;&lt;pos=&gt;%s&lt;conv=&gt;%s&lt;\n&quot;, SKYPIAX_P_LOG, pos, conv);
-
-            options = strdup(v-&gt;value);
-            strsep(&amp;options, &quot;,&quot;);
-            strsep(&amp;options, &quot;,&quot;);
-            strsep(&amp;options, &quot;,&quot;);
-            strsep(&amp;options, &quot;,&quot;);
-            DEBUGA_SKYPE(&quot;options=%s\n&quot;, SKYPIAX_P_LOG, options);
-
-            while ((s = strsep(&amp;options, &quot;|&quot;))) {
-              value = s;
-              if ((var = strsep(&amp;value, &quot;=&quot;)) &amp;&amp; value) {
-                DEBUGA_SKYPE(&quot;var=%s value=%s\n&quot;, SKYPIAX_P_LOG, var, value);
-                if (!strcmp(var, &quot;phonebook_direct_calling_ext&quot;))
-                  strncpy(phonebook_direct_calling_ext, value, 6);
-              }
-            }
-
-            //FIXME choose a logic for fields maximum lenght
-            res =
-              snprintf(entry_number, sizeof(entry_number) - 1, &quot;%s%s%d%s%s&quot;, argv[2], &quot;p&quot;,
-                       p-&gt;celliax_dir_prefix, &quot;p&quot;, phonebook_direct_calling_ext);
-            if (res == (sizeof(entry_number) - 1)
-                || res &gt; (sizeof(entry_number) - 1)) {
-              ERRORA(&quot;entry_number truncated, was: '%s%s%d%s%s', now is: '%s'\n&quot;,
-                     SKYPIAX_P_LOG, argv[2], &quot;p&quot;, p-&gt;celliax_dir_prefix, &quot;p&quot;,
-                     phonebook_direct_calling_ext, entry_number);
-              //FIXME: abort ???
-
-            }
-
-            res = snprintf(final_entry_text, sizeof(final_entry_text) - 1, &quot;%s&quot;, name); //FIXME result not checked
-
-            int i, a;
-
-            a = 0;
-            for (i = 0; i &lt; p-&gt;csv_complete_name_pos - 1; i++) {
-              if (p-&gt;csv_separator_is_semicolon)
-                write_entry_command[a] = ';';
-              else
-                write_entry_command[a] = ',';
-              a++;
-            }
-            //NOTICA(&quot;i=%d a=%d\n&quot;, SKYPIAX_P_LOG, i, a);
-
-            write_entry_command[a] = '&quot;';
-            a++;
-            //NOTICA(&quot;i=%d a=%d\n&quot;, SKYPIAX_P_LOG, i, a);
-            for (i = 0; i &lt; strlen(final_entry_text); i++) {
-              write_entry_command[a] = final_entry_text[i];
-              a++;
-            }
-            //NOTICA(&quot;i=%d a=%d\n&quot;, SKYPIAX_P_LOG, i, a);
-            write_entry_command[a] = '&quot;';
-            a++;
-            //NOTICA(&quot;i=%d a=%d\n&quot;, SKYPIAX_P_LOG, i, a);
-            for (i = 0; i &lt; (p-&gt;csv_business_phone_pos - p-&gt;csv_complete_name_pos); i++) {
-              if (p-&gt;csv_separator_is_semicolon)
-                write_entry_command[a] = ';';
-              else
-                write_entry_command[a] = ',';
-              a++;
-            }
-
-            //NOTICA(&quot;i=%d a=%d\n&quot;, SKYPIAX_P_LOG, i, a);
-
-            write_entry_command[a] = '&quot;';
-            a++;
-            //NOTICA(&quot;i=%d a=%d\n&quot;, SKYPIAX_P_LOG, i, a);
-            for (i = 0; i &lt; strlen(entry_number); i++) {
-              write_entry_command[a] = entry_number[i];
-              a++;
-            }
-            //NOTICA(&quot;i=%d a=%d\n&quot;, SKYPIAX_P_LOG, i, a);
-            write_entry_command[a] = '&quot;';
-            a++;
-            //NOTICA(&quot;i=%d a=%d\n&quot;, SKYPIAX_P_LOG, i, a);
-
-            if (option_debug)
-              NOTICA(&quot;%s\n&quot;, SKYPIAX_P_LOG, write_entry_command);
-          }
-        }
-        if (conv)
-          free(conv);
-        if (start)
-          free(start);
-        if (options)
-          free(options);
-      }
-      v = v-&gt;next;
-    }
-
-  }
-  if (tovcf) {
-//TODO implementation here
-  }
-#endif /*  CELLIAX_LIBCSV */
-  ast_config_destroy(cfg);
</del><span class="cx">   return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#ifdef CELLIAX_LIBCSV
-
-void celliax_cb1(char *s, size_t len, void *data)
</del><ins>+int celliax_console_at(int fd, int argc, char *argv[])
</ins><span class="cx"> {
</span><del>-  private_t * tech_pvt = data;
-  char field_content[256];
-
-  p-&gt;csv_fields++;
-  memset(field_content, 0, sizeof(field_content));
-  strncpy(field_content, s,
-          sizeof(field_content) &gt; (len + 1) ? len : (sizeof(field_content) - 1));
-  if (p-&gt;csv_fields == p-&gt;csv_complete_name_pos) {
-    strncpy(p-&gt;csv_complete_name, field_content, sizeof(p-&gt;csv_complete_name) - 1);
-  }
-  if (p-&gt;csv_fields == p-&gt;csv_email_pos) {
-    strncpy(p-&gt;csv_email, field_content, sizeof(p-&gt;csv_email) - 1);
-  }
-  if (p-&gt;csv_fields == p-&gt;csv_home_phone_pos) {
-    strncpy(p-&gt;csv_home_phone, field_content, sizeof(p-&gt;csv_home_phone) - 1);
-  }
-  if (p-&gt;csv_fields == p-&gt;csv_mobile_phone_pos) {
-    strncpy(p-&gt;csv_mobile_phone, field_content, sizeof(p-&gt;csv_mobile_phone) - 1);
-  }
-  if (p-&gt;csv_fields == p-&gt;csv_business_phone_pos) {
-    strncpy(p-&gt;csv_business_phone, field_content, sizeof(p-&gt;csv_business_phone) - 1);
-  }
-}
-
-void celliax_cb2(char c, void *data)
-{
-  private_t * tech_pvt = data;
-
-  p-&gt;csv_rows++;
-  p-&gt;csv_fields = 0;
-
-  if (p-&gt;csv_first_row_is_title &amp;&amp; p-&gt;csv_rows == 1) {
-    //do nothing
-  } else {
-    if (strlen(p-&gt;csv_complete_name)) {
-      if (option_debug)
-        NOTICA
-          (&quot;ROW %d ENDED, complete_name=%s, email=%s, home_phone=%s, mobile_phone=%s, business_phone=%s\n&quot;,
-           SKYPIAX_P_LOG, p-&gt;csv_rows,
-           strlen(p-&gt;csv_complete_name) ? p-&gt;csv_complete_name : &quot;N/A&quot;,
-           strlen(p-&gt;csv_email) ? p-&gt;csv_email : &quot;N/A&quot;,
-           strlen(p-&gt;csv_home_phone) ? p-&gt;csv_home_phone : &quot;N/A&quot;,
-           strlen(p-&gt;csv_mobile_phone) ? p-&gt;csv_mobile_phone : &quot;N/A&quot;,
-           strlen(p-&gt;csv_business_phone) ? p-&gt;csv_business_phone : &quot;N/A&quot;);
-    }
-
-    /* write entries in phonebook file */
-    if (p-&gt;phonebook_writing_fp) {
-      celliax_dir_entry_extension++;
-
-      if (strlen(p-&gt;csv_complete_name)) {
-        /* let's start with home_phone */
-        if (strlen(p-&gt;csv_home_phone)) {
-          fprintf(p-&gt;phonebook_writing_fp,
-                  &quot;%s  =&gt; ,%s %sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromcsv=%s|phonebook_entry_owner=%s\n&quot;,
-                  p-&gt;csv_home_phone, p-&gt;csv_complete_name, &quot;HOME&quot;, &quot;no&quot;,
-                  p-&gt;celliax_dir_entry_extension_prefix, &quot;2&quot;, celliax_dir_entry_extension,
-                  &quot;yes&quot;, &quot;not_specified&quot;);
-          fprintf(p-&gt;phonebook_writing_fp,
-                  &quot;%s  =&gt; ,%s %sDO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromcsv=%s|phonebook_entry_owner=%s\n&quot;,
-                  p-&gt;csv_home_phone, p-&gt;csv_complete_name, &quot;HOME&quot;, &quot;no&quot;,
-                  p-&gt;celliax_dir_entry_extension_prefix, &quot;3&quot;, celliax_dir_entry_extension,
-                  &quot;yes&quot;, &quot;not_specified&quot;);
-        }
-
-        /* now business_phone */
-        if (strlen(p-&gt;csv_business_phone)) {
-          fprintf(p-&gt;phonebook_writing_fp,
-                  &quot;%s  =&gt; ,%s %sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromcsv=%s|phonebook_entry_owner=%s\n&quot;,
-                  p-&gt;csv_business_phone, p-&gt;csv_complete_name, &quot;BIZ&quot;, &quot;no&quot;,
-                  p-&gt;celliax_dir_entry_extension_prefix, &quot;2&quot;, celliax_dir_entry_extension,
-                  &quot;yes&quot;, &quot;not_specified&quot;);
-          fprintf(p-&gt;phonebook_writing_fp,
-                  &quot;%s  =&gt; ,%s %sDO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromcsv=%s|phonebook_entry_owner=%s\n&quot;,
-                  p-&gt;csv_business_phone, p-&gt;csv_complete_name, &quot;BIZ&quot;, &quot;no&quot;,
-                  p-&gt;celliax_dir_entry_extension_prefix, &quot;3&quot;, celliax_dir_entry_extension,
-                  &quot;yes&quot;, &quot;not_specified&quot;);
-        }
-
-        /* let's end with mobile_phone */
-        if (strlen(p-&gt;csv_mobile_phone)) {
-          fprintf(p-&gt;phonebook_writing_fp,
-                  &quot;%s  =&gt; ,%s %sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromcsv=%s|phonebook_entry_owner=%s\n&quot;,
-                  p-&gt;csv_mobile_phone, p-&gt;csv_complete_name, &quot;CELL&quot;, &quot;no&quot;,
-                  p-&gt;celliax_dir_entry_extension_prefix, &quot;2&quot;, celliax_dir_entry_extension,
-                  &quot;yes&quot;, &quot;not_specified&quot;);
-          fprintf(p-&gt;phonebook_writing_fp,
-                  &quot;%s  =&gt; ,%s %sDO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromcsv=%s|phonebook_entry_owner=%s\n&quot;,
-                  p-&gt;csv_mobile_phone, p-&gt;csv_complete_name, &quot;CELL&quot;, &quot;no&quot;,
-                  p-&gt;celliax_dir_entry_extension_prefix, &quot;3&quot;, celliax_dir_entry_extension,
-                  &quot;yes&quot;, &quot;not_specified&quot;);
-        }
-      }
-
-    }
-
-  }
-}
-
-#endif /* CELLIAX_LIBCSV */
-
-int celliax_console_celliax_dir_import(int fd, int argc, char *argv[])
-{
-  int res;
</del><span class="cx">   private_t * tech_pvt = celliax_console_find_desc(celliax_console_active);
</span><del>-  char list_command[64];
-  char fn[256];
-  char date[256] = &quot;&quot;;
-  time_t t;
-  char *configfile = CELLIAX_DIR_CONFIG;
-  int add_to_celliax_dir_conf = 1;
-  //int fromskype = 0;
-  int fromcell = 0;
-#ifdef CELLIAX_LIBCSV
-  int fromcsv = 0;
-  int fromvcf = 0;
-#endif /* CELLIAX_LIBCSV */
</del><ins>+  char at_cmd[1024];
+  int i, a, c;
</ins><span class="cx"> 
</span><del>-  if (argc &lt; 3 || argc &gt; 4)
</del><ins>+  if (argc == 1)
</ins><span class="cx">     return RESULT_SHOWUSAGE;
</span><del>-  if (!p) {
-    ast_cli(fd, &quot;No \&quot;current\&quot; console ???, please enter 'help celliax_console'\n&quot;);
</del><ins>+  if (!tech_pvt) {
+    ast_cli(fd,
+            &quot;No \&quot;current\&quot; console for celliax_at, please enter 'help celliax_console'\n&quot;);
</ins><span class="cx">     return RESULT_SUCCESS;
</span><span class="cx">   }
</span><del>-
-  if (!strcasecmp(argv[1], &quot;add&quot;))
-    add_to_celliax_dir_conf = 1;
-  else if (!strcasecmp(argv[1], &quot;replace&quot;))
-    add_to_celliax_dir_conf = 0;
-  else {
-    ast_cli(fd, &quot;\n\nYou have neither specified 'add' nor 'replace'\n\n&quot;);
-    return RESULT_SHOWUSAGE;
-  }
-
-  //if (!strcasecmp(argv[2], &quot;fromskype&quot;))
-  //fromskype = 1;
-  //else 
-
-  if (!strcasecmp(argv[2], &quot;fromcell&quot;))
-    fromcell = 1;
-#ifdef CELLIAX_LIBCSV
-  else if (!strcasecmp(argv[2], &quot;fromcsv&quot;))
-    fromcsv = 1;
-  else if (!strcasecmp(argv[2], &quot;fromvcf&quot;))
-    fromvcf = 1;
-#endif /* CELLIAX_LIBCSV */
-  else {
-    ast_cli(fd, &quot;\n\nYou have neither specified 'fromcell' neither 'fromcsv'\n\n&quot;);
-    return RESULT_SHOWUSAGE;
-  }
-
-#ifdef CELLIAX_LIBCSV
-  if (fromcsv || fromvcf)
-    if (argc != 4) {
-      ast_cli(fd,
-              &quot;\n\nYou have to specify a filename with 'fromcsv' or with 'fromvcf'\n\n&quot;);
-      return RESULT_SHOWUSAGE;
-    }
-#endif /* CELLIAX_LIBCSV */
-  if (fromcell)
-    if (p-&gt;controldevprotocol != PROTOCOL_AT) {
-      ast_cli(fd,
-              &quot;Importing from cellphone is currently supported only on \&quot;AT\&quot; cellphones :( !\n&quot;);
-      //fclose(p-&gt;phonebook_writing_fp);
-      //celliax_dir_create_extensions();
-      return RESULT_SUCCESS;
-    }
-
-  if (fromcell)
-    if (argc != 3) {
-      ast_cli(fd, &quot;\n\nYou don't have to specify a filename with 'fromcell'\n\n&quot;);
-      return RESULT_SHOWUSAGE;
-    }
-#ifdef CELLIAX_LIBCSV
-  if (fromvcf) {
-    if (option_debug)
-      NOTICA(&quot;filename is: %s\n&quot;, SKYPIAX_P_LOG, argv[3]);
-    ast_cli(fd, &quot;\n\nnot yet implemented :P \n&quot;);
</del><ins>+  if (tech_pvt-&gt;controldevprotocol != PROTOCOL_AT) {
+    ast_cli(fd,
+            &quot;The \&quot;current\&quot; console is not connected to an 'AT modem' (cellphone)\n&quot;);
</ins><span class="cx">     return RESULT_SUCCESS;
</span><span class="cx">   }
</span><del>-#endif /* CELLIAX_LIBCSV */
</del><span class="cx"> 
</span><del>-  /*******************************************************************************************/
-
-  if (configfile[0] == '/') {
-    ast_copy_string(fn, configfile, sizeof(fn));
-  } else {
-    snprintf(fn, sizeof(fn), &quot;%s/%s&quot;, ast_config_AST_CONFIG_DIR, configfile);
-  }
-  if (option_debug)
-    NOTICA(&quot;Opening '%s'\n&quot;, SKYPIAX_P_LOG, fn);
-  time(&amp;t);
-  ast_copy_string(date, ctime(&amp;t), sizeof(date));
-
-  if (add_to_celliax_dir_conf)
-    p-&gt;phonebook_writing_fp = fopen(fn, &quot;a+&quot;);
-  else
-    p-&gt;phonebook_writing_fp = fopen(fn, &quot;w+&quot;);
-
-  if (p-&gt;phonebook_writing_fp) {
-    if (add_to_celliax_dir_conf) {
-      if (option_debug)
-        NOTICA(&quot;Opened '%s' for appending \n&quot;, SKYPIAX_P_LOG, fn);
-      fprintf(p-&gt;phonebook_writing_fp, &quot;;!\n&quot;);
-      fprintf(p-&gt;phonebook_writing_fp, &quot;;! Update Date: %s&quot;, date);
-      fprintf(p-&gt;phonebook_writing_fp, &quot;;! Updated by: %s, %d\n&quot;, __FILE__, __LINE__);
-      fprintf(p-&gt;phonebook_writing_fp, &quot;;!\n&quot;);
-    } else {
-      if (option_debug)
-        NOTICA(&quot;Opened '%s' for writing \n&quot;, SKYPIAX_P_LOG, fn);
-      fprintf(p-&gt;phonebook_writing_fp, &quot;;!\n&quot;);
-      fprintf(p-&gt;phonebook_writing_fp, &quot;;! Automatically generated configuration file\n&quot;);
-      fprintf(p-&gt;phonebook_writing_fp, &quot;;! Filename: %s (%s)\n&quot;, configfile, fn);
-      fprintf(p-&gt;phonebook_writing_fp, &quot;;! Creation Date: %s&quot;, date);
-      fprintf(p-&gt;phonebook_writing_fp, &quot;;! Generated by: %s, %d\n&quot;, __FILE__, __LINE__);
-      fprintf(p-&gt;phonebook_writing_fp, &quot;;!\n&quot;);
-      fprintf(p-&gt;phonebook_writing_fp, &quot;[general]\n\n&quot;);
-      fprintf(p-&gt;phonebook_writing_fp, &quot;[default]\n&quot;);
</del><ins>+  memset(at_cmd, 0, sizeof(at_cmd));
+  c = 0;
+  for (i = 1; i &lt; argc; i++) {
+    for (a = 0; a &lt; strlen(argv[i]); a++) {
+      at_cmd[c] = argv[i][a];
+      c++;
+      if (c == 1022)
+        break;
</ins><span class="cx">     }
</span><del>-
-#ifdef CELLIAX_LIBCSV
-    //FIXME: if add_to_celliax_dir_conf parse the &quot;old&quot; config file, so to have the correct next entry id-exten
-    if (fromcsv) {
-      if (option_debug)
-        NOTICA(&quot;filename is: %s\n&quot;, SKYPIAX_P_LOG, argv[3]);
-
-/************************/
-      FILE *fp;
-      struct csv_parser *csvp;
-      char buf[1024];
-      size_t bytes_read;
-      unsigned char options = 0;
-
-      p-&gt;csv_rows = 0;
-      p-&gt;csv_fields = 0;
-
-      if (p-&gt;csv_separator_is_semicolon) {
-        if (csv_init(&amp;csvp, options | CSV_USE_SEMICOLON_SEPARATOR) != 0) {
-          ERRORA(&quot;Failed to initialize csv parser\n&quot;, SKYPIAX_P_LOG);
-          return RESULT_SUCCESS;
-        }
-      } else {
-        if (csv_init(&amp;csvp, options) != 0) {
-          ERRORA(&quot;Failed to initialize csv parser\n&quot;, SKYPIAX_P_LOG);
-          return RESULT_SUCCESS;
-        }
-
-      }
-
-      fp = fopen(argv[3], &quot;rb&quot;);
-      if (!fp) {
-        ERRORA(&quot;Failed to open %s: %s\n&quot;, SKYPIAX_P_LOG, argv[3], strerror(errno));
-        return RESULT_SUCCESS;
-      }
-      while ((bytes_read = fread(buf, 1, 1024, fp)) &gt; 0) {
-        if (csv_parse(csvp, buf, bytes_read, celliax_cb1, celliax_cb2, p) != bytes_read) {
-          ERRORA(&quot;Error while parsing file: %s\n&quot;, SKYPIAX_P_LOG,
-                 csv_strerror(csv_error(csvp)));
-        }
-      }
-
-      csv_fini(csvp, celliax_cb1, celliax_cb2, p);
-
-      if (ferror(fp)) {
-        ERRORA(&quot;Error while reading file %s\n&quot;, SKYPIAX_P_LOG, argv[3]);
-        fclose(fp);
-        return RESULT_SUCCESS;
-      }
-
-      fclose(fp);
-      if (option_debug)
-        NOTICA(&quot;%s: %d fields, %d rows\n&quot;, SKYPIAX_P_LOG, argv[3], p-&gt;csv_fields,
-               p-&gt;csv_rows);
-
-      csv_free(csvp);
-
-    /**************************/
</del><ins>+    if (i != argc - 1) {
+      at_cmd[c] = ' ';
+      c++;
</ins><span class="cx">     }
</span><del>-#endif /* CELLIAX_LIBCSV */
-
-  /*******************************************************************************************/
-    //if (fromskype) {
-    //ast_cli(fd,
-    //&quot;Skype not supported in celliax_dir. Load chan_skypiax and use skypiax_dir!\n&quot;);
-    //}
-
-  /*******************************************************************************************/
-    if (fromcell) {
-      /* which phonebook to use, use the SIM  */
-      res = celliax_serial_write_AT_ack(p, &quot;AT+CPBS=SM&quot;);
-      if (res) {
-        WARNINGA(&quot;AT+CPBS=SM failed, continue\n&quot;, SKYPIAX_P_LOG);
-      }
-      /* which phonebook to use, trying to use combined phone+SIM  */
-      res = celliax_serial_write_AT_ack(p, &quot;AT+CPBS=MT&quot;);
-      if (res) {
-        WARNINGA(&quot;AT+CPBS=MT failed, continue\n&quot;, SKYPIAX_P_LOG);
-      }
-      /* How many entries in phonebook  */
-      p-&gt;phonebook_querying = 1;
-      res = celliax_serial_write_AT_ack(p, &quot;AT+CPBR=?&quot;);
-      if (res) {
-        WARNINGA(&quot;AT+CPBR=? failed, continue\n&quot;, SKYPIAX_P_LOG);
-      }
-      p-&gt;phonebook_querying = 0;
-      /* list entries in phonebook, give the SIM the time to answer  */
-      WARNINGA
-        (&quot;About to querying the cellphone phonebook, if the SIM do not answer may stuck here for 20 seconds... Don't worry.\n&quot;,
-         SKYPIAX_P_LOG);
-      sprintf(list_command, &quot;AT+CPBR=%d,%d&quot;, p-&gt;phonebook_first_entry,
-              p-&gt;phonebook_last_entry);
-      p-&gt;phonebook_listing = 1;
-      res = celliax_serial_write_AT_expect_longtime(p, list_command, &quot;OK&quot;);
-      if (res) {
-        WARNINGA(&quot;AT+CPBR=%d,%d failed, continue\n&quot;, SKYPIAX_P_LOG,
-                 p-&gt;phonebook_first_entry, p-&gt;phonebook_last_entry);
-      }
-      p-&gt;phonebook_listing = 0;
-    }
-  /*******************************************************************************************/
-#ifdef CELLIAX_LIBCSV
-    if (fromvcf) {
-      //TODO implementation here
-    }
-#endif /* CELLIAX_LIBCSV */
-
-  } else {
-    ast_cli(fd, &quot;\n\nfailed to open the directoriax.conf configuration file: %s\n&quot;, fn);
-    ERRORA(&quot;failed to open the directoriax.conf configuration file: %s\n&quot;, SKYPIAX_P_LOG,
-           fn);
-    return RESULT_FAILURE;
</del><ins>+    if (c == 1023)
+      break;
</ins><span class="cx">   }
</span><del>-
-  fclose(p-&gt;phonebook_writing_fp);
-  //celliax_dir_create_extensions();
-
</del><ins>+  celliax_serial_write_AT_noack(tech_pvt, at_cmd);
</ins><span class="cx">   return RESULT_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#endif /* CELLIAX_DIR */
-
-#ifdef CELLIAX_FBUS2
-
-int celliax_serial_getstatus_FBUS2(private_t * tech_pvt)
</del><ins>+int celliax_serial_getstatus_AT(private_t * tech_pvt)
</ins><span class="cx"> {
</span><del>-  unsigned char MsgBuffer[7];
</del><span class="cx">   int res;
</span><del>-  int how_many_reads = 0;
</del><span class="cx"> 
</span><del>-  PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  LOKKA(&amp;p-&gt;controldev_lock);
-
-  MsgBuffer[0] = FBUS2_COMMAND_BYTE_1;
-  MsgBuffer[1] = FBUS2_COMMAND_BYTE_2;
-  MsgBuffer[2] = 0x00;
-  MsgBuffer[3] = 0x03;
-  MsgBuffer[4] = 0x00;
-  MsgBuffer[5] = FBUS2_IS_LAST_FRAME;
-  MsgBuffer[6] = celliax_serial_get_seqnum_FBUS2(p);
-
-  if (option_debug &gt; 1)
-    DEBUGA_FBUS2(&quot;asking model, outseqnum %.2X \n&quot;, SKYPIAX_P_LOG, MsgBuffer[6]);
-  celliax_serial_write_FBUS2(p, MsgBuffer, 7, FBUS2_TYPE_MODEL_ASK);
-  usleep(1000);
-  res = celliax_serial_read_FBUS2(p);   //we don't have no monitor neither do_controldev_thread
-  if (res == -1) {
-    ERRORA(&quot;failed celliax_serial_read_FBUS2\n&quot;, SKYPIAX_P_LOG);
-    UNLOCKA(&amp;p-&gt;controldev_lock);
-    return -1;
-  }
-  while (res != MsgBuffer[6] &amp;&amp; res != FBUS2_TYPE_MODEL_ANSWER) {
-    usleep(1000);
-    res = celliax_serial_read_FBUS2(p);
-    how_many_reads++;
-    if (res == -1) {
-      ERRORA(&quot;failed celliax_serial_read_FBUS2\n&quot;, SKYPIAX_P_LOG);
-      UNLOCKA(&amp;p-&gt;controldev_lock);
-      return -1;
</del><ins>+  if (tech_pvt-&gt;owner) {
+    if (tech_pvt-&gt;owner-&gt;_state != SKYPIAX_STATE_UP &amp;&amp; tech_pvt-&gt;owner-&gt;_state != SKYPIAX_STATE_DOWN) {
+      DEBUGA_SKYPE(&quot;No getstatus, we're neither UP nor DOWN\n&quot;, SKYPIAX_P_LOG);
+      return 0;
</ins><span class="cx">     }
</span><del>-    if (how_many_reads &gt; 10) {
-      ERRORA(&quot;no expected results in %d celliax_serial_read_FBUS2\n&quot;, SKYPIAX_P_LOG,
-             how_many_reads);
-      UNLOCKA(&amp;p-&gt;controldev_lock);
-      return -1;
-    }
</del><span class="cx">   }
</span><span class="cx"> 
</span><del>-  UNLOCKA(&amp;p-&gt;controldev_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  return 0;
-}
-
-int celliax_serial_sync_FBUS2(private_t * tech_pvt)
-{
-  unsigned char initc = 0x55;   /* FBUS2 initialization char */
-  int c, rt;
-  PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  LOKKA(&amp;p-&gt;controldev_lock);
-  /*  init the link (sync receive uart) */
-  for (c = 0; c &lt; 55; c++) {    /* 55 times */
-    usleep(10000);
-    rt = write(p-&gt;controldevfd, &amp;initc, 1);
-    if (rt != 1) {
-      ERRORA(&quot;serial error: %s&quot;, SKYPIAX_P_LOG, strerror(errno));
-      UNLOCKA(&amp;p-&gt;controldev_lock);
-      return -1;
-    }
</del><ins>+  PUSHA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  LOKKA(&amp;tech_pvt-&gt;controldev_lock);
+  res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT&quot;);
+  if (res) {
+    ERRORA(&quot;AT was not acknowledged, continuing but maybe there is a problem\n&quot;,
+           SKYPIAX_P_LOG);
</ins><span class="cx">   }
</span><del>-  time(&amp;p-&gt;celliax_serial_synced_timestamp);
-  UNLOCKA(&amp;p-&gt;controldev_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  return 0;
-}
</del><ins>+  usleep(1000);
</ins><span class="cx"> 
</span><del>-int celliax_serial_answer_FBUS2(private_t * tech_pvt)
-{
-  unsigned char MsgBuffer[6];
-
-  celliax_serial_security_command_FBUS2(p);
-
-  MsgBuffer[0] = FBUS2_COMMAND_BYTE_1;
-  MsgBuffer[1] = FBUS2_COMMAND_BYTE_2;
-  MsgBuffer[2] = FBUS2_SECURIY_CALL_COMMANDS;
-  MsgBuffer[3] = FBUS2_SECURIY_CALL_COMMAND_ANSWER;
-  MsgBuffer[4] = FBUS2_IS_LAST_FRAME;
-  MsgBuffer[5] = celliax_serial_get_seqnum_FBUS2(p);
-  if (option_debug &gt; 1)
-    DEBUGA_FBUS2(&quot;celliax_serial_answer_FBUS2, outseqnum %.2X \n&quot;, SKYPIAX_P_LOG,
-                 MsgBuffer[5]);
-  celliax_serial_write_FBUS2(p, MsgBuffer, 6, FBUS2_TYPE_SECURITY);
-  DEBUGA_FBUS2(&quot;FBUS2: sent commands to answer the call\n&quot;, SKYPIAX_P_LOG);
-  p-&gt;interface_state = AST_STATE_UP;    //FIXME
-
-  return 0;
-}
-
-int celliax_serial_call_FBUS2(private_t * tech_pvt, char *dstr)
-{
-  unsigned char MsgBufferNum[255];
-  int i;
-
-  celliax_serial_security_command_FBUS2(p);
-
-  MsgBufferNum[0] = FBUS2_COMMAND_BYTE_1;
-  MsgBufferNum[1] = FBUS2_COMMAND_BYTE_2;
-  MsgBufferNum[2] = FBUS2_SECURIY_CALL_COMMANDS;
-  MsgBufferNum[3] = FBUS2_SECURIY_CALL_COMMAND_CALL;
-  for (i = 0; i &lt; strlen(dstr); i++) {
-    MsgBufferNum[4 + i] = dstr[i];
-  }
-  MsgBufferNum[4 + strlen(dstr)] = 0x00;    /* required by FBUS2 prot */
-  MsgBufferNum[4 + strlen(dstr) + 1] = FBUS2_IS_LAST_FRAME;
-  MsgBufferNum[4 + strlen(dstr) + 2] = celliax_serial_get_seqnum_FBUS2(p);
-  if (option_debug &gt; 1)
-    DEBUGA_FBUS2(&quot;celliax_serial_call_FBUS2, outseqnum %.2X \n&quot;, SKYPIAX_P_LOG,
-                 MsgBufferNum[4 + strlen(dstr) + 2]);
-  celliax_serial_write_FBUS2(p, MsgBufferNum, 5 + strlen(dstr) + 2, FBUS2_TYPE_SECURITY);
-
-  p-&gt;phone_callflow = CALLFLOW_CALL_DIALING;
-  p-&gt;interface_state = AST_STATE_DIALING;
-  if (option_debug)
-    DEBUGA_FBUS2(&quot;FBUS2: sent commands to call\n&quot;, SKYPIAX_P_LOG);
-  return 0;
-}
-
-int celliax_serial_hangup_FBUS2(private_t * tech_pvt)
-{
-  unsigned char MsgBuffer[6];
-
-  if (p-&gt;interface_state != AST_STATE_DOWN) {
-    celliax_serial_security_command_FBUS2(p);
-
-    MsgBuffer[0] = FBUS2_COMMAND_BYTE_1;
-    MsgBuffer[1] = FBUS2_COMMAND_BYTE_2;
-    MsgBuffer[2] = FBUS2_SECURIY_CALL_COMMANDS;
-    MsgBuffer[3] = FBUS2_SECURIY_CALL_COMMAND_RELEASE;
-    MsgBuffer[4] = FBUS2_IS_LAST_FRAME;
-    MsgBuffer[5] = celliax_serial_get_seqnum_FBUS2(p);
-
-    if (option_debug &gt; 1)
-      DEBUGA_FBUS2(&quot;celliax_serial_hangup_FBUS2, outseqnum %.2X \n&quot;, SKYPIAX_P_LOG,
-                   MsgBuffer[5]);
-    celliax_serial_write_FBUS2(p, MsgBuffer, 6, FBUS2_TYPE_SECURITY);
-
-    DEBUGA_FBUS2(&quot;FBUS2: sent commands to hangup the call\n&quot;, SKYPIAX_P_LOG);
-
-  }
-  p-&gt;interface_state = AST_STATE_DOWN;  //FIXME
-  p-&gt;phone_callflow = CALLFLOW_CALL_IDLE;   //FIXME
-  return 0;
-}
-
-int celliax_serial_config_FBUS2(private_t * tech_pvt)
-{
-  unsigned char MsgBuffer[6];
-  int res;
-  int how_many_reads = 0;
-
-  MsgBuffer[0] = FBUS2_COMMAND_BYTE_1;
-  MsgBuffer[1] = FBUS2_COMMAND_BYTE_2;
-  MsgBuffer[2] = FBUS2_SECURIY_EXTENDED_COMMANDS;
-  MsgBuffer[3] = FBUS2_SECURIY_EXTENDED_COMMAND_ON;
-  MsgBuffer[4] = FBUS2_IS_LAST_FRAME;
-  MsgBuffer[5] = celliax_serial_get_seqnum_FBUS2(p);
-
-  if (option_debug &gt; 1)
-    DEBUGA_FBUS2(&quot;activating security commands for getting IMEI, outseqnum %.2X \n&quot;,
-                 SKYPIAX_P_LOG, MsgBuffer[5]);
-  celliax_serial_write_FBUS2(p, MsgBuffer, 6, FBUS2_TYPE_SECURITY);
-  res = celliax_serial_read_FBUS2(p);   //we don't have no monitor neither do_controldev_thread
-  if (res == -1) {
-    ERRORA(&quot;failed celliax_serial_read_FBUS2\n&quot;, SKYPIAX_P_LOG);
-    return -1;
-  }
-  while (res != MsgBuffer[5] &amp;&amp; res != FBUS2_SECURIY_EXTENDED_COMMAND_ON) {
-    usleep(1000);
-    res = celliax_serial_read_FBUS2(p);
-    how_many_reads++;
-    if (res == -1) {
-      ERRORA(&quot;failed celliax_serial_read_FBUS2\n&quot;, SKYPIAX_P_LOG);
-      return -1;
</del><ins>+  if (strlen(tech_pvt-&gt;at_query_battchg)) {
+    res =
+      celliax_serial_write_AT_expect(tech_pvt, tech_pvt-&gt;at_query_battchg, tech_pvt-&gt;at_query_battchg_expect);
+    if (res) {
+      WARNINGA(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
+               tech_pvt-&gt;at_query_battchg, tech_pvt-&gt;at_query_battchg_expect);
</ins><span class="cx">     }
</span><del>-    if (how_many_reads &gt; 10) {
-      ERRORA(&quot;no expected results in %d celliax_serial_read_FBUS2\n&quot;, SKYPIAX_P_LOG,
-             how_many_reads);
-      return -1;
-    }
-  }
-
-  MsgBuffer[0] = FBUS2_COMMAND_BYTE_1;
-  MsgBuffer[1] = FBUS2_COMMAND_BYTE_2;
-  MsgBuffer[2] = FBUS2_SECURIY_IMEI_COMMANDS;
-  MsgBuffer[3] = FBUS2_SECURIY_IMEI_COMMAND_GET;
-  MsgBuffer[4] = FBUS2_IS_LAST_FRAME;
-  MsgBuffer[5] = celliax_serial_get_seqnum_FBUS2(p);
-  if (option_debug &gt; 1)
-    DEBUGA_FBUS2(&quot;celliax_serial_get_IMEI_init_FBUS2, outseqnum %.2X \n&quot;, SKYPIAX_P_LOG,
-                 MsgBuffer[5]);
-  celliax_serial_write_FBUS2(p, MsgBuffer, 6, FBUS2_TYPE_SECURITY);
-  res = celliax_serial_read_FBUS2(p);   //we don't have no monitor neither do_controldev_thread
-  if (res == -1) {
-    ERRORA(&quot;failed celliax_serial_read_FBUS2\n&quot;, SKYPIAX_P_LOG);
-    return -1;
-  }
-  how_many_reads = 0;
-  while (res != MsgBuffer[5] &amp;&amp; res != CALLFLOW_GOT_IMEI) {
</del><span class="cx">     usleep(1000);
</span><del>-    res = celliax_serial_read_FBUS2(p);
-    how_many_reads++;
-    if (res == -1) {
-      ERRORA(&quot;failed celliax_serial_read_FBUS2\n&quot;, SKYPIAX_P_LOG);
-      return -1;
-    }
-    if (how_many_reads &gt; 10) {
-      ERRORA(&quot;no expected results in %d celliax_serial_read_FBUS2\n&quot;, SKYPIAX_P_LOG,
-             how_many_reads);
-      //FIXME return -1;
-      return 0;
-    }
</del><span class="cx">   }
</span><span class="cx"> 
</span><del>-  if (option_debug &gt; 1)
-    DEBUGA_FBUS2(&quot;xxxxx GOT IMEI xxxxx res=%d %.2X \n&quot;, SKYPIAX_P_LOG, res, res);
-
-  return 0;
-}
-
-int celliax_serial_get_seqnum_FBUS2(private_t * tech_pvt)
-{
-  if (p-&gt;seqnumfbus &gt; FBUS2_SEQNUM_MAX || p-&gt;seqnumfbus &lt; FBUS2_SEQNUM_MIN) {
-    ERRORA(&quot;p-&gt;seqnumfbus: %2.X\n&quot;, SKYPIAX_P_LOG, p-&gt;seqnumfbus);
-    p-&gt;seqnumfbus = FBUS2_SEQNUM_MIN;
-  }
-
-  if (p-&gt;seqnumfbus == FBUS2_SEQNUM_MAX) {
-    p-&gt;seqnumfbus = FBUS2_SEQNUM_MIN;
-  } else {
-    p-&gt;seqnumfbus++;
-  }
-  if (option_debug &gt; 10)
-    DEBUGA_FBUS2(&quot;sqnum: %2.X\n&quot;, SKYPIAX_P_LOG, p-&gt;seqnumfbus);
-  return p-&gt;seqnumfbus;
-}
-
-int celliax_serial_security_command_FBUS2(private_t * tech_pvt)
-{
-  unsigned char MsgBuffer[6];
-
-  MsgBuffer[0] = FBUS2_COMMAND_BYTE_1;
-  MsgBuffer[1] = FBUS2_COMMAND_BYTE_2;
-  MsgBuffer[2] = FBUS2_SECURIY_EXTENDED_COMMANDS;
-  MsgBuffer[3] = FBUS2_SECURIY_EXTENDED_COMMAND_ON;
-  MsgBuffer[4] = FBUS2_IS_LAST_FRAME;
-  MsgBuffer[5] = celliax_serial_get_seqnum_FBUS2(p);
-
-  if (option_debug &gt; 1)
-    DEBUGA_FBUS2(&quot;activating security commands, outseqnum %.2X \n&quot;, SKYPIAX_P_LOG,
-                 MsgBuffer[5]);
-  celliax_serial_write_FBUS2(p, MsgBuffer, 6, FBUS2_TYPE_SECURITY);
-  return 0;
-}
-
-/*!
- * \brief Write on the serial port for all the FBUS2 (old Nokia) functions
- * \param p celliax_pvt
- * \param len lenght of buffer2
- * \param buffer2 chars to be written
- *
- * Write on the serial port for all the FBUS2 (old Nokia) functions
- *
- * \return the number of chars written on the serial, 
- * that can be different from len (or negative) in case of errors.
- */
-int celliax_serial_send_FBUS2(private_t * tech_pvt, int len, unsigned char *mesg_ptr)
-{
-  int ret;
-  size_t actual = 0;
-  unsigned char *mesg_ptr2 = mesg_ptr;
-  PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  LOKKA(&amp;p-&gt;controldev_lock);
-  do {
-    ret = write(p-&gt;controldevfd, mesg_ptr, len - actual);
-    if (ret &lt; 0 &amp;&amp; errno == EAGAIN)
-      continue;
-    if (ret &lt; 0) {
-      if (actual != len)
-        ERRORA(&quot;celliax_serial_write error: %s&quot;, SKYPIAX_P_LOG, strerror(errno));
-      UNLOCKA(&amp;p-&gt;controldev_lock);
-      return -1;
</del><ins>+  if (strlen(tech_pvt-&gt;at_query_signal)) {
+    res =
+      celliax_serial_write_AT_expect(tech_pvt, tech_pvt-&gt;at_query_signal, tech_pvt-&gt;at_query_signal_expect);
+    if (res) {
+      WARNINGA(&quot;%s does not get %s from the phone. Continuing.\n&quot;, SKYPIAX_P_LOG,
+               tech_pvt-&gt;at_query_signal, tech_pvt-&gt;at_query_signal_expect);
</ins><span class="cx">     }
</span><del>-    actual += ret;
-    mesg_ptr += ret;
-    usleep(10000);
-  } while (actual &lt; len);
-
-  UNLOCKA(&amp;p-&gt;controldev_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  if (option_debug &gt; 10) {
-    int i;
-    char debug_buf[1024];
-    char *debug_buf_pos;
-
-    memset(debug_buf, 0, 1024);
-    debug_buf_pos = debug_buf;
-
-    for (i = 0; i &lt; len; i++) {
-      debug_buf_pos += sprintf(debug_buf_pos, &quot;[%.2X] &quot;, mesg_ptr2[i]);
-      if (debug_buf_pos &gt; ((char *) &amp;debug_buf + 1000))
-        break;
-    }
-    DEBUGA_FBUS2(&quot;%s was sent down the wire\n&quot;, SKYPIAX_P_LOG, debug_buf);
</del><ins>+    usleep(1000);
</ins><span class="cx">   }
</span><ins>+  //FIXME all the following commands in config!
</ins><span class="cx"> 
</span><del>-  return 0;
-}
-
-/*!
- * \brief Flags as acknowledged an FBUS2 message previously sent
- * \param p celliax_pvt
- * \param seqnum identifier of the message to be acknowledged
- *
- * Called upon receiving an FBUS2 acknoledgement message, browse the fbus2_outgoing_list 
- * looking for the seqnum sent FBUS2 message, and flags it as acknowledged.
- * (if an outgoing FBUS2 message is not aknowledged by the cellphone in a while,
- * it will be retransmitted)
- *
- * \return 0 on error, 1 otherwise
- */
-int celliax_serial_list_acknowledge_FBUS2(private_t * tech_pvt, int seqnum)
-{
-  struct fbus2_msg *ptr;
-
-  ptr = p-&gt;fbus2_outgoing_list;
-  if (ptr == NULL) {
-    ERRORA(&quot;fbus2_outgoing_list is NULL ?\n&quot;, SKYPIAX_P_LOG);
-    return -1;
-  }
-  PUSHA_UNLOCKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-  LOKKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-  while (ptr-&gt;next != NULL)
-    ptr = ptr-&gt;next;
-  while (ptr-&gt;acknowledged == 0) {
-    if (ptr-&gt;seqnum == seqnum) {
-      ptr-&gt;acknowledged = 1;
-      if (option_debug &gt; 1)
-        DEBUGA_FBUS2(&quot;Acknowledgment to %.2X\n&quot;, SKYPIAX_P_LOG, seqnum);
-
-      DEBUGA_FBUS2(&quot;PREFREE OUTGOING list:\n&quot;, SKYPIAX_P_LOG);
-      celliax_serial_list_print_FBUS2(p, p-&gt;fbus2_outgoing_list);
-      if (ptr-&gt;previous) {
-        if (ptr-&gt;next) {
-          ptr-&gt;previous-&gt;next = ptr-&gt;next;
-        } else {
-          ptr-&gt;previous-&gt;next = NULL;
-        }
-      }
-      if (ptr-&gt;next) {
-        if (ptr-&gt;previous) {
-          ptr-&gt;next-&gt;previous = ptr-&gt;previous;
-        } else {
-          ptr-&gt;next-&gt;previous = NULL;
-        }
-      }
-
-      if ((NULL == ptr-&gt;next) &amp;&amp; (NULL == ptr-&gt;previous)) { /* bug catched by Wojciech Andralojc */
-        if (option_debug &gt; 1)
-          DEBUGA_FBUS2(&quot;FREEING LAST\n&quot;, SKYPIAX_P_LOG);
-        p-&gt;fbus2_outgoing_list = NULL;
-        p-&gt;fbus2_outgoing_list = celliax_serial_list_init_FBUS2(p);
-      }
-
-      free(ptr);
-      DEBUGA_FBUS2(&quot;POSTFREE OUTGOING list:\n&quot;, SKYPIAX_P_LOG);
-      celliax_serial_list_print_FBUS2(p, p-&gt;fbus2_outgoing_list);
-
-      break;
-    }
-    if (ptr-&gt;previous != NULL) {
-      ptr = ptr-&gt;previous;
</del><ins>+  if (tech_pvt-&gt;sms_cnmi_not_supported) {
+    res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT+MMGL=\&quot;HEADER ONLY\&quot;&quot;);
+    if (res) {
+      WARNINGA
+        (&quot;%s does not get %s from the modem, maybe a long msg is incoming. If this cellmodem is not a Motorola, you are arriving here because your cellmodem do not supports CNMI kind of incoming SMS alert; please let it know to the developers of Celliax. If this cellmodem is a Motorola and this message keeps repeating, and you cannot correctly receive SMSs from this interface, please manually clean all messages from the cellmodem/SIM. Continuing.\n&quot;,
+         SKYPIAX_P_LOG, &quot;AT+MMGL=\&quot;HEADER ONLY\&quot;&quot;, &quot;OK&quot;);
</ins><span class="cx">     } else {
</span><del>-      ERRORA
-        (&quot;The phone sent us an acknowledgement referring to a msg with a seqnum that is not in our sent list: %.2X\n&quot;,
-         SKYPIAX_P_LOG, seqnum);
-      break;
-    }
-  }
-  UNLOCKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-  return 0;
-}
</del><ins>+      usleep(1000);
+      if (tech_pvt-&gt;unread_sms_msg_id) {
+        char at_command[256];
</ins><span class="cx"> 
</span><del>-/*!
- * \brief Sends an FBUS2 message or resends it if it was not acknowledged
- * \param p celliax_pvt
- *
- * Called by celliax_serial_read_FBUS2, browse the fbus2_outgoing_list looking for FBUS2 messages to be sent, 
- * or for FBUS2 messages previously sent but not yet acknoledged.
- * (if an outgoing FBUS2 message is not aknowledged by the cellphone in a while,
- * it will be retransmitted)
- *
- * \return 0 on error, 1 otherwise
- */
-int celliax_serial_send_if_time_FBUS2(private_t * tech_pvt)
-{
-  struct fbus2_msg *ptr;
-  struct timeval tv;
-  struct timezone tz;
-
-  gettimeofday(&amp;tv, &amp;tz);
-  ptr = p-&gt;fbus2_outgoing_list;
-  if (ptr == NULL) {
-    ERRORA(&quot;fbus2_outgoing_list is NULL ?\n&quot;, SKYPIAX_P_LOG);
-    return -1;
-  }
-  while (ptr-&gt;next != NULL) {
-    WARNINGA(&quot;fbus2_outgoing_list-&gt;next is not null ?\n&quot;, SKYPIAX_P_LOG);
-    ptr = ptr-&gt;next;            //FIXME what to do?
-  }
-  while (ptr-&gt;sent == 0 &amp;&amp; ptr-&gt;acknowledged == 0) {
-    if (ptr-&gt;previous != NULL) {
-      ptr = ptr-&gt;previous;
-    } else
-      break;
-  }
-  while (ptr-&gt;sent == 1 &amp;&amp; ptr-&gt;acknowledged == 0) {
-    if (ptr-&gt;previous != NULL) {
-      ptr = ptr-&gt;previous;
-    } else
-      break;
-  }
-  if (ptr-&gt;sent == 1 &amp;&amp; ptr-&gt;acknowledged == 1) {
-    if (ptr-&gt;next != NULL) {
-      ptr = ptr-&gt;next;
-    }
-  }
-  if (ptr-&gt;sent == 1 &amp;&amp; ptr-&gt;acknowledged == 0 &amp;&amp; ptr-&gt;msg &gt; 0) {
-    if ((tv.tv_sec * 1000 + tv.tv_usec / 1000) &gt;
-        ((ptr-&gt;tv_sec * 1000 + ptr-&gt;tv_usec / 1000) + 1000)) {
-
-      PUSHA_UNLOCKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-      LOKKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-
-      if (ptr-&gt;sent == 1 &amp;&amp; ptr-&gt;acknowledged == 0 &amp;&amp; ptr-&gt;msg &gt; 0) {   //retest, maybe has been changed?
-        if ((tv.tv_sec * 1000 + tv.tv_usec / 1000) &gt; ((ptr-&gt;tv_sec * 1000 + ptr-&gt;tv_usec / 1000) + 1000)) { //retest, maybe has been changed?
-
-          if (option_debug &gt; 1)
-            DEBUGA_FBUS2(&quot;RESEND %.2X, passed %ld ms, sent %d times\n&quot;, SKYPIAX_P_LOG,
-                         ptr-&gt;seqnum,
-                         ((tv.tv_sec * 1000 + tv.tv_usec / 1000) -
-                          (ptr-&gt;tv_sec * 1000 + ptr-&gt;tv_usec / 1000)),
-                         ptr-&gt;how_many_sent);
-          if (ptr-&gt;how_many_sent &gt; 9) {
-            ERRORA(&quot;RESEND %.2X, passed %ld ms, sent %d times\n&quot;, SKYPIAX_P_LOG,
-                   ptr-&gt;seqnum,
-                   ((tv.tv_sec * 1000 + tv.tv_usec / 1000) -
-                    (ptr-&gt;tv_sec * 1000 + ptr-&gt;tv_usec / 1000)), ptr-&gt;how_many_sent);
-
-            UNLOCKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-            return -1;
</del><ins>+        if (tech_pvt-&gt;no_ucs2 == 0) {
+          res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT+CSCS=\&quot;UCS2\&quot;&quot;);
+          if (res) {
+            ERRORA
+              (&quot;AT+CSCS=\&quot;UCS2\&quot; (set TE messages to ucs2)  do not got OK from the phone\n&quot;,
+               SKYPIAX_P_LOG);
+            memset(tech_pvt-&gt;sms_message, 0, sizeof(tech_pvt-&gt;sms_message));
</ins><span class="cx">           }
</span><del>-
-          celliax_serial_send_FBUS2(p, ptr-&gt;len, ptr-&gt;buffer);
-          if (ptr-&gt;buffer[3] == FBUS2_ACK_BYTE) {
-            if (option_debug &gt; 1)
-              DEBUGA_FBUS2(&quot;RESEND ACK, passed %ld ms, sent %d times\n&quot;, SKYPIAX_P_LOG,
-                           ((tv.tv_sec * 1000 + tv.tv_usec / 1000) -
-                            (ptr-&gt;tv_sec * 1000 + ptr-&gt;tv_usec / 1000)),
-                           ptr-&gt;how_many_sent);
-            ptr-&gt;acknowledged = 1;
-            ptr-&gt;msg = FBUS2_OUTGOING_ACK;
-          }
-          ptr-&gt;tv_sec = tv.tv_sec;
-          ptr-&gt;tv_usec = tv.tv_usec;
-          ptr-&gt;sent = 1;
-          ptr-&gt;how_many_sent++;
-          if (option_debug &gt; 1) {
-            DEBUGA_FBUS2(&quot;OUTGOING list:\n&quot;, SKYPIAX_P_LOG);
-            celliax_serial_list_print_FBUS2(p, p-&gt;fbus2_outgoing_list);
-            DEBUGA_FBUS2(&quot;OUTGOING list END\n&quot;, SKYPIAX_P_LOG);
-          }
-
</del><span class="cx">         }
</span><del>-      }
</del><span class="cx"> 
</span><del>-      UNLOCKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-      POPPA_UNLOCKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-    }
-  }
-  if (ptr-&gt;sent == 0 &amp;&amp; ptr-&gt;acknowledged == 0 &amp;&amp; ptr-&gt;msg &gt; 0) {
</del><ins>+        memset(at_command, 0, sizeof(at_command));
+        sprintf(at_command, &quot;AT+CMGR=%d&quot;, tech_pvt-&gt;unread_sms_msg_id);
+        memset(tech_pvt-&gt;sms_message, 0, sizeof(tech_pvt-&gt;sms_message));
</ins><span class="cx"> 
</span><del>-    PUSHA_UNLOCKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-    LOKKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-
-    if (ptr-&gt;sent == 0 &amp;&amp; ptr-&gt;acknowledged == 0 &amp;&amp; ptr-&gt;msg &gt; 0) { //retest, maybe has been changed?
-
-      if (option_debug &gt; 1)
-        DEBUGA_FBUS2(&quot;SENDING 1st TIME %.2X\n&quot;, SKYPIAX_P_LOG, ptr-&gt;seqnum);
-      celliax_serial_send_FBUS2(p, ptr-&gt;len, ptr-&gt;buffer);
-      if (ptr-&gt;buffer[3] == FBUS2_ACK_BYTE) {
-        if (option_debug &gt; 1)
-          DEBUGA_FBUS2(&quot;SENDING 1st TIME ACK\n&quot;, SKYPIAX_P_LOG);
-        ptr-&gt;acknowledged = 1;
-        ptr-&gt;msg = FBUS2_OUTGOING_ACK;
-      }
-      ptr-&gt;tv_sec = tv.tv_sec;
-      ptr-&gt;tv_usec = tv.tv_usec;
-      ptr-&gt;sent = 1;
-      ptr-&gt;how_many_sent++;
-      if (option_debug &gt; 1) {
-        DEBUGA_FBUS2(&quot;OUTGOING list:\n&quot;, SKYPIAX_P_LOG);
-        celliax_serial_list_print_FBUS2(p, p-&gt;fbus2_outgoing_list);
-        DEBUGA_FBUS2(&quot;OUTGOING list END\n&quot;, SKYPIAX_P_LOG);
-      }
-
-    }
-
-    UNLOCKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-    POPPA_UNLOCKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-
-  }
-  return 0;
-}
-
-int celliax_serial_write_FBUS2(private_t * tech_pvt, unsigned char *MsgBuffer,
-                               int MsgLength, unsigned char MsgType)
-{
-  unsigned char buffer2[FBUS2_MAX_TRANSMIT_LENGTH + 10];
-  unsigned char checksum = 0;
-  int i, len;
-  struct timeval tv;
-  struct timezone tz;
-
-  buffer2[0] = FBUS2_SERIAL_FRAME_ID;
-  buffer2[1] = FBUS2_DEVICE_PHONE;  /* destination */
-  buffer2[2] = FBUS2_DEVICE_PC; /* source */
-  buffer2[3] = MsgType;
-  buffer2[4] = 0x00;            /* required by protocol */
-  buffer2[5] = MsgLength;
-
-  memcpy(buffer2 + 6, MsgBuffer, MsgLength);
-  len = MsgLength + 6;
-
-  /* Odd messages require additional padding 0x00 byte */
-  if (MsgLength % 2)
-    buffer2[len++] = 0x00;      /* optional PaddingByte */
-
-  checksum = 0;
-  for (i = 0; i &lt; len; i += 2)
-    checksum ^= buffer2[i];
-  buffer2[len++] = checksum;    /* ChkSum1 */
-
-  checksum = 0;
-  for (i = 1; i &lt; len; i += 2)
-    checksum ^= buffer2[i];
-  buffer2[len++] = checksum;    /* ChkSum2 */
-
-  if (option_debug &gt; 10) {
-    int i;
-    char debug_buf[1024];
-    char *debug_buf_pos;
-
-    memset(debug_buf, 0, 1024);
-    debug_buf_pos = debug_buf;
-
-    for (i = 0; i &lt; len; i++) {
-      debug_buf_pos += sprintf(debug_buf_pos, &quot;[%.2X] &quot;, buffer2[i]);
-      if (debug_buf_pos &gt; (char *) (&amp;debug_buf + 1000))
-        break;
-    }
-    if (buffer2[3] == FBUS2_ACK_BYTE) {
-      DEBUGA_FBUS2(&quot;%s to be written, ACK\n&quot;, SKYPIAX_P_LOG, debug_buf);
-    } else {
-      DEBUGA_FBUS2(&quot;%s to be written\n&quot;, SKYPIAX_P_LOG, debug_buf);
-    }
-  }
-
-  gettimeofday(&amp;tv, &amp;tz);
-
-  if (buffer2[3] != FBUS2_ACK_BYTE) {
-    p-&gt;fbus2_outgoing_list = celliax_serial_list_init_FBUS2(p);
-    p-&gt;fbus2_outgoing_list-&gt;msg = 11;
-
-    p-&gt;fbus2_outgoing_list-&gt;len = len;
-    for (i = 0; i &lt; len; i++) {
-      p-&gt;fbus2_outgoing_list-&gt;buffer[i] = buffer2[i];
-    }
-    p-&gt;fbus2_outgoing_list-&gt;seqnum = MsgBuffer[MsgLength - 1];
-    if (option_debug &gt; 1) {
-      DEBUGA_FBUS2(&quot;OUTGOING LIST seqnum is %2.X\n&quot;, SKYPIAX_P_LOG,
-                   MsgBuffer[MsgLength - 1]);
-
-      DEBUGA_FBUS2(&quot;OUTGOING list:\n&quot;, SKYPIAX_P_LOG);
-      celliax_serial_list_print_FBUS2(p, p-&gt;fbus2_outgoing_list);
-      DEBUGA_FBUS2(&quot;OUTGOING list END\n&quot;, SKYPIAX_P_LOG);
-    }
-  } else {
-    usleep(100);
-    celliax_serial_send_FBUS2(p, len, buffer2);
-  }
-
-  return 0;
-}
-
-int celliax_serial_send_ack_FBUS2(private_t * tech_pvt, unsigned char MsgType,
-                                  unsigned char MsgSequence)
-{
-  unsigned char buffer2[2];
-
-  buffer2[0] = MsgType;
-  buffer2[1] = (MsgSequence - FBUS2_SEQNUM_MIN);
-
-  if (option_debug &gt; 1)
-    DEBUGA_FBUS2(&quot;SENDING ACK to %2.X, seqack %2.X \n&quot;, SKYPIAX_P_LOG, MsgSequence,
-                 (MsgSequence - FBUS2_SEQNUM_MIN));
-  /* Sending to phone */
-  return celliax_serial_write_FBUS2(p, buffer2, 2, FBUS2_ACK_BYTE);
-}
-
-struct fbus2_msg *celliax_serial_list_init_FBUS2(private_t * tech_pvt)
-{
-  struct fbus2_msg *list;
-  list = p-&gt;fbus2_outgoing_list;
-
-  PUSHA_UNLOCKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-  LOKKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-  if (list == NULL) {
-    list = malloc(sizeof(*(list)));
-    list-&gt;msg = 0;
-    list-&gt;seqnum = 0;
-    list-&gt;len = 0;
-    list-&gt;acknowledged = 0;
-    list-&gt;how_many_sent = 0;
-    list-&gt;sent = 0;
-    list-&gt;tv_sec = 0;
-    list-&gt;tv_usec = 0;
-    list-&gt;next = NULL;
-    list-&gt;previous = NULL;
-  }
-  if (list-&gt;msg != 0) {
-    struct fbus2_msg *new;
-    new = malloc(sizeof(*new));
-    new-&gt;msg = 0;
-    new-&gt;seqnum = 0;
-    new-&gt;len = 0;
-    new-&gt;acknowledged = 0;
-    new-&gt;how_many_sent = 0;
-    new-&gt;sent = 0;
-    new-&gt;tv_sec = 0;
-    new-&gt;tv_usec = 0;
-    new-&gt;next = NULL;
-    new-&gt;previous = list;
-    list-&gt;next = new;
-    list = new;
-  }
-  UNLOCKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;fbus2_outgoing_list_lock);
-  return list;
-}
-
-int celliax_serial_list_print_FBUS2(private_t * tech_pvt, struct fbus2_msg *list)
-{
-  struct fbus2_msg *ptr;
-  ptr = list;
-  while (ptr) {
-    if (option_debug &gt; 3)
-      DEBUGA_FBUS2
-        (&quot;PTR msg is: %d, seqnum is %.2X, tv_sec is %d, tv_usec is %d, acknowledged is: %d,&quot;
-         &quot; sent is:%d, how_many_sent is: %d\n&quot;, SKYPIAX_P_LOG, ptr-&gt;msg, ptr-&gt;seqnum,
-         ptr-&gt;tv_sec, ptr-&gt;tv_usec, ptr-&gt;acknowledged, ptr-&gt;sent, ptr-&gt;how_many_sent);
-    ptr = ptr-&gt;previous;
-  }
-  return 0;
-}
-
-int celliax_serial_read_FBUS2(private_t * tech_pvt)
-{
-  int read_count;
-  int select_err;
-  fd_set read_fds;
-  struct timeval timeout;
-  int fbus_mesg = 0;
-  int i;
-
-  FD_ZERO(&amp;read_fds);
-  FD_SET(p-&gt;controldevfd, &amp;read_fds);
-  timeout.tv_sec = 0;
-  timeout.tv_usec = 50000;
-
-  if ((select_err = select(p-&gt;controldevfd + 1, &amp;read_fds, NULL, NULL, &amp;timeout)) &gt; 0) {
-    timeout.tv_sec = 0;         //reset the timeout, linux modify it
-    timeout.tv_usec = 50000;    //reset the timeout, linux modify it
-    PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-    LOKKA(&amp;p-&gt;controldev_lock);
-    while ((select_err =
-            select(p-&gt;controldevfd + 1, &amp;read_fds, NULL, NULL, &amp;timeout)) &gt; 0) {
-      gettimeofday(&amp;p-&gt;fbus2_list_tv, &amp;p-&gt;fbus2_list_tz);
-      read_count = read(p-&gt;controldevfd, p-&gt;rxm, 255);
-
-      if (read_count == 0) {
-        ERRORA
-          (&quot;read 0 bytes!!! Nenormalno! Marking this celliax_serial_device %s as dead, andif it is owned by a channel, hanging up. Maybe the phone is stuck, switched off, power down or battery exhausted\n&quot;,
-           SKYPIAX_P_LOG, p-&gt;controldevice_name);
-        p-&gt;controldev_dead = 1;
-        close(p-&gt;controldevfd);
-        UNLOCKA(&amp;p-&gt;controldev_lock);
-        if (p-&gt;owner) {
-          celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
-          p-&gt;owner-&gt;hangupcause = AST_CAUSE_FAILURE;
</del><ins>+        tech_pvt-&gt;reading_sms_msg = 1;
+        res = celliax_serial_write_AT_ack(tech_pvt, at_command);
+        tech_pvt-&gt;reading_sms_msg = 0;
+        if (res) {
+          ERRORA
+            (&quot;AT+CMGR (read SMS) do not got OK from the phone, message sent was:|||%s|||\n&quot;,
+             SKYPIAX_P_LOG, at_command);
</ins><span class="cx">         }
</span><del>-        return -1;
-      }
-      if (option_debug &gt; 10) {
-        int c;
-        char debug_buf[1024];
-        char *debug_buf_pos;
-
-        memset(debug_buf, 0, 1024);
-        debug_buf_pos = debug_buf;
-        for (c = 0; c &lt; read_count; c++) {
-          debug_buf_pos += sprintf(debug_buf_pos, &quot;[%.2X] &quot;, p-&gt;rxm[c]);
-          if (debug_buf_pos &gt; (char *) (&amp;debug_buf + 1000))
-            break;
</del><ins>+        res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT+CSCS=\&quot;GSM\&quot;&quot;);
+        if (res) {
+          ERRORA
+            (&quot;AT+CSCS=\&quot;GSM\&quot; (set TE messages to GSM) do not got OK from the phone\n&quot;,
+             SKYPIAX_P_LOG);
</ins><span class="cx">         }
</span><del>-        DEBUGA_FBUS2(&quot;%s READ AT seconds=%ld usec=%6ld read_count=%d\n&quot;, SKYPIAX_P_LOG,
-                     debug_buf, p-&gt;fbus2_list_tv.tv_sec, p-&gt;fbus2_list_tv.tv_usec,
-                     read_count);
-      }
-
-      for (i = 0; i &lt; read_count; i++) {
-        if (p-&gt;rxm[i] == FBUS2_DEVICE_PHONE &amp;&amp; p-&gt;rxm[i - 1] == FBUS2_DEVICE_PC
-            &amp;&amp; p-&gt;rxm[i - 2] == FBUS2_SERIAL_FRAME_ID) {
-          /* if we have identified the start of an fbus2 frame sent to us by the phone */
-          /* clean the array, copy into it the beginning of the frame, move the counter in the array after the last byte copied */
-          memset(p-&gt;array, 0, 255);
-          p-&gt;array[0] = FBUS2_SERIAL_FRAME_ID;
-          p-&gt;array[1] = FBUS2_DEVICE_PC;
-          p-&gt;arraycounter = 2;
</del><ins>+        memset(at_command, 0, sizeof(at_command));
+        sprintf(at_command, &quot;AT+CMGD=%d&quot;, tech_pvt-&gt;unread_sms_msg_id);    /* delete the message */
+        tech_pvt-&gt;unread_sms_msg_id = 0;
+        res = celliax_serial_write_AT_ack(tech_pvt, at_command);
+        if (res) {
+          ERRORA
+            (&quot;AT+CMGD (Delete SMS) do not got OK from the phone, message sent was:|||%s|||\n&quot;,
+             SKYPIAX_P_LOG, at_command);
</ins><span class="cx">         }
</span><del>-        if (p-&gt;rxm[i] == FBUS2_SERIAL_FRAME_ID &amp;&amp; read_count == 1) {    /* quick hack to try to identify the lone char 
-                                                                           at the beginning a frame, often returned by 
-                                                                           ark3116 based datacables */
-          /* if we have identified the start of an fbus2 frame sent to us by the phone */
-          /* clean the array, copy into it the beginning of the frame, move the counter in the array after the last byte copied */
-          memset(p-&gt;array, 0, 255);
-          p-&gt;arraycounter = 0;
-        }
</del><span class="cx"> 
</span><del>-        /* continue copying into the array, until... */
-        p-&gt;array[p-&gt;arraycounter] = p-&gt;rxm[i];
-        /* we reach the end of the incoming frame, its lenght is in the p-&gt;array[5] byte, plus overhead */
-        if (p-&gt;arraycounter == p-&gt;array[5] + 7) {
-          /* start categorizing frames */
-          int seqnum;
-          int known = 0;
</del><ins>+        if (strlen(tech_pvt-&gt;sms_message)) {
</ins><span class="cx"> 
</span><del>-          /* ACK frames are always of lenght 10, without padding */
-          seqnum = p-&gt;array[p-&gt;arraycounter - 2];
-          /* first step in categorizing frames, look at the general kind of frame, in p-&gt;array[3] */
-          switch (p-&gt;array[3]) {
-/****************************************************************/
-          case FBUS2_ACK_BYTE:
-            /* this is an ACKnowledgement frame sent to us in reply to an item we sent, take note we were ACKnowledged, no need to resend the item */
-            if (option_debug &gt; 1)
-              DEBUGA_FBUS2(&quot;INCOMING ACK, seqack %.2X \n&quot;, SKYPIAX_P_LOG, seqnum);
-            if (seqnum == 0x80) {   /* reset */
-              seqnum = 0x00;
-              DEBUGA_FBUS2
-                (&quot;seqack was 0x80, interpreting as 0x00, first acknowledgement (session begin?) of our first sent item 0x40\n&quot;,
-                 SKYPIAX_P_LOG);
-            }
-            /* an ACK frame has the same seqnum as the item it acknowledge, minus 0x40, so here we obtain the seqnum of the item that has been ACKnowledged */
-            fbus_mesg = seqnum + FBUS2_SEQNUM_MIN;
-            /* take note that the item sent was ACKnowledged, so no need to resend it */
-            celliax_serial_list_acknowledge_FBUS2(p, fbus_mesg);
-            /* this frame has been categorized, bail out from the loop */
-            known = 1;
-            break;
-/****************************************************************/
-          case FBUS2_TYPE_CALL_DIVERT:
-            if (option_debug &gt; 1)
-              DEBUGA_FBUS2(&quot;CALL DIVERT SIGNALING seqnum %.2X \n&quot;, SKYPIAX_P_LOG, seqnum);
-            fbus_mesg = FBUS2_TYPE_CALL_DIVERT;
-            /* this signal us that we have some settings in line divert, let's use it as activation of the line when we call */
-            if (p-&gt;interface_state == AST_STATE_DIALING) {
-              p-&gt;interface_state = AST_STATE_UP;
-              p-&gt;phone_callflow = CALLFLOW_CALL_ACTIVE;
-              ast_setstate(p-&gt;owner, AST_STATE_RINGING);
-              celliax_queue_control(p-&gt;owner, AST_CONTROL_ANSWER);
-              if (option_debug)
-                DEBUGA_FBUS2
-                  (&quot;call is active, I know it's not yet true, but 3310 do not give us remote answer signaling\n&quot;,
-                   SKYPIAX_P_LOG);
-            }
-            /* this frame has been categorized, bail out from the loop */
-            known = 1;
-            break;
</del><ins>+          manager_event(EVENT_FLAG_SYSTEM, &quot;CELLIAXincomingsms&quot;,
+                        &quot;Interface: %s\r\nSMS_Message: %s\r\n&quot;, tech_pvt-&gt;name, tech_pvt-&gt;sms_message);
</ins><span class="cx"> 
</span><del>-/****************************************************************/
-            /* this kind of frames is an answer to &quot;ask model&quot; actions */
-          case FBUS2_TYPE_MODEL_ANSWER:
-            if (1) {
-              int newline = 0;
-              int c = i = 0;
-              unsigned char model[10];
-              for (i = 10; i &lt; p-&gt;arraycounter; i++) {
-                if (p-&gt;array[i] == '\n')
-                  newline++;
-                if (newline == 2) {
-                  if (p-&gt;array[i] != '\n') {
-                    model[c] = p-&gt;array[i];
-                    c++;
-                  }
-                }
-                if (newline == 3) {
-                  break;
-                }
-                if (c == 9)
-                  break;
-              }
-              model[c] = '\0';
-              DEBUGA_FBUS2(&quot;FBUS2 PHONE MODEL is: %s, inseqnum %.2X \n&quot;, SKYPIAX_P_LOG,
-                           model, seqnum);
-            }
-            known = 1;
-            fbus_mesg = FBUS2_TYPE_MODEL_ANSWER;
-            break;
-/****************************************************************/
-            /* this kind of frames is an answer to &quot;security enabled&quot; actions */
-          case FBUS2_TYPE_SECURITY:
-            switch (p-&gt;array[8]) {
-              /* this subkind of frames is an answer to &quot;security enabled&quot; CALL actions */
-            case FBUS2_SECURIY_CALL_COMMANDS:
-              switch (p-&gt;array[9]) {
-                /* this sub-subkind of frames tell us that we answered the call */
-              case FBUS2_SECURIY_CALL_COMMAND_ANSWER:
-                p-&gt;interface_state = AST_STATE_UP;
-                p-&gt;phone_callflow = CALLFLOW_CALL_ACTIVE;
-
-                /* set the channel state to UP, we've answered */
-                if (ast_setstate(p-&gt;owner, AST_STATE_UP)) {
-                  ERRORA(&quot;ast_setstate failed, BAD\n&quot;, SKYPIAX_P_LOG);
-                }
-
-                if (option_debug &gt; 1)
-                  DEBUGA_FBUS2(&quot;ANSWERED CALL, inseqnum %.2X \n&quot;, SKYPIAX_P_LOG, seqnum);
-                known = 1;
-                break;
-                /* this sub-subkind of frames tell us that we released the call */
-              case FBUS2_SECURIY_CALL_COMMAND_RELEASE:
-                p-&gt;interface_state = AST_STATE_DOWN;
-                p-&gt;phone_callflow = CALLFLOW_CALL_IDLE;
-                if (option_debug &gt; 1)
-                  DEBUGA_FBUS2(&quot;RELEASED CALL, inseqnum %.2X \n&quot;, SKYPIAX_P_LOG, seqnum);
-                fbus_mesg = CALLFLOW_CALL_RELEASED;
-                known = 1;
-                break;
-              }
-              break;
-              /* this subkind of frames is an answer to &quot;enable security commands&quot; action */
-            case FBUS2_SECURIY_EXTENDED_COMMANDS:
-              if (option_debug &gt; 1)
-                DEBUGA_FBUS2(&quot;SECURITY EXTENDED COMMANDS ON, inseqnum %.2X \n&quot;,
-                             SKYPIAX_P_LOG, seqnum);
-              fbus_mesg = FBUS2_SECURIY_EXTENDED_COMMAND_ON;
-              known = 1;
-              break;
-              /* this subkind of frames is an answer to &quot;get IMEI&quot; action */
-            case FBUS2_SECURIY_IMEI_COMMANDS:
-              if (option_debug &gt; 1)
-                DEBUGA_FBUS2(&quot;CALLFLOW_GOT_IMEI, inseqnum %.2X \n&quot;, SKYPIAX_P_LOG,
-                             seqnum);
-              fbus_mesg = CALLFLOW_GOT_IMEI;
-              known = 1;
-              break;
-            }
-            break;
-/****************************************************************/
-            /* this kind of frames is about SMSs */
-          case FBUS2_TYPE_SMS:
-            switch (p-&gt;array[9]) {
-              /* this subkind of frames is about an INCOMING SMS */
-            case FBUS2_SMS_INCOMING:
-              if (option_debug &gt; 1)
-                DEBUGA_FBUS2(&quot;SMS, inseqnum %.2X \n&quot;, SKYPIAX_P_LOG, seqnum);
-              known = 1;
-              break;
-            }
-            break;
-/****************************************************************/
-            /* this kind of frames is about PHONE CALLs */
-          case FBUS2_TYPE_CALL:
-            switch (p-&gt;array[9]) {
-              int a;
-              /* this subkind of frame is about the CALL has been HUNGUP */
-            case FBUS2_CALL_HANGUP:
-              p-&gt;interface_state = AST_STATE_DOWN;
-              p-&gt;phone_callflow = CALLFLOW_CALL_IDLE;
-              if (option_debug &gt; 1)
-                DEBUGA_FBUS2(&quot;REMOTE PARTY HANG UP, inseqnum %.2X \n&quot;, SKYPIAX_P_LOG,
-                             seqnum);
-              fbus_mesg = CALLFLOW_INCOMING_HANGUP;
-              known = 1;
-              break;
-              /* this subkind of frame is about the remote CALLID (not signaled by 3310) */
-            case FBUS2_CALL_CALLID:
-              if (option_debug &gt; 1)
-                DEBUGA_FBUS2(&quot;CALLID, inseqnum %.2X \n&quot;, SKYPIAX_P_LOG, seqnum);
-              memset(p-&gt;callid_name, 0, sizeof(p-&gt;callid_name));
-              memset(p-&gt;callid_number, 0, sizeof(p-&gt;callid_number));
-              for (a = 0; a &lt; p-&gt;array[12]; a++) {
-                p-&gt;callid_number[a] = p-&gt;array[12 + a + 1];
-              }
-              for (a = 0; a &lt; p-&gt;array[12 + 1 + p-&gt;array[12]] + 1; a++) {
-                p-&gt;callid_name[a] = p-&gt;array[12 + 1 + a + p-&gt;array[12] + 1];
-              }
-              if (option_debug &gt; 1)
-                DEBUGA_FBUS2(&quot;CALLFLOW_INCOMING_CALLID: name is %s, number is %s\n&quot;,
-                             SKYPIAX_P_LOG,
-                             p-&gt;callid_name[0] != 1 ? p-&gt;callid_name : &quot;not available&quot;,
-                             p-&gt;callid_number[0] ? p-&gt;callid_number : &quot;not available&quot;);
-              fbus_mesg = CALLFLOW_INCOMING_CALLID;
-              p-&gt;phone_callflow = CALLFLOW_INCOMING_RING;
-              p-&gt;interface_state = AST_STATE_RING;
-              known = 1;
-              break;
-            }
-            break;
-/****************************************************************/
-            /* this kind of frames is about NETWORK STATUS */
-          case FBUS2_TYPE_NETWORK_STATUS:
-            switch (p-&gt;array[9]) {
-              /* this subkind of frames is NETWORK STATUS REGISTERED */
-            case FBUS2_NETWORK_STATUS_REGISTERED:
-              if (option_debug &gt; 1)
-                DEBUGA_FBUS2(&quot;NETWORK STATUS REGISTERED, inseqnum %.2X \n&quot;, SKYPIAX_P_LOG,
-                             seqnum);
-              if (p-&gt;callid_name[0] == 0 &amp;&amp; p-&gt;owner
-                  &amp;&amp; p-&gt;interface_state != AST_STATE_DOWN) {
-                p-&gt;interface_state = AST_STATE_DOWN;
-                p-&gt;phone_callflow = CALLFLOW_CALL_IDLE;
-                if (option_debug)
-                  NOTICA(&quot;We think we are using a nokia3310, so NETWORK STATUS REGISTERED&quot;
-                         &quot; is interpreted as REMOTE PARTY HANG UP during a call, because&quot;
-                         &quot; Nokia 3310 give no hint about remote hangup. Nokia 3310&quot;
-                         &quot; does not signal the CALLID, while other nokias at least put&quot;
-                         &quot; callid_name[0]=1 (also if no callid was transmitted by remote&quot;
-                         &quot; party), we use this lack of CALLID as a sign of 3310nness.&quot;
-                         &quot; Outside a call, or when CALLID has been signaled, NETWORK STATUS&quot;
-                         &quot; REGISTERED is ignored.\n&quot;, SKYPIAX_P_LOG);
-                fbus_mesg = CALLFLOW_INCOMING_HANGUP;
-              }
-              known = 1;
-              break;
-            }
-            break;
-/****************************************************************/
-            /* this kind of frames is about CALL STATUS */
-          case FBUS2_TYPE_CALL_STATUS:
-            switch (p-&gt;array[12]) {
-              /* this subkind of frames is about CALL STATUS OFF */
-            case FBUS2_CALL_STATUS_OFF:
-              p-&gt;interface_state = AST_STATE_DOWN;
-              p-&gt;phone_callflow = CALLFLOW_CALL_IDLE;
-              if (option_debug &gt; 1)
-                DEBUGA_FBUS2(&quot;STATUS call in progress OFF, inseqnum %.2X \n&quot;,
-                             SKYPIAX_P_LOG, seqnum);
-              fbus_mesg = CALLFLOW_INCOMING_HANGUP;
-              known = 1;
-              break;
-              /* this subkind of frames is about CALL STATUS ON */
-            case FBUS2_CALL_STATUS_ON:
-              if (option_debug &gt; 1)
-                DEBUGA_FBUS2(&quot;STATUS call in progress ON, inseqnum %.2X \n&quot;,
-                             SKYPIAX_P_LOG, seqnum);
-              known = 1;
-              break;
-            }
-/****************************************************************/
-            break;
-          }
-
-          /* categorization of frame is ended, if it has not been recognized, whine */
-          if (!known) {
-            WARNINGA(&quot;FBUS2 MSG UNKNOWN, inseqnum %.2X\n&quot;, SKYPIAX_P_LOG, seqnum);
-          }
-
-          /* let's print our frame */
-          if (option_debug &gt; 1) {
</del><ins>+          if (strlen(tech_pvt-&gt;sms_receiving_program)) {
+            int fd1[2];
+            pid_t pid1;
+            char *arg1[] = { tech_pvt-&gt;sms_receiving_program, (char *) NULL };
</ins><span class="cx">             int i;
</span><del>-            char debug_buf[1024];
-            char *debug_buf_pos;
</del><span class="cx"> 
</span><del>-            memset(debug_buf, 0, 1024);
-            debug_buf_pos = debug_buf;
-            for (i = 0; i &lt; p-&gt;arraycounter + 1; i++) {
-              debug_buf_pos += sprintf(debug_buf_pos, &quot;[%.2X] &quot;, p-&gt;array[i]);
-              if (debug_buf_pos &gt; (char *) (&amp;debug_buf + 1000))
-                break;
-            }
-            DEBUGA_FBUS2(&quot;%s is the RECEIVED FRAME inseqnum %.2X\n&quot;, SKYPIAX_P_LOG,
-                         debug_buf, seqnum);
-          }
</del><ins>+            NOTICA(&quot;incoming SMS message:&gt;&gt;&gt;%s&lt;&lt;&lt;\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;sms_message);
+            pipe(fd1);
+            pid1 = fork();
</ins><span class="cx"> 
</span><del>-          /* if the frame we received is not an ACK frame, let's ACKnowledge it */
-          if (p-&gt;array[0] == FBUS2_SERIAL_FRAME_ID &amp;&amp; p-&gt;array[3] != FBUS2_ACK_BYTE) {
-            celliax_serial_send_ack_FBUS2(p, p-&gt;array[3], seqnum);
-          }
-        }
-        p-&gt;arraycounter++;
-      }
-    }
-    UNLOCKA(&amp;p-&gt;controldev_lock);
-    POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  }
-  /* oooops, select returned error, got a kill/cancel or problems with the serial file descriptor */
-  if (select_err == -1) {
-    if (errno != EINTR) {
-      ERRORA
-        (&quot;select returned -1 on %s, marking controldev as dead, errno was: %d, error was: %s\n&quot;,
-         SKYPIAX_P_LOG, p-&gt;controldevice_name, errno, strerror(errno));
-      p-&gt;controldev_dead = 1;
-      close(p-&gt;controldevfd);
-      if (p-&gt;owner)
-        celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
-      return -1;
-    } else {
-      WARNINGA(&quot;select returned -1 on %s, errno was: %d, EINTR, error was: %s\n&quot;,
-               SKYPIAX_P_LOG, p-&gt;controldevice_name, errno, strerror(errno));
-      return 0;
-    }
-  }
-  /* OK, reading done, let's browse the list of pending frames to be sent, and act on it */
-  if (celliax_serial_send_if_time_FBUS2(p)) {
-    ERRORA(&quot;celliax_serial_send_if_time_FBUS2 failed!\n&quot;, SKYPIAX_P_LOG);
-    return -1;
-  }
</del><ins>+            if (pid1 == 0) {    //child
+              int err;
</ins><span class="cx"> 
</span><del>-  if (fbus_mesg == CALLFLOW_INCOMING_HANGUP) {
-    if (p-&gt;owner) {
-      celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
-      DEBUGA_FBUS2(&quot;phone call ended\n&quot;, SKYPIAX_P_LOG);
-    }
-  }
-
-  return fbus_mesg;             //FIXME breaks the convention of returning 0 on success
-}
-
-#endif /* CELLIAX_FBUS2 */
-
-#ifdef CELLIAX_CVM
-
-int celliax_serial_sync_CVM_BUSMAIL(private_t * tech_pvt)
-{
-  usleep(1000);                 /* 1msec */
-  time(&amp;p-&gt;celliax_serial_synced_timestamp);
-  return 0;
-}
-
-int celliax_serial_answer_CVM_BUSMAIL(private_t * tech_pvt)
-{
-  if (AST_STATE_RING == p-&gt;interface_state) {
-    DEBUGA_CVM(&quot;Sending commands to answer an incomming call...\n&quot;, SKYPIAX_P_LOG);
-    celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_CONNECT_REQ, 0, NULL);
-
-  } else {
-    DEBUGA_CVM
-      (&quot;SKIPPING Sending commands to answer an incomming call, because: !AST_STATE_RING\n&quot;,
-       SKYPIAX_P_LOG);
-  }
-
-  return 0;
-}
-
-int celliax_serial_call_CVM_BUSMAIL(private_t * tech_pvt, char *dstr)
-{
-  unsigned char bCallType = 0x01;   /* INTERNAL */
-
-  unsigned char DialReqBuff[2];
-
-  celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_SETUP_REQ, sizeof(bCallType),
-                                             &amp;bCallType);
-
-  while (AST_STATE_DOWN == p-&gt;interface_state) {
-    usleep(10000);              //10msec
-  }
-
-  if (AST_STATE_DIALING == p-&gt;interface_state) {
-    /* as for now, we only support internal calls */
-    /* &quot;0&quot; - call speaker phone */
-    /* &quot;1&quot; - call handset #1 */
-    /* &quot;2&quot; - call handset #2 */
-    /* ... */
-
-    DialReqBuff[0] = 1;         /* number of digits to send */
-    DialReqBuff[1] = dstr[0];   /* digit to send */
-
-    celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_KEYPAD_REQ, 2, DialReqBuff);
-  }
-
-  if (option_debug)
-    NOTICA(&quot;CVM_BUSMAIL: sent commands to call\n&quot;, SKYPIAX_P_LOG);
-  return 0;
-}
-
-int celliax_serial_hangup_CVM_BUSMAIL(private_t * tech_pvt)
-{
-  unsigned char bReason = 0x0;  /* Normal hang-up */
-
-  if (p-&gt;interface_state != AST_STATE_DOWN) {
-    celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_RELEASE_REQ, sizeof(bReason),
-                                               &amp;bReason);
-
-    DEBUGA_CVM(&quot;CVM_BUSMAIL: sent commands to hangup the call\n&quot;, SKYPIAX_P_LOG);
-
-  } else {
-    DEBUGA_CVM(&quot;CVM_BUSMAIL: sent commands to hangup skipped because: AST_STATE_DOWN\n&quot;,
-               SKYPIAX_P_LOG);
-  }
-
-  return 0;
-}
-
-int celliax_serial_config_CVM_BUSMAIL(private_t * tech_pvt)
-{
-  int res;
-  int how_many_reads = 0;
-  unsigned char SubcriptionNo = p-&gt;cvm_subsc_no;
-  unsigned char RegistartionData[5];
-
-  p-&gt;cvm_lock_state = CVM_UNKNOWN_LOCK_STATE;
-  p-&gt;cvm_register_state = CVM_UNKNOWN_REGISTER_STATE;
-
-  PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  CVM_LOKKA(&amp;p-&gt;controldev_lock);
-
-  if (option_debug &gt; 1)
-    DEBUGA_CVM(&quot;Try to init communication with CVM...\n&quot;, SKYPIAX_P_LOG);
-
-  /* CVM after reset sends SABM CTRL frame, let's assume that CVM already sent it, that's the reply... */
-  celliax_serial_send_ctrl_frame_CVM_BUSMAIL(p,
-                                             BUSMAIL_HEADER_CTRL_FRAME |
-                                             BUSMAIL_HEADER_CTRL_UN_FRAME |
-                                             BUSMAIL_HEADER_UNID_SABM);
-  /*  usleep(10000);   *//* 10ms */
-
-  /* Now we are sending SABM CTRL frame, if CVM is out there, it should reply... */
-  celliax_serial_send_ctrl_frame_CVM_BUSMAIL(p,
-                                             BUSMAIL_HEADER_CTRL_FRAME |
-                                             BUSMAIL_HEADER_CTRL_UN_FRAME |
-                                             BUSMAIL_HEADER_UNID_SABM |
-                                             (BUSMAIL_HEADER_PF_BIT_MASK &amp; 0xFF));
-//  usleep(1000);
-
-  res = celliax_serial_read_CVM_BUSMAIL(p); //we don't have no monitor neither do_controldev_thread
-
-  DEBUGA_CVM(&quot;celliax_serial_read_CVM_BUSMAIL res= %X, expected %X\n&quot;, SKYPIAX_P_LOG, res,
-             (BUSMAIL_HEADER_CTRL_FRAME | BUSMAIL_HEADER_CTRL_UN_FRAME |
-              BUSMAIL_HEADER_SABM));
-
-  if (res == -1) {
-    ERRORA(&quot;failed celliax_serial_read_CVM_BUSMAIL\n&quot;, SKYPIAX_P_LOG);
-    CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-    return -1;
-  }
-
-  how_many_reads = 0;
-
-  while ((res &amp; 0xF0) !=
-         (BUSMAIL_HEADER_CTRL_FRAME | BUSMAIL_HEADER_CTRL_UN_FRAME | BUSMAIL_HEADER_SABM))
-  {
-
-    usleep(1000);
-    res = celliax_serial_read_CVM_BUSMAIL(p);
-    how_many_reads++;
-
-    if (res == -1) {
-      ERRORA(&quot;failed celliax_serial_read_CVM_BUSMAIL\n&quot;, SKYPIAX_P_LOG);
-      CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-      return -1;
-    }
-
-    if (how_many_reads &gt; 10) {
-      ERRORA(&quot;no expected results in %d celliax_serial_read_CVM_BUSMAIL\n&quot;, SKYPIAX_P_LOG,
-             how_many_reads);
-
-      ERRORA(&quot;Unable to initialize cmmunication with CVM...\n&quot;, SKYPIAX_P_LOG);
-
-      CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-      return -1;
-    }
-  }
-
-  DEBUGA_CVM(&quot;Communication with CVM initialized successfully...\n&quot;, SKYPIAX_P_LOG);
-
-  DEBUGA_CVM(&quot;Attempt to lock to FP...\n&quot;, SKYPIAX_P_LOG);
-
-  /* Try to connect to FP, try to lock to FP, maybe we registered with it in the past... */
-  /* CVM can hold up to 2 subscriptions in its EEPROM, celliax.conf contains number we should try */
-  /* eg. cvm_subscription_no = 1 */
-
-  celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_LOCK_REQ, sizeof(SubcriptionNo),
-                                             &amp;SubcriptionNo);
-
-  usleep(10000);
-
-  res = celliax_serial_read_CVM_BUSMAIL(p); //we don't have no monitor neither do_controldev_thread
-
-  if (res == -1) {
-    ERRORA(&quot;failed celliax_serial_read_CVM_BUSMAIL\n&quot;, SKYPIAX_P_LOG);
-    CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-    return -1;
-  }
-
-  how_many_reads = 0;
-
-  while (CVM_UNKNOWN_LOCK_STATE == p-&gt;cvm_lock_state) {
-
-/*    
-    if (0 == (how_many_reads % 10))
-    {
-      DEBUGA_CVM(&quot;Attempt to lock to FP... %d\n&quot;, SKYPIAX_P_LOG, how_many_reads/10 );
-      celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_LOCK_REQ, sizeof(SubcriptionNo) ,&amp;SubcriptionNo);
-    }
-*/
-
-    usleep(100000);
-
-    res = celliax_serial_read_CVM_BUSMAIL(p);
-    how_many_reads++;
-
-    if (res == -1) {
-      ERRORA(&quot;failed celliax_serial_read_CVM_BUSMAIL\n&quot;, SKYPIAX_P_LOG);
-      CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-      return -1;
-    }
-
-    if (how_many_reads &gt; 50) {
-      ERRORA(&quot;no expected results in %d celliax_serial_read_CVM_BUSMAIL\n&quot;, SKYPIAX_P_LOG,
-             how_many_reads);
-
-      ERRORA(&quot;Unable to lock to FP...\n&quot;, SKYPIAX_P_LOG);
-      break;
-    }
-  }
-
-  if (CVM_LOCKED_TO_FP == p-&gt;cvm_lock_state) {
-    DEBUGA_CVM(&quot;CVM locked to FP successfully...\n&quot;, SKYPIAX_P_LOG);
-  } else {
-    DEBUGA_CVM(&quot;Lock to FP failed, Attempt to register to FP...\n&quot;, SKYPIAX_P_LOG);
-
-    RegistartionData[0] = SubcriptionNo;
-    RegistartionData[1] = 0xFF;
-    RegistartionData[2] = 0xFF;
-
-    if (1 == SubcriptionNo) {
-      RegistartionData[3] =
-        (((p-&gt;cvm_subsc_1_pin[3] - 0x30) &amp; 0x0F) &lt;&lt; 4) | ((p-&gt;cvm_subsc_1_pin[2] -
-                                                           0x30) &amp; 0x0F);
-      RegistartionData[4] =
-        (((p-&gt;cvm_subsc_1_pin[1] - 0x30) &amp; 0x0F) &lt;&lt; 4) | ((p-&gt;cvm_subsc_1_pin[0] -
-                                                           0x30) &amp; 0x0F);
-    } else {
-      RegistartionData[3] =
-        (((p-&gt;cvm_subsc_2_pin[3] - 0x30) &amp; 0x0F) &lt;&lt; 4) | ((p-&gt;cvm_subsc_2_pin[2] -
-                                                           0x30) &amp; 0x0F);
-      RegistartionData[4] =
-        (((p-&gt;cvm_subsc_2_pin[1] - 0x30) &amp; 0x0F) &lt;&lt; 4) | ((p-&gt;cvm_subsc_2_pin[0] -
-                                                           0x30) &amp; 0x0F);
-    }
-
-    celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_ACCESS_RIGHTS_REQ,
-                                               sizeof(RegistartionData),
-                                               RegistartionData);
-
-    usleep(100000);
-
-    res = celliax_serial_read_CVM_BUSMAIL(p);   //we don't have no monitor neither do_controldev_thread
-
-    if (res == -1) {
-      ERRORA(&quot;failed celliax_serial_read_CVM_BUSMAIL\n&quot;, SKYPIAX_P_LOG);
-      CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-      return -1;
-    }
-
-    how_many_reads = 0;
-
-    while (CVM_UNKNOWN_REGISTER_STATE == p-&gt;cvm_register_state) {
-
-      if (0 == (how_many_reads % 50)) {
-        DEBUGA_CVM(&quot;Attempt to register to FP... %d\n&quot;, SKYPIAX_P_LOG,
-                   how_many_reads / 10);
-        celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_ACCESS_RIGHTS_REQ,
-                                                   sizeof(RegistartionData),
-                                                   RegistartionData);
-      }
-
-      /* up to 5 minutes for registration.... */
-      usleep(1000000);
-      res = celliax_serial_read_CVM_BUSMAIL(p);
-      how_many_reads++;
-
-      if (res == -1) {
-        ERRORA(&quot;failed celliax_serial_read_CVM_BUSMAIL\n&quot;, SKYPIAX_P_LOG);
-        CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-        return -1;
-      }
-
-      if (how_many_reads &gt; 300) {
-        ERRORA(&quot;no expected results in %d celliax_serial_read_CVM_BUSMAIL\n&quot;,
-               SKYPIAX_P_LOG, how_many_reads);
-
-        ERRORA(&quot;Unable to communication with CVM...\n&quot;, SKYPIAX_P_LOG);
-
-        CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-        return -1;
-      }
-    }
-
-    if (CVM_REGISTERED_TO_FP != p-&gt;cvm_register_state) {
-      ERRORA(&quot;Unable to register to FP...\n&quot;, SKYPIAX_P_LOG);
-
-      CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-      return -1;
-
-    } else {
-      DEBUGA_CVM(&quot;CVM registered to FP successfully...\n&quot;, SKYPIAX_P_LOG);
-      DEBUGA_CVM(&quot;Attempt to lock to FP...\n&quot;, SKYPIAX_P_LOG);
-
-      /* Try to connect to FP, try to lock to FP, maybe we registered with it in the past... */
-      /* CVM can hold up to 2 subscriptions in its EEPROM, celliax.conf contains number we should try */
-      /* eg. cvm_subscription_no = 1 */
-
-      celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_LOCK_REQ,
-                                                 sizeof(SubcriptionNo), &amp;SubcriptionNo);
-
-      usleep(10000);
-
-      res = celliax_serial_read_CVM_BUSMAIL(p); //we don't have no monitor neither do_controldev_thread
-
-      if (res == -1) {
-        ERRORA(&quot;failed celliax_serial_read_CVM_BUSMAIL\n&quot;, SKYPIAX_P_LOG);
-        CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-        return -1;
-      }
-
-      how_many_reads = 0;
-
-      while (CVM_UNKNOWN_LOCK_STATE == p-&gt;cvm_lock_state) {
-
-        if (0 == (how_many_reads % 10)) {
-          DEBUGA_CVM(&quot;Attempt to lock to FP... %d\n&quot;, SKYPIAX_P_LOG, how_many_reads / 10);
-          celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_ACCESS_RIGHTS_REQ,
-                                                     sizeof(RegistartionData),
-                                                     RegistartionData);
-        }
-
-        usleep(10000);
-        res = celliax_serial_read_CVM_BUSMAIL(p);
-        how_many_reads++;
-
-        if (res == -1) {
-          ERRORA(&quot;failed celliax_serial_read_CVM_BUSMAIL\n&quot;, SKYPIAX_P_LOG);
-          CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-          return -1;
-        }
-
-        if (how_many_reads &gt; 100) {
-          ERRORA(&quot;no expected results in %d celliax_serial_read_CVM_BUSMAIL\n&quot;,
-                 SKYPIAX_P_LOG, how_many_reads);
-
-          ERRORA(&quot;Unable to communication with CVM...\n&quot;, SKYPIAX_P_LOG);
-
-          CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-          return -1;
-        }
-      }
-
-      if (CVM_LOCKED_TO_FP != p-&gt;cvm_lock_state) {
-        ERRORA(&quot;Unable to lock to FP...\n&quot;, SKYPIAX_P_LOG);
-
-        CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-        return -1;
-      } else {
-        DEBUGA_CVM(&quot;CVM locked to FP successfully...\n&quot;, SKYPIAX_P_LOG);
-      }
-    }
-  }
-
-  usleep(100000);
-
-  CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  return 0;
-
-}
-
-int celliax_serial_read_CVM_BUSMAIL(private_t * tech_pvt)
-{
-  int read_count;
-  int select_err;
-  fd_set read_fds;
-  struct timeval timeout;
-  int cvm_busmail_mesg = 0;
-  unsigned char busmail_crc = 0;
-  unsigned char MsgCrc = 0;
-  unsigned char MsgHeader = 0;
-  unsigned char MsgTxSeqNo = 0;
-  unsigned char MsgRxSeqNo = 0;
-  unsigned char MsgTaskId = 0;
-  unsigned char MsgProgId = 0;
-  unsigned char MsgPrimitiveLSB = 0;
-  unsigned char MsgPrimitiveMSB = 0;
-  unsigned int MsgPrimitive = 0;
-
-  int i = 0;
-
-  FD_ZERO(&amp;read_fds);
-  FD_SET(p-&gt;controldevfd, &amp;read_fds);
-  timeout.tv_sec = 0;
-  timeout.tv_usec = 10000;
-
-  if ((select_err = select(p-&gt;controldevfd + 1, &amp;read_fds, NULL, NULL, &amp;timeout)) &gt; 0) {
-    timeout.tv_sec = 0;         //reset the timeout, linux modify it
-    timeout.tv_usec = 10000;    //reset the timeout, linux modify it
-    PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-    CVM_LOKKA(&amp;p-&gt;controldev_lock);
-
-    while ((select_err =
-            select(p-&gt;controldevfd + 1, &amp;read_fds, NULL, NULL, &amp;timeout)) &gt; 0) {
-      gettimeofday(&amp;p-&gt;cvm_busmail_list_tv, &amp;p-&gt;cvm_busmail_list_tz);
-      read_count = read(p-&gt;controldevfd, p-&gt;rxm, 255);
-
-      if (read_count == 0) {
-        ERRORA
-          (&quot;read 0 bytes!!! Nenormalno! Marking this celliax_serial_device %s as dead, andif it is owned by a channel, hanging up. Maybe the CVM is stuck, switched off or power down.\n&quot;,
-           SKYPIAX_P_LOG, p-&gt;controldevice_name);
-
-        p-&gt;controldev_dead = 1;
-        close(p-&gt;controldevfd);
-        CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-
-        if (p-&gt;owner)
-          celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
-        return -1;
-      }
-
-      if (option_debug &gt; 10) {
-        char debug_buf[1024];
-        char *debug_buf_pos;
-
-        memset(debug_buf, 0, 1024);
-        debug_buf_pos = debug_buf;
-        for (i = 0; i &lt; read_count; i++) {
-          debug_buf_pos += sprintf(debug_buf_pos, &quot;[%.2X] &quot;, p-&gt;rxm[i]);
-          if (debug_buf_pos &gt; (char *) (&amp;debug_buf + 1000))
-            break;
-        }
-
-        DEBUGA_CVM(&quot;%s READ AT seconds=%ld usec=%6ld read_count=%d\n&quot;, SKYPIAX_P_LOG,
-                   debug_buf, p-&gt;cvm_busmail_list_tv.tv_sec,
-                   p-&gt;cvm_busmail_list_tv.tv_usec, read_count);
-      }
-
-      for (i = 0; i &lt; read_count; i++) {
-        if (p-&gt;rxm[i] == BUSMAIL_SOF) {
-          /* if we have identified the start of an busmail frame sent to us by the CVM */
-          /* clean the array, copy into it the beginning of the frame, move the counter in the array after the last byte copied */
-          memset(p-&gt;array, 0, 255);
-          p-&gt;array[0] = p-&gt;rxm[i];
-          p-&gt;arraycounter = 1;
-        }
-
-        /* buffer overload protection */
-        if (255 == p-&gt;arraycounter) {
-          p-&gt;arraycounter = 1;
-        }
-
-        /* continue copying into the array, until... */
-        p-&gt;array[p-&gt;arraycounter - 1] = p-&gt;rxm[i];
-
-        /* we reach the end of the incoming frame, its lenght is in the p-&gt;array[BUSMAIL_OFFSET_LEN_LSB] byte, plus overhead */
-        if (p-&gt;arraycounter == p-&gt;array[BUSMAIL_OFFSET_LEN_LSB] + 4) {
-
-          tcflush(p-&gt;controldevfd, TCIFLUSH);   /* PL2303HX bug? */
-          /* start categorizing frames */
-
-          if (option_debug &gt; 10) {
-            char debug_buf[1024];
-            char *debug_buf_pos;
-
-            memset(debug_buf, 0, 1024);
-            debug_buf_pos = debug_buf;
-
-            for (i = 0; i &lt; p-&gt;arraycounter; i++) {
-              debug_buf_pos += sprintf(debug_buf_pos, &quot;[%.2X] &quot;, p-&gt;array[i]);
-              if (debug_buf_pos &gt; (char *) (&amp;debug_buf + 1000))
-                break;
-            }
-
-            DEBUGA_CVM(&quot;%s was received, Starting to categorize this frame\n&quot;,
-                       SKYPIAX_P_LOG, debug_buf);
-          }
-
-          int known = 0;
-          int j = 0;
-
-          busmail_crc = 0;
-          MsgCrc = p-&gt;array[p-&gt;arraycounter - 1];
-
-          busmail_crc = (unsigned char) (p-&gt;array[BUSMAIL_OFFSET_HEADER] + busmail_crc);
-
-          for (j = BUSMAIL_OFFSET_MAIL; j &lt; (p-&gt;arraycounter - 1); j++) {
-            busmail_crc = (unsigned char) (p-&gt;array[j] + busmail_crc);
-          }
-
-          if (busmail_crc != MsgCrc) {
-            WARNINGA(&quot;BUSMAIL MSG CRC FAILED!, MsgCrc %.2X, calcd %.2X, dropping frame\n&quot;,
-                     SKYPIAX_P_LOG, MsgCrc, busmail_crc);
-          } else {
-            /* first step in categorizing frames, look at the general kind of frame, in p-&gt;array[BUSMAIL_OFFSET_HEADER] */
-            if (option_debug &gt; 1)
-              DEBUGA_CVM(&quot;BUSMAIL MSG CRC, MsgCrc %.2X, calcd %.2X...\n&quot;, SKYPIAX_P_LOG,
-                         MsgCrc, busmail_crc);
-
-            MsgHeader = p-&gt;array[BUSMAIL_OFFSET_HEADER];
-            cvm_busmail_mesg = MsgHeader;
-
-            switch (MsgHeader &amp; BUSMAIL_HEADER_IC_BIT_MASK) {
-            case BUSMAIL_HEADER_INFO_FRAME:
-              /* analyzis of frame header */
-              MsgTxSeqNo = ((MsgHeader &amp; BUSMAIL_HEADER_TXSEQ_MASK) &gt;&gt; 4);
-              MsgRxSeqNo = ((MsgHeader &amp; BUSMAIL_HEADER_RXSEQ_MASK));
-
-              if (option_debug &gt; 1)
-                DEBUGA_CVM(&quot;BUSMAIL_HEADER_INFO_FRAME TxSeq %X, RxSeq %X\n&quot;,
-                           SKYPIAX_P_LOG, MsgTxSeqNo, MsgRxSeqNo);
-
-              if (((p-&gt;busmail_rxseq_cvm_last + 1) &amp; 0x7) != MsgTxSeqNo) {
-                /* some CVM frames are missing, TxSeq of this frame is higher then expected */
-                /* reject, I expected p-&gt;busmail_rxseq_cvm_last + 1, resend it to me, please */
-
-                WARNINGA(&quot;CVM TxSeq %X, does not match expected value %X\n&quot;,
-                         SKYPIAX_P_LOG, MsgTxSeqNo,
-                         (p-&gt;busmail_rxseq_cvm_last + 1) &amp; 0x7);
-
-//                celliax_serial_send_ctrl_frame_CVM_BUSMAIL(p, BUSMAIL_HEADER_CTRL_FRAME | BUSMAIL_HEADER_CTRL_SU_FRAME | BUSMAIL_HEADER_SUID_REJ);
-
-                if (((p-&gt;busmail_rxseq_cvm_last) &amp; 0x7) == MsgTxSeqNo) {
-
-                  WARNINGA
-                    (&quot;It looks like our ACK to this frame was MIA :), lets ACK the frame one more time...\n&quot;,
-                     SKYPIAX_P_LOG);
-
-                  /* if the frame we received informs us that other side is waiting for ACK, let's ACK it */
-                  /* even if it is unknown to us */
-                  if (p-&gt;array[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_PF_BIT_MASK) {
-                    if (BUSMAIL_HEADER_SABM ==
-                        (p-&gt;array[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_SABM_MASK)) {
-                      celliax_serial_send_ctrl_frame_CVM_BUSMAIL(p, (unsigned char)
-                                                                 (BUSMAIL_HEADER_CTRL_FRAME | BUSMAIL_HEADER_CTRL_UN_FRAME | BUSMAIL_HEADER_UNID_SABM));
-                    } else {
-                      celliax_serial_send_ctrl_frame_CVM_BUSMAIL(p, (unsigned char)
-                                                                 (BUSMAIL_HEADER_CTRL_FRAME | BUSMAIL_HEADER_CTRL_SU_FRAME | BUSMAIL_HEADER_SUID_RR));
-                    }
-                  }
-                }
-
-                break;
-              } else {
-                /* we expected packet with this seq no. */
-                /* CVM ACKed our frames with info frame */
-                celliax_serial_list_acknowledge_CVM_BUSMAIL(p, MsgRxSeqNo);
-
-                /* save it but limit it to 3 bits only (valid values: 0-7) */
-                p-&gt;busmail_rxseq_cvm_last = MsgTxSeqNo;
-                p-&gt;busmail_rxseq_cvm_last &amp;= 0x7;
-
-                /* if the frame we received informs us that other side is waiting for ACK, let's ACK it */
-                /* even if it is unknown to us */
-                if (p-&gt;array[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_PF_BIT_MASK) {
-                  if (BUSMAIL_HEADER_SABM ==
-                      (p-&gt;array[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_SABM_MASK)) {
-                    celliax_serial_send_ctrl_frame_CVM_BUSMAIL(p, (unsigned char)
-                                                               (BUSMAIL_HEADER_CTRL_FRAME
-                                                                |
-                                                                BUSMAIL_HEADER_CTRL_UN_FRAME
-                                                                |
-                                                                BUSMAIL_HEADER_UNID_SABM));
-                  } else {
-                    celliax_serial_send_ctrl_frame_CVM_BUSMAIL(p, (unsigned char)
-                                                               (BUSMAIL_HEADER_CTRL_FRAME
-                                                                |
-                                                                BUSMAIL_HEADER_CTRL_SU_FRAME
-                                                                |
-                                                                BUSMAIL_HEADER_SUID_RR));
-                  }
-                }
-
</del><ins>+              dup2(fd1[0], 0);  // Connect stdin to pipe output
+              close(fd1[1]);    // close input pipe side
+              setsid();         //session id
+              err = execvp(arg1[0], arg1);  //exec our program, with stdin connected to pipe output
+              if (err) {
+                ERRORA
+                  (&quot;'sms_receiving_program' is set in config file to '%s', and it gave us back this error: %d, (%s). SMS received was:---%s---\n&quot;,
+                   SKYPIAX_P_LOG, tech_pvt-&gt;sms_receiving_program, err, strerror(errno),
+                   tech_pvt-&gt;sms_message);
</ins><span class="cx">               }
</span><del>-
-              /* frame header OK, let's see what's inside mail field */
-              MsgTaskId = p-&gt;array[BUSMAIL_OFFSET_MAIL_TASK_ID];
-              MsgProgId = p-&gt;array[BUSMAIL_OFFSET_MAIL_PROGRAM_ID];
-              MsgPrimitiveLSB = p-&gt;array[BUSMAIL_OFFSET_MAIL_PRIMITIVE_LSB];
-              MsgPrimitiveMSB = p-&gt;array[BUSMAIL_OFFSET_MAIL_PRIMITIVE_MSB];
-              MsgPrimitive = MsgPrimitiveMSB &lt;&lt; 8 | MsgPrimitiveLSB;
-
-              if (option_debug &gt; 1)
-                DEBUGA_CVM
-                  (&quot;BUSMAIL_HEADER_INFO_FRAME ProgId %X, TaskId %X, Primitive %X %X\n&quot;,
-                   SKYPIAX_P_LOG, MsgProgId, MsgTaskId, MsgPrimitiveMSB, MsgPrimitiveLSB);
-
-              switch (MsgPrimitive) {
-
-              case API_PP_ACCESS_RIGHTS_REJ:
-                /* FP rejected our registration... */
-                WARNINGA(&quot;API_PP_ACCESS_RIGHTS_REJ, FP rejected our registration...\n&quot;,
-                         SKYPIAX_P_LOG);
-
-                p-&gt;cvm_register_state = CVM_UNREGISTERED_TO_FP;
-                p-&gt;cvm_lock_state = CVM_UNKNOWN_LOCK_STATE;
-                known = 1;
-                break;
-
-              case API_PP_ACCESS_RIGHTS_CFM:
-                /* FP accepted our registration... */
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM
-                    (&quot;API_PP_ACCESS_RIGHTS_CFM, FP accepted our registration...\n&quot;,
-                     SKYPIAX_P_LOG);
-
-                p-&gt;cvm_register_state = CVM_REGISTERED_TO_FP;
-                p-&gt;cvm_lock_state = CVM_UNKNOWN_LOCK_STATE;
-                p-&gt;cvm_handset_no = p-&gt;array[BUSMAIL_OFFSET_MAIL_PARAMS + 0];
-                p-&gt;cvm_fp_is_cvm = p-&gt;array[BUSMAIL_OFFSET_MAIL_PARAMS + 1];
-
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM
-                    (&quot;API_PP_ACCESS_RIGHTS_CFM, FP accepted our registration, Our handset no. is %d, CVM? %X\n&quot;,
-                     SKYPIAX_P_LOG, p-&gt;cvm_handset_no, p-&gt;cvm_fp_is_cvm);
-
-                known = 1;
-                break;
-
-              case API_PP_LOCKED_IND:
-                /* CVM is connected to FP */
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM(&quot;API_PP_LOCKED_IND, Connection to FP completed...\n&quot;,
-                             SKYPIAX_P_LOG);
-
-                p-&gt;cvm_register_state = CVM_REGISTERED_TO_FP;
-                p-&gt;cvm_lock_state = CVM_LOCKED_TO_FP;
-                known = 1;
-                break;
-
-              case API_PP_UNLOCKED_IND:
-                /* CVM is unlocked with FP, Out of service */
-                WARNINGA
-                  (&quot;API_PP_UNLOCKED_IND, CVM is unlocked with FP, Out of service !!!\n&quot;,
-                   SKYPIAX_P_LOG);
-
-                p-&gt;cvm_lock_state = CVM_UNLOCKED_TO_FP;
-                known = 1;
-                break;
-
-              case API_PP_SETUP_ACK_IND:
-                /* Outgoing call, connection to FP established, FP is waiting for a number to dial */
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM
-                    (&quot;API_PP_SETUP_ACK_IND, connection to FP established, FP is waiting for a numer to dial...\n&quot;,
-                     SKYPIAX_P_LOG);
-
-                if (AST_STATE_DOWN == p-&gt;interface_state) {
-                  p-&gt;interface_state = AST_STATE_DIALING;
-                }
-
-                known = 1;
-                break;
-
-              case API_PP_ALERT_IND:
-                /* Outgoing call, Remote end is ringing */
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM(&quot;API_PP_ALERT_IND, remote end is ringing...\n&quot;,
-                             SKYPIAX_P_LOG);
-
-                if (AST_STATE_DIALING == p-&gt;interface_state) {
-                  p-&gt;interface_state = AST_STATE_RINGING;
-                }
-
-                known = 1;
-                break;
-
-              case API_PP_CONNECT_IND:
-                /* Outgoing call, the remote end answered our call */
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM(&quot;API_PP_CONNECT_IND, our call was answered...\n&quot;,
-                             SKYPIAX_P_LOG);
-
-                if (AST_STATE_RINGING == p-&gt;interface_state) {
-
-                  /* let's open audio and have a chat */
-                  celliax_serial_send_info_frame_CVM_BUSMAIL(p, CVM_PP_AUDIO_OPEN_REQ, 0,
-                                                             NULL);
-
-                  unsigned char volume = (unsigned char) p-&gt;cvm_volume_level;
-                  celliax_serial_send_info_frame_CVM_BUSMAIL(p,
-                                                             CVM_PP_AUDIO_SET_VOLUME_REQ,
-                                                             sizeof(volume), &amp;volume);
-
-                  /* let's unmute mic and have a chat */
-                  celliax_serial_send_info_frame_CVM_BUSMAIL(p,
-                                                             CVM_PP_AUDIO_UNMUTE_MIC_REQ,
-                                                             0, NULL);
-
-                  /* let's switch to headset, because we fried normal output.... */
-/*                  unsigned char headset_on = (unsigned char) 1;
-                  celliax_serial_send_info_frame_CVM_BUSMAIL(p, CVM_PP_AUDIO_HS_PLUG_IND, sizeof(headset_on), &amp;headset_on);
-*/
-                  p-&gt;interface_state = AST_STATE_UP;
-                  ast_setstate(p-&gt;owner, AST_STATE_RINGING);
-                  celliax_queue_control(p-&gt;owner, AST_CONTROL_ANSWER);
-                }
-
-                known = 1;
-                break;
-
-              case API_PP_REJECT_IND:
-                /* Outgoing/Incoming call, FP rejected our connection... */
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM
-                    (&quot;API_PP_REJECT_IND, FP or ther PP rejected our connection...\n&quot;,
-                     SKYPIAX_P_LOG);
-
-                if (AST_STATE_RING == p-&gt;interface_state &amp;&amp; p-&gt;owner) {
-                  /* Attempt to answer incoming call rejected by FP or PP */
-                  if (option_debug &gt; 1)
-                    DEBUGA_CVM(&quot;Was it PAGE_ALL CALL, that we should not answered?\n&quot;,
-                               SKYPIAX_P_LOG);
-
-                  p-&gt;interface_state = AST_STATE_DOWN;
-                  celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
-
-                } else if (AST_STATE_DOWN != p-&gt;interface_state &amp;&amp; p-&gt;owner) {
-                  /* Outgoing call rejected by other PP or FP */
-                  p-&gt;interface_state = AST_STATE_BUSY;
-                  ast_setstate(p-&gt;owner, AST_STATE_BUSY);
-                  celliax_queue_control(p-&gt;owner, AST_CONTROL_BUSY);
-                }
-
-                known = 1;
-                break;
-
-              case API_PP_SIGNAL_ON_IND:
-                /* Ringback, ignore it... */
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM(&quot;API_PP_SIGNAL_ON_IND, Ringback, ignore it...\n&quot;,
-                             SKYPIAX_P_LOG);
-
-                known = 1;
-                break;
-
-              case API_PP_SIGNAL_OFF_IND:
-                /* Ringback, ignore it... */
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM(&quot;API_PP_SIGNAL_OFF_IND, Ringback, ignore it...\n&quot;,
-                             SKYPIAX_P_LOG);
-
-                known = 1;
-                break;
-
-              case API_PP_SETUP_IND:
-                /* Incoming call, Somebody is calling us */
-
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM(&quot;API_PP_SETUP_IND, somebody is calling us...\n&quot;,
-                             SKYPIAX_P_LOG);
-
-                if (AST_STATE_DOWN == p-&gt;interface_state) {
-
-                  if (API_PP_SETUP_IND_CALL_INT ==
-                      p-&gt;array[BUSMAIL_OFFSET_MAIL_PARAMS +
-                               API_PP_SETUP_IND_CALL_TYPE_OFFSET]) {
-                    DEBUGA_CVM(&quot;INTERNAL CALL, receive it...\n&quot;, SKYPIAX_P_LOG);
-
-                    p-&gt;interface_state = AST_STATE_RING;
-
-                    /* inform calling end, that we know about his call, and that we are alerting */
-                    celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_ALERT_REQ, 0,
-                                                               NULL);
-
-                    /* let's open audio before valid mac, to remove noise... */
-                    celliax_serial_send_info_frame_CVM_BUSMAIL(p,
-                                                               CVM_PP_AUDIO_OPEN_ADPCM_OFF_REQ,
-                                                               0, NULL);
-
-                  } else {
-                    DEBUGA_CVM(&quot;NOT an INTERNAL CALL, CALL TYPE %X, just ignore it...\n&quot;,
-                               SKYPIAX_P_LOG,
-                               p-&gt;array[BUSMAIL_OFFSET_MAIL_PARAMS +
-                                        API_PP_SETUP_IND_CALL_TYPE_OFFSET]);
-
-                    /* inform calling end, that we know about his call, and that we are alerting OR not :) */
-                    /* probably it is needed so FP does not remove us from PP list :) */
-                    celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_ALERT_REQ, 0,
-                                                               NULL);
-                  }
-
-                } else {
-                  WARNINGA
-                    (&quot;Ignore incoming call, Wrong interface state, current state %X\n&quot;,
-                     SKYPIAX_P_LOG, p-&gt;interface_state);
-                }
-
-                known = 1;
-                break;
-
-              case API_PP_ALERT_OFF_IND:
-                /* Incoming call, We should stop alerting about incoming call... */
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM
-                    (&quot;API_PP_ALERT_OFF_IND, Ringback, stop alerting about incoming call...\n&quot;,
-                     SKYPIAX_P_LOG);
-
-                known = 1;
-                break;
-
-              case API_PP_ALERT_ON_IND:
-                /* Incoming call, We should stop alerting about incoming call... */
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM
-                    (&quot;API_PP_ALERT_ON_IND, Ringback, start alerting about incoming call...\n&quot;,
-                     SKYPIAX_P_LOG);
-/*
-                if (AST_STATE_DOWN == p-&gt;interface_state) {
-                  DEBUGA_CVM(&quot;Somebody is calling us, we see a PP_ALERT_ON_IND, receive it...\n&quot;, SKYPIAX_P_LOG);
-                  p-&gt;interface_state = AST_STATE_RING;
-                }
-*/
-                known = 1;
-                break;
-
-              case API_PP_CONNECT_CFM:
-                /* Incoming call, Confirmation for request to answer incoming call... */
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM
-                    (&quot;API_PP_CONNECT_CFM, Confirmation for request to answer incoming call...\n&quot;,
-                     SKYPIAX_P_LOG);
-
-                if (AST_STATE_RING == p-&gt;interface_state &amp;&amp; p-&gt;owner) {
-
-                  p-&gt;interface_state = AST_STATE_UP;
-                  ast_setstate(p-&gt;owner, AST_STATE_UP);
-
-                  /* let's open audio and have a chat */
-//                  celliax_serial_send_info_frame_CVM_BUSMAIL(p, CVM_PP_AUDIO_OPEN_ADPCM_OFF_REQ, 0, NULL);
-
-                  /* let's open audio and have a chat */
-                  celliax_serial_send_info_frame_CVM_BUSMAIL(p, CVM_PP_AUDIO_OPEN_REQ, 0,
-                                                             NULL);
-
-                  unsigned char volume = (unsigned char) p-&gt;cvm_volume_level;
-                  celliax_serial_send_info_frame_CVM_BUSMAIL(p,
-                                                             CVM_PP_AUDIO_SET_VOLUME_REQ,
-                                                             sizeof(volume), &amp;volume);
-
-                  /* let's unmute mic and have a chat */
-                  celliax_serial_send_info_frame_CVM_BUSMAIL(p,
-                                                             CVM_PP_AUDIO_UNMUTE_MIC_REQ,
-                                                             0, NULL);
-
-                  /* let's switch to headset, because we fried normal output.... */
-/*                  unsigned char headset_on = (unsigned char) 1;
-                  celliax_serial_send_info_frame_CVM_BUSMAIL(p, CVM_PP_AUDIO_HS_PLUG_IND, sizeof(headset_on), &amp;headset_on);
-*/
-                } else {
-                  WARNINGA
-                    (&quot;Ignore connection cfm, Wrong interface state, current state %X\n&quot;,
-                     SKYPIAX_P_LOG, p-&gt;interface_state);
-                }
-
-                known = 1;
-                break;
-
-              case API_PP_RELEASE_CFM:
-                /* Confirmation for request to hangup a call... */
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM
-                    (&quot;API_PP_RELEASE_CFM, Confirmation for request to hangup a call..\n&quot;,
-                     SKYPIAX_P_LOG);
-
-                if (AST_STATE_UP == p-&gt;interface_state) {
-                  /* let's close audio */
-                  celliax_serial_send_info_frame_CVM_BUSMAIL(p, CVM_PP_AUDIO_CLOSE_REQ, 0,
-                                                             NULL);
-
-                  /* let's unmute mic and have a chat */
-                  celliax_serial_send_info_frame_CVM_BUSMAIL(p, CVM_PP_AUDIO_MUTE_MIC_REQ,
-                                                             0, NULL);
-                }
-
-                p-&gt;interface_state = AST_STATE_DOWN;
-
-                known = 1;
-                break;
-
-              case API_PP_RELEASE_IND:
-                /* FP releases connection to CVM... */
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM(&quot;API_PP_RELEASE_IND, FP releases connection to CVM...\n&quot;,
-                             SKYPIAX_P_LOG);
-
-                if (AST_STATE_UP == p-&gt;interface_state &amp;&amp; p-&gt;owner) {
-                  /* let's close audio */
-                  celliax_serial_send_info_frame_CVM_BUSMAIL(p, CVM_PP_AUDIO_CLOSE_REQ, 0,
-                                                             NULL);
-                  p-&gt;interface_state = AST_STATE_DOWN;
-                  celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
-
-                } else if (AST_STATE_RING == p-&gt;interface_state &amp;&amp; p-&gt;owner) {
-                  /* workaround for PAGE ALL CALL, FIXME!!!! */
-                  if (option_debug &gt; 1)
-                    DEBUGA_CVM(&quot;WAS IT A PAGE ALL ???...\n&quot;, SKYPIAX_P_LOG);
-
-                  p-&gt;interface_state = AST_STATE_UP;
-                  usleep(100000);
-
-                  p-&gt;interface_state = AST_STATE_DOWN;
-                  celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
-                }
-
-                /* we need to ACK release */
-                celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_RELEASE_RES, 0,
-                                                           NULL);
-
-                known = 1;
-                break;
-
-              case API_PP_READ_RSSI_CFM:
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM(&quot;API_PP_READ_RSSI_CFM, RSSI readout...\n&quot;, SKYPIAX_P_LOG);
-
-                p-&gt;cvm_rssi = p-&gt;array[BUSMAIL_OFFSET_MAIL_PARAMS + 0];
-                int rssi_percent = p-&gt;cvm_rssi * 100 / 0x3F;
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM(&quot;RSSI is %X, %d%%...\n&quot;, SKYPIAX_P_LOG, p-&gt;cvm_rssi,
-                             rssi_percent);
-
-                known = 1;
-                break;
-              default:
-                WARNINGA(&quot;UNKNOWN MsgPrimitive!!! %X\n&quot;, SKYPIAX_P_LOG, MsgPrimitive);
-                break;
-              }
-
-              break;
-
-            case BUSMAIL_HEADER_CTRL_FRAME:
-              if (option_debug &gt; 1)
-                DEBUGA_CVM(&quot;BUSMAIL_HEADER_CTRL_FRAME\n&quot;, SKYPIAX_P_LOG);
-
-              switch (p-&gt;array[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_SU_BIT_MASK) {
-              case BUSMAIL_HEADER_CTRL_SU_FRAME:
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM(&quot;BUSMAIL_HEADER_CTRL_SU_FRAME\n&quot;, SKYPIAX_P_LOG);
-
-                switch (p-&gt;array[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_SUID_MASK) {
-                case BUSMAIL_HEADER_SUID_REJ:
-                  /* CVM Reject, CVM missed one of our packets, it will be resend, do nothing */
-                  MsgRxSeqNo =
-                    ((p-&gt;array[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_RXSEQ_MASK));
-
-                  if (option_debug &gt; 1)
-                    DEBUGA_CVM(&quot;BUSMAIL_HEADER_SUID_REJ, RxSeq %X\n&quot;, SKYPIAX_P_LOG,
-                               MsgRxSeqNo);
-
-                  /* Even that it is CVM Reject packet, it still ACKs some packets */
-                  celliax_serial_list_acknowledge_CVM_BUSMAIL(p, MsgRxSeqNo);
-
-                  known = 1;
-                  break;
-                case BUSMAIL_HEADER_SUID_RNR:
-                  /* CVM Receiver Not Ready, answer to packet that we sent, do nothing, it will be resend later */
-                  MsgRxSeqNo =
-                    ((p-&gt;array[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_RXSEQ_MASK));
-
-                  if (option_debug &gt; 1)
-                    DEBUGA_CVM(&quot;BUSMAIL_HEADER_SUID_RNR, RxSeq %X\n&quot;, SKYPIAX_P_LOG,
-                               MsgRxSeqNo);
-
-                  known = 1;
-                  break;
-                case BUSMAIL_HEADER_SUID_RR:
-                  /* CVM ACKs our packets */
-                  MsgRxSeqNo =
-                    ((p-&gt;array[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_RXSEQ_MASK));
-
-                  if (option_debug &gt; 1)
-                    DEBUGA_CVM(&quot;BUSMAIL_HEADER_SUID_RR, RxSeq %X\n&quot;, SKYPIAX_P_LOG,
-                               MsgRxSeqNo);
-
-                  /* CVM ACKed our frames with RR frame */
-                  celliax_serial_list_acknowledge_CVM_BUSMAIL(p, MsgRxSeqNo);
-
-                  known = 1;
-                  break;
-
-                default:
-                  WARNINGA(&quot;BUSMAIL_HEADER_SUID_UNKNOWN!!!\n&quot;, SKYPIAX_P_LOG);
-                  break;
-                }
-                break;
-
-              case BUSMAIL_HEADER_CTRL_UN_FRAME:
-                if (option_debug &gt; 1)
-                  DEBUGA_CVM(&quot;BUSMAIL_HEADER_CTRL_UN_FRAME\n&quot;, SKYPIAX_P_LOG);
-
-                switch (p-&gt;array[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_UNID_MASK) {
-
-                case BUSMAIL_HEADER_UNID_SABM:
-                  if (option_debug &gt; 1)
-                    DEBUGA_CVM(&quot;BUSMAIL_HEADER_UNID_SABM\n&quot;, SKYPIAX_P_LOG);
-                  /* reset seq counters */
-                  p-&gt;busmail_txseq_celliax_last = 0xFF;
-                  p-&gt;busmail_rxseq_cvm_last = 0xFF;
-
-                  celliax_serial_lists_free_CVM_BUSMAIL(p);
-                  /* if needed, reply will be send by code at the end of switch statements */
-                  known = 1;
-                  break;
-
-                default:
-                  WARNINGA(&quot;BUSMAIL_HEADER_UNID_UNKNOWN!!!\n&quot;, SKYPIAX_P_LOG);
-                  break;
-                }
-                break;
-
-              default:
-                WARNINGA(&quot;BUSMAIL_HEADER_CTRL_UNKNOWN!!!\n&quot;, SKYPIAX_P_LOG);
-                break;
-              }
-              break;
-
-            default:
-              WARNINGA(&quot;BUSMAIL_HEADER_UNKNOWN!!!\n&quot;, SKYPIAX_P_LOG);
-              break;
</del><ins>+              close(fd1[0]);    // close output pipe side
+            }                   //starting here continue the parent
+            close(fd1[0]);      // close output pipe side
+            // write the msg on the pipe input
+            for (i = 0; i &lt; strlen(tech_pvt-&gt;sms_message); i++) {
+              write(fd1[1], &amp;tech_pvt-&gt;sms_message[i], 1);
</ins><span class="cx">             }
</span><del>-
-          }
-
-          /* categorization of frame is ended, if it has not been recognized, whine */
-          if (!known) {
-            WARNINGA(&quot;BUSMAIL MSG UNKNOWN or REJECTED!\n&quot;, SKYPIAX_P_LOG);
-          }
-        }
-        p-&gt;arraycounter++;
-      }
-    }
-    CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-    POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  }
-
-  /* oooops, select returned error, got a kill/cancel or problems with the serial file descriptor */
-  if (select_err == -1) {
-    if (errno != EINTR) {
-      ERRORA
-        (&quot;select returned -1 on %s, marking controldev as dead, errno was: %d, error was: %s\n&quot;,
-         SKYPIAX_P_LOG, p-&gt;controldevice_name, errno, strerror(errno));
-
-      p-&gt;controldev_dead = 1;
-      close(p-&gt;controldevfd);
-
-      if (p-&gt;owner)
-        celliax_queue_control(p-&gt;owner, AST_CONTROL_HANGUP);
-      return -1;
-
-    } else {
-      WARNINGA(&quot;select returned -1 on %s, errno was: %d, EINTR, error was: %s\n&quot;,
-               SKYPIAX_P_LOG, p-&gt;controldevice_name, errno, strerror(errno));
-      return 0;
-    }
-  }
-  /* OK, reading done, let's browse the list of pending frames to be sent, and act on it */
-  if (celliax_serial_send_if_time_CVM_BUSMAIL(p)) {
-    ERRORA(&quot;celliax_serial_send_if_time_CVM_BUSMAIL failed!\n&quot;, SKYPIAX_P_LOG);
-    return -1;
-  }
-
-  return cvm_busmail_mesg;      //FIXME breaks the convention of returning 0 on success
-}
-
-int celliax_serial_getstatus_CVM_BUSMAIL(private_t * tech_pvt)
-{
-  int res;
-  int how_many_reads = 0;
-
-  PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  CVM_LOKKA(&amp;p-&gt;controldev_lock);
-
-  if (option_debug &gt; 1)
-    DEBUGA_CVM(&quot;Sending RR CTRL frame wit PF bit set\n&quot;, SKYPIAX_P_LOG);
-
-  /* this ctrl frame can be used as low level keep alive */
-  celliax_serial_send_ctrl_frame_CVM_BUSMAIL(p,
-                                             BUSMAIL_HEADER_CTRL_FRAME |
-                                             BUSMAIL_HEADER_CTRL_SU_FRAME |
-                                             BUSMAIL_HEADER_SUID_RR |
-                                             (BUSMAIL_HEADER_PF_BIT_MASK &amp; 0xFF));
-
-  //usleep(1000);
-
-  res = celliax_serial_read_CVM_BUSMAIL(p); //we don't have no monitor neither do_controldev_thread
-
-  if (res == -1) {
-    ERRORA(&quot;failed celliax_serial_read_CVM_BUSMAIL\n&quot;, SKYPIAX_P_LOG);
-    CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-    return -1;
-  }
-
-  while ((res &amp; 0xF0) !=
-         (BUSMAIL_HEADER_CTRL_FRAME | BUSMAIL_HEADER_CTRL_SU_FRAME |
-          BUSMAIL_HEADER_SUID_RR)) {
-
-    usleep(1000);
-    res = celliax_serial_read_CVM_BUSMAIL(p);
-    how_many_reads++;
-
-    if (res == -1) {
-      ERRORA(&quot;failed celliax_serial_read_CVM_BUSMAIL\n&quot;, SKYPIAX_P_LOG);
-      CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-      return -1;
-    }
-
-    if (how_many_reads &gt; 10) {
-      ERRORA(&quot;no expected results in %d celliax_serial_read_CVM_BUSMAIL\n&quot;, SKYPIAX_P_LOG,
-             how_many_reads);
-      CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-      return -1;
-    }
-  }
-
-  //celliax_serial_send_info_frame_CVM_BUSMAIL(p, API_PP_READ_RSSI_REQ, 0, NULL);
-
-  CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
-
-  return 0;
-
-}
-
-/*!
- * \brief Write on the serial port for all the CVM_BUSMAIL functions
- * \param p celliax_pvt
- * \param len lenght of buffer2
- * \param buffer2 chars to be written
- *
- * Write on the serial port for all the CVM_BUSMAIL functions
- *
- * \return the number of chars written on the serial, 
- * that can be different from len (or negative) in case of errors.
- */
-int celliax_serial_send_CVM_BUSMAIL(private_t * tech_pvt, int len,
-                                    unsigned char *mesg_ptr)
-{
-  int ret;
-  size_t actual = 0;
-  unsigned char *mesg_ptr2 = mesg_ptr;
-  PUSHA_UNLOCKA(&amp;p-&gt;controldev_lock);
-  CVM_LOKKA(&amp;p-&gt;controldev_lock);
-  do {
-    ret = write(p-&gt;controldevfd, mesg_ptr, len - actual);
-    if (ret &lt; 0 &amp;&amp; errno == EAGAIN)
-      continue;
-    if (ret &lt; 0) {
-      if (actual != len)
-        ERRORA(&quot;celliax_serial_write error: %s&quot;, SKYPIAX_P_LOG, strerror(errno));
-      CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-      return -1;
-    }
-    actual += ret;
-    mesg_ptr += ret;
-    usleep(10000);
-//    usleep(p-&gt;cvm_celliax_serial_delay*1000);
-  } while (actual &lt; len);
-
-  usleep(p-&gt;cvm_celliax_serial_delay * 1000);
-
-//  tcdrain(p-&gt;controldevfd);
-
-  CVM_UNLOCKA(&amp;p-&gt;controldev_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;controldev_lock);
-
-  if (option_debug &gt; 10) {
-    int i;
-    char debug_buf[1024];
-    char *debug_buf_pos;
-
-    memset(debug_buf, 0, 1024);
-    debug_buf_pos = debug_buf;
-
-    for (i = 0; i &lt; len; i++) {
-      debug_buf_pos += sprintf(debug_buf_pos, &quot;[%.2X] &quot;, mesg_ptr2[i]);
-      if (debug_buf_pos &gt; ((char *) &amp;debug_buf + 1000))
-        break;
-    }
-    DEBUGA_CVM(&quot;%s was sent down the wire\n&quot;, SKYPIAX_P_LOG, debug_buf);
-  }
-
-  return 0;
-}
-
-/*!
- * \brief Flags as acknowledged an BUSMAIL message previously sent
- * \param p celliax_pvt
- * \param seqnum identifier of the message to be acknowledged
- *
- * Called upon receiving an BUSMAIL acknoledgement message, browse the cvm_busmail_outgoing_list 
- * looking for the seqnum sent BUSMAIL message, and flags it as acknowledged.
- * (if an outgoing BUSMAIL message is not aknowledged by the cellphone in a while,
- * it will be retransmitted)
- *
- * \return 0 on error, 1 otherwise
- */
-int celliax_serial_list_acknowledge_CVM_BUSMAIL(private_t * tech_pvt,
-                                                unsigned char AckTxSeqNo)
-{
-  struct cvm_busmail_msg *ptr = NULL;
-  struct cvm_busmail_msg *old = NULL;
-
-  unsigned char MsgTxSeqNo;
-  unsigned char MsgRxSeqNo;
-
-  ptr = p-&gt;cvm_busmail_outgoing_list;
-
-  if (ptr == NULL) {
-    ERRORA(&quot;cvm_busmail_outgoing_list is NULL ?\n&quot;, SKYPIAX_P_LOG);
-    return -1;
-  }
-
-  PUSHA_UNLOCKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-  CVM_LOKKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-/*
-  DEBUGA_CVM(&quot;PREFREE OUTGOING list:\n&quot;, SKYPIAX_P_LOG);
-  celliax_serial_list_print_CVM_BUSMAIL(p, p-&gt;cvm_busmail_outgoing_list);
-*/
-  while (ptr-&gt;next != NULL)
-    ptr = ptr-&gt;next;
-
-  while (ptr) {
-
-    if ((1 == ptr-&gt;valid) &amp;&amp; (0 == ptr-&gt;acknowledged) &amp;&amp; (0 != ptr-&gt;sent)) {
-      MsgTxSeqNo =
-        ((ptr-&gt;busmail_msg_buffer[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_TXSEQ_MASK) &gt;&gt;
-         4);
-      MsgRxSeqNo =
-        ((ptr-&gt;busmail_msg_buffer[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_RXSEQ_MASK));
-
-/*
-    if (option_debug &gt; 1) 
-      DEBUGA_CVM(&quot;OUTGOING LIST TxSeq is %X, RxSeq is %X\n&quot;, SKYPIAX_P_LOG, MsgTxSeqNo, MsgRxSeqNo);
-*/
-      unsigned char TxToAck = 0;
-
-      if (0 == AckTxSeqNo) {
-        TxToAck = 7;
-      } else {
-        TxToAck = AckTxSeqNo - 1;
-      }
-
-      if (MsgTxSeqNo &lt;= TxToAck) {
-
-        if (option_debug &gt; 1)
-          DEBUGA_CVM(&quot;Msg with TxSeq=%X ACKed with CvmRxSeq=%X\n&quot;, SKYPIAX_P_LOG,
-                     MsgTxSeqNo, AckTxSeqNo);
-
-        old = ptr;
-        old-&gt;acknowledged = 1;
-        old-&gt;valid = 0;
-        ptr = old-&gt;previous;
-
-        if (old-&gt;previous) {
-          if (old-&gt;next) {
-            old-&gt;previous-&gt;next = old-&gt;next;
</del><ins>+            close(fd1[1]);      // close pipe input, let our program know we've finished
</ins><span class="cx">           } else {
</span><del>-            old-&gt;previous-&gt;next = NULL;
</del><ins>+            ERRORA
+              (&quot;got SMS incoming message, but 'sms_receiving_program' is not set in config file. SMS received was:---%s---\n&quot;,
+               SKYPIAX_P_LOG, tech_pvt-&gt;sms_message);
</ins><span class="cx">           }
</span><span class="cx">         }
</span><del>-
-        if (old-&gt;next) {
-          if (old-&gt;previous) {
-            old-&gt;next-&gt;previous = old-&gt;previous;
-          } else {
-            old-&gt;next-&gt;previous = NULL;
</del><ins>+#if 1                           //is this one needed? maybe it can interrupt an incoming call that is just to announce itself
+        if (tech_pvt-&gt;phone_callflow == CALLFLOW_CALL_IDLE
+            &amp;&amp; tech_pvt-&gt;interface_state == SKYPIAX_STATE_DOWN &amp;&amp; tech_pvt-&gt;owner == NULL) {
+          /* we're not in a call, neither calling */
+          res = celliax_serial_write_AT_ack(tech_pvt, &quot;AT+CKPD=\&quot;EEE\&quot;&quot;);
+          if (res) {
+            ERRORA
+              (&quot;AT+CKPD=\&quot;EEE\&quot; (cellphone screen back to user) do not got OK from the phone\n&quot;,
+               SKYPIAX_P_LOG);
</ins><span class="cx">           }
</span><span class="cx">         }
</span><del>-
-        if ((NULL == old-&gt;next) &amp;&amp; (NULL == old-&gt;previous)) {
-          if (option_debug &gt; 1) {
-            DEBUGA_CVM(&quot;FREEING LAST\n&quot;, SKYPIAX_P_LOG);
-          }
-
-          p-&gt;cvm_busmail_outgoing_list = NULL;
-          p-&gt;cvm_busmail_outgoing_list = celliax_serial_list_init_CVM_BUSMAIL(p);
-        }
-
-/*
-      if (option_debug &gt; 1)
-        DEBUGA_CVM(&quot;FREEING TxSeq is %X, RxSeq is %X\n&quot;, SKYPIAX_P_LOG, MsgTxSeqNo, MsgRxSeqNo);
-*/
-
-        free(old);
-
-      } else {
-        ptr = ptr-&gt;previous;
</del><ins>+#endif
</ins><span class="cx">       }
</span><del>-
-    } else {
-      ptr = ptr-&gt;previous;
</del><span class="cx">     }
</span><span class="cx">   }
</span><span class="cx"> 
</span><del>-/*
-  DEBUGA_CVM(&quot;POSTFREE OUTGOING list:\n&quot;, SKYPIAX_P_LOG);
-  celliax_serial_list_print_CVM_BUSMAIL(p, p-&gt;cvm_busmail_outgoing_list);
-*/
-
-  CVM_UNLOCKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
</del><ins>+  UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
+  POPPA_UNLOCKA(&amp;tech_pvt-&gt;controldev_lock);
</ins><span class="cx">   return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-/*!
- * \brief Sends an FBUS2 message or resends it if it was not acknowledged
- * \param p celliax_pvt
- *
- * Called by celliax_serial_read_CVM_BUSMAIL, browse the fbus2_outgoing_list looking for FBUS2 messages to be sent, 
- * or for FBUS2 messages previously sent but not yet acknoledged.
- * (if an outgoing FBUS2 message is not aknowledged by the cellphone in a while,
- * it will be retransmitted)
- *
- * \return 0 on error, 1 otherwise
- */
-int celliax_serial_send_if_time_CVM_BUSMAIL(private_t * tech_pvt)
-{
-  struct cvm_busmail_msg *ptr;
-  struct timeval tv;
-  struct timezone tz;
</del><span class="cx"> 
</span><del>-  gettimeofday(&amp;tv, &amp;tz);
-  ptr = p-&gt;cvm_busmail_outgoing_list;
</del><span class="cx"> 
</span><del>-  if (ptr == NULL) {
-/*    ERRORA(&quot;cvm_busmail_outgoing_list is NULL ?\n&quot;, SKYPIAX_P_LOG); */
-    WARNINGA(&quot;cvm_busmail_outgoing_list is NULL, nothing to send...\n&quot;, SKYPIAX_P_LOG);
-
-/*    return -1; */
-    return 0;
-
-  }
-
-  while (ptr-&gt;next != NULL) {
-    WARNINGA(&quot;cvm_busmail_outgoing_list-&gt;next is not null ?\n&quot;, SKYPIAX_P_LOG);
-    ptr = ptr-&gt;next;            //FIXME what to do?
-  }
-
-  while (ptr-&gt;sent == 0 &amp;&amp; ptr-&gt;acknowledged == 0) {
-    if (ptr-&gt;previous != NULL) {
-      ptr = ptr-&gt;previous;
-    } else
-      break;
-  }
-
-  while (ptr-&gt;sent == 1 &amp;&amp; ptr-&gt;acknowledged == 0) {
-    if (ptr-&gt;previous != NULL) {
-      ptr = ptr-&gt;previous;
-    } else
-      break;
-  }
-
-  if (ptr-&gt;sent == 1 &amp;&amp; ptr-&gt;acknowledged == 1) {
-    if (ptr-&gt;next != NULL) {
-      ptr = ptr-&gt;next;
-    }
-  }
-
-  if (ptr-&gt;sent == 1 &amp;&amp; ptr-&gt;acknowledged == 0 &amp;&amp; ptr-&gt;valid == 1) {
-    if ((tv.tv_sec * 1000 + tv.tv_usec / 1000) &gt;
-        ((ptr-&gt;tv_sec * 1000 + ptr-&gt;tv_usec / 1000) + 1000)) {
-
-      PUSHA_UNLOCKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-      CVM_LOKKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-
-      if (ptr-&gt;sent == 1 &amp;&amp; ptr-&gt;acknowledged == 0 &amp;&amp; ptr-&gt;valid == 1) {    //retest, maybe has been changed?
-        if ((tv.tv_sec * 1000 + tv.tv_usec / 1000) &gt; ((ptr-&gt;tv_sec * 1000 + ptr-&gt;tv_usec / 1000) + 1000)) { //retest, maybe has been changed?
-
-          if (option_debug &gt; 1)
-            DEBUGA_CVM(&quot;RESEND TxSeq=%X, passed %ld ms, sent %d times\n&quot;, SKYPIAX_P_LOG,
-                       ptr-&gt;txseqno,
-                       ((tv.tv_sec * 1000 + tv.tv_usec / 1000) -
-                        (ptr-&gt;tv_sec * 1000 + ptr-&gt;tv_usec / 1000)), ptr-&gt;how_many_sent);
-
-          if (ptr-&gt;how_many_sent &gt; 9) {
-            ERRORA(&quot;RESEND TxSeq=%X, passed %ld ms, sent %d times\n&quot;, SKYPIAX_P_LOG,
-                   ptr-&gt;txseqno,
-                   ((tv.tv_sec * 1000 + tv.tv_usec / 1000) -
-                    (ptr-&gt;tv_sec * 1000 + ptr-&gt;tv_usec / 1000)), ptr-&gt;how_many_sent);
-
-            CVM_UNLOCKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-            return -1;
-          }
-
-          celliax_serial_send_CVM_BUSMAIL(p, ptr-&gt;busmail_msg_len,
-                                          ptr-&gt;busmail_msg_buffer);
-
-          ptr-&gt;tv_sec = tv.tv_sec;
-          ptr-&gt;tv_usec = tv.tv_usec;
-          ptr-&gt;sent = 1;
-          ptr-&gt;how_many_sent++;
-/*
-          if (option_debug &gt; 1) {
-            DEBUGA_CVM(&quot;OUTGOING list:\n&quot;, SKYPIAX_P_LOG);
-            celliax_serial_list_print_CVM_BUSMAIL(p, p-&gt;cvm_busmail_outgoing_list);
-            DEBUGA_CVM(&quot;OUTGOING list END\n&quot;, SKYPIAX_P_LOG);
-          }
-*/
-        }
-      }
-
-      CVM_UNLOCKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-      POPPA_UNLOCKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-    }
-  }
-
-  if (ptr-&gt;sent == 0 &amp;&amp; ptr-&gt;acknowledged == 0 &amp;&amp; ptr-&gt;valid == 1) {
-
-    PUSHA_UNLOCKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-    CVM_LOKKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-
-    if (ptr-&gt;sent == 0 &amp;&amp; ptr-&gt;acknowledged == 0 &amp;&amp; ptr-&gt;valid == 1) {  //retest, maybe has been changed?
-
-      if (option_debug &gt; 1)
-        DEBUGA_CVM(&quot;SENDING 1st TIME TxSeq=%X\n&quot;, SKYPIAX_P_LOG, ptr-&gt;txseqno);
-
-      celliax_serial_send_CVM_BUSMAIL(p, ptr-&gt;busmail_msg_len, ptr-&gt;busmail_msg_buffer);
-
-      ptr-&gt;tv_sec = tv.tv_sec;
-      ptr-&gt;tv_usec = tv.tv_usec;
-      ptr-&gt;sent = 1;
-      ptr-&gt;how_many_sent++;
-/*
-      if (option_debug &gt; 1) {
-        DEBUGA_CVM(&quot;OUTGOING list:\n&quot;, SKYPIAX_P_LOG);
-        celliax_serial_list_print_CVM_BUSMAIL(p, p-&gt;cvm_busmail_outgoing_list);
-        DEBUGA_CVM(&quot;OUTGOING list END\n&quot;, SKYPIAX_P_LOG);        
-      }
-*/
-    }
-
-    CVM_UNLOCKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-    POPPA_UNLOCKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-
-  }
-  return 0;
-}
-
-int celliax_serial_write_CVM_BUSMAIL(private_t * tech_pvt,
-                                     struct cvm_busmail_frame *busmail_frame)
-{
-  unsigned char buffer2[BUSMAIL_MAX_FRAME_LENGTH];
-  int i = 0;
-  int len = 0;
-  unsigned int busmail_len_total = 0;
-
-  busmail_frame-&gt;busmail_sof = BUSMAIL_SOF;
-  busmail_frame-&gt;busmail_crc = 0;
-
-/* because of Rx Tx SEQ HEADER fields problem, update when these fields are filled with correct data
-  busmail_frame-&gt;busmail_crc = (unsigned char)(busmail_frame-&gt;busmail_header + busmail_frame-&gt;busmail_crc);
-*/
-
-  buffer2[BUSMAIL_OFFSET_SOF] = busmail_frame-&gt;busmail_sof;
-  buffer2[BUSMAIL_OFFSET_HEADER] = busmail_frame-&gt;busmail_header;
-
-  if ((buffer2[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_IC_BIT_MASK) ==
-      BUSMAIL_HEADER_INFO_FRAME) {
-    len =
-      BUSMAIL_OFFSET_MAIL_PARAMS + busmail_frame-&gt;busmail_mail_params_buffer_len +
-      sizeof(busmail_frame-&gt;busmail_crc);
-    busmail_len_total =
-      busmail_frame-&gt;busmail_mail_params_buffer_len +
-      sizeof(busmail_frame-&gt;busmail_header)
-      + sizeof(busmail_frame-&gt;busmail_mail_program_id) +
-      sizeof(busmail_frame-&gt;busmail_mail_task_id) + 2;
-
-    if (option_debug &gt; 1)
-      DEBUGA_CVM(&quot;INFO frame to send\n&quot;, SKYPIAX_P_LOG);
-
-    buffer2[BUSMAIL_OFFSET_MAIL_PROGRAM_ID] = busmail_frame-&gt;busmail_mail_program_id;
-    buffer2[BUSMAIL_OFFSET_MAIL_TASK_ID] = busmail_frame-&gt;busmail_mail_task_id;
-    buffer2[BUSMAIL_OFFSET_MAIL_PRIMITIVE_LSB] =
-      busmail_frame-&gt;busmail_mail_primitive[BUSMAIL_MAIL_PRIMITIVE_LSB];
-    buffer2[BUSMAIL_OFFSET_MAIL_PRIMITIVE_MSB] =
-      busmail_frame-&gt;busmail_mail_primitive[BUSMAIL_MAIL_PRIMITIVE_MSB];
-
-    if (busmail_frame-&gt;busmail_mail_params_buffer_len) {
-      memcpy(buffer2 + BUSMAIL_OFFSET_MAIL_PARAMS,
-             busmail_frame-&gt;busmail_mail_params_buffer,
-             busmail_frame-&gt;busmail_mail_params_buffer_len);
-    }
-
-    for (i = 0; i &lt; busmail_frame-&gt;busmail_mail_params_buffer_len; i++) {
-      busmail_frame-&gt;busmail_crc =
-        (unsigned char) (busmail_frame-&gt;busmail_mail_params_buffer[i] +
-                         busmail_frame-&gt;busmail_crc);
-    }
-
-    busmail_frame-&gt;busmail_crc += busmail_frame-&gt;busmail_mail_program_id;
-    busmail_frame-&gt;busmail_crc += busmail_frame-&gt;busmail_mail_task_id;
-    busmail_frame-&gt;busmail_crc +=
-      busmail_frame-&gt;busmail_mail_primitive[BUSMAIL_MAIL_PRIMITIVE_LSB];
-    busmail_frame-&gt;busmail_crc +=
-      busmail_frame-&gt;busmail_mail_primitive[BUSMAIL_MAIL_PRIMITIVE_MSB];
-  } else {
-    busmail_len_total = sizeof(busmail_frame-&gt;busmail_header);
-    len = BUSMAIL_OFFSET_MAIL + sizeof(busmail_frame-&gt;busmail_crc);
-
-    if (option_debug &gt; 1)
-      DEBUGA_CVM(&quot;CTRL frame to send\n&quot;, SKYPIAX_P_LOG);
-  }
-
-/*
-  DEBUGA_CVM(&quot;Its len=%d\n&quot;, SKYPIAX_P_LOG, len);      
-*/
-
-  busmail_frame-&gt;busmail_len[BUSMAIL_LEN_LSB] =
-    (unsigned char) (busmail_len_total &amp; 0xFF);
-  busmail_frame-&gt;busmail_len[BUSMAIL_LEN_MSB] = (unsigned char) (busmail_len_total &gt;&gt; 8);
-  buffer2[BUSMAIL_OFFSET_LEN_MSB] = busmail_frame-&gt;busmail_len[BUSMAIL_LEN_MSB];
-  buffer2[BUSMAIL_OFFSET_LEN_LSB] = busmail_frame-&gt;busmail_len[BUSMAIL_LEN_LSB];
-
-/*
-  buffer2[len-1] = busmail_frame-&gt;busmail_crc;
-*/
-  buffer2[len - 1] = 0xFF;
-
-  if ((buffer2[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_IC_BIT_MASK) ==
-      BUSMAIL_HEADER_INFO_FRAME) {
-    /* if it is INFO frame, queue it */
-
-    /* update TxSeq and RxSeq bits */
-    /* clear TxSeq and RxSeq bits */
-    buffer2[BUSMAIL_OFFSET_HEADER] &amp;=
-      ~(BUSMAIL_HEADER_RXSEQ_MASK | BUSMAIL_HEADER_TXSEQ_MASK);
-
-    buffer2[BUSMAIL_OFFSET_HEADER] |=
-      (p-&gt;busmail_rxseq_cvm_last + 1) &amp; BUSMAIL_HEADER_RXSEQ_MASK;
-
-    p-&gt;busmail_txseq_celliax_last++;
-    p-&gt;busmail_txseq_celliax_last &amp;= 0x07;
-
-    buffer2[BUSMAIL_OFFSET_HEADER] |=
-      ((p-&gt;busmail_txseq_celliax_last) &lt;&lt; 4) &amp; BUSMAIL_HEADER_TXSEQ_MASK;
-
-    /* update CRC */
-    busmail_frame-&gt;busmail_crc += buffer2[BUSMAIL_OFFSET_HEADER];
-    buffer2[len - 1] = busmail_frame-&gt;busmail_crc;
-
-    p-&gt;cvm_busmail_outgoing_list = celliax_serial_list_init_CVM_BUSMAIL(p);
-    p-&gt;cvm_busmail_outgoing_list-&gt;busmail_msg_len = len;
-
-    for (i = 0; i &lt; len; i++) {
-      p-&gt;cvm_busmail_outgoing_list-&gt;busmail_msg_buffer[i] = buffer2[i];
-    }
-
-    if (option_debug &gt; 10) {
-      char debug_buf[1024];
-      char *debug_buf_pos;
-
-      memset(debug_buf, 0, 1024);
-      debug_buf_pos = debug_buf;
-
-      for (i = 0; i &lt; len; i++) {
-        debug_buf_pos += sprintf(debug_buf_pos, &quot;[%.2X] &quot;, buffer2[i]);
-        if (debug_buf_pos &gt; (char *) (&amp;debug_buf + 1000))
-          break;
-      }
-
-      if (option_debug &gt; 1)
-        DEBUGA_CVM(&quot;INFO: %s was prepared to send\n&quot;, SKYPIAX_P_LOG, debug_buf);
-    }
-
-    if (option_debug &gt; 1) {
-      DEBUGA_CVM(&quot;OUTGOING INFO Frame TxSeq is %X, RxSeq is %X\n&quot;, SKYPIAX_P_LOG,
-                 (buffer2[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_TXSEQ_MASK) &gt;&gt; 4,
-                 buffer2[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_RXSEQ_MASK);
-/*
-      DEBUGA_CVM(&quot;OUTGOING list:\n&quot;, SKYPIAX_P_LOG);
-      celliax_serial_list_print_CVM_BUSMAIL(p, p-&gt;cvm_busmail_outgoing_list);
-      DEBUGA_CVM(&quot;OUTGOING list END\n&quot;, SKYPIAX_P_LOG); */
-    }
-    p-&gt;cvm_busmail_outgoing_list-&gt;txseqno =
-      (unsigned char) (buffer2[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_TXSEQ_MASK) &gt;&gt; 4;
-    p-&gt;cvm_busmail_outgoing_list-&gt;valid = 1;    /* ready to send (?) */
-
-  } else {
-    /* if it is CTRL frame, send it straight to the wire */
-    if (BUSMAIL_HEADER_SABM !=
-        (buffer2[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_SABM_MASK)) {
-      /*SABM ctrl frames have no RxSeq bits */
-
-      buffer2[BUSMAIL_OFFSET_HEADER] &amp;= ~BUSMAIL_HEADER_RXSEQ_MASK;
-
-      if (BUSMAIL_HEADER_REJ ==
-          (buffer2[BUSMAIL_OFFSET_HEADER] &amp; BUSMAIL_HEADER_REJ_MASK)) {
-
-        if (option_debug &gt; 1)
-          DEBUGA_CVM(&quot;CTRL REJ frame...\n&quot;, SKYPIAX_P_LOG);
-
-        if (0xFF != p-&gt;busmail_rxseq_cvm_last) {
-          buffer2[BUSMAIL_OFFSET_HEADER] |=
-            (p-&gt;busmail_rxseq_cvm_last + 1) &amp; BUSMAIL_HEADER_RXSEQ_MASK;
-        } else {
-          if (option_debug &gt; 1)
-            DEBUGA_CVM
-              (&quot;Skipping sending REJ, because we just cleared RxSeq counter, and probably it was a packet that is invalid now...\n&quot;,
-               SKYPIAX_P_LOG);
-          return 0;
-        }
-
-      } else {
-        buffer2[BUSMAIL_OFFSET_HEADER] |=
-          (p-&gt;busmail_rxseq_cvm_last + 1) &amp; BUSMAIL_HEADER_RXSEQ_MASK;
-      }
-    }
-
-    /* update CRC */
-    busmail_frame-&gt;busmail_crc += buffer2[BUSMAIL_OFFSET_HEADER];
-    buffer2[len - 1] = busmail_frame-&gt;busmail_crc;
-
-    if (option_debug &gt; 10) {
-      char debug_buf[1024];
-      char *debug_buf_pos;
-
-      memset(debug_buf, 0, 1024);
-      debug_buf_pos = debug_buf;
-
-      for (i = 0; i &lt; len; i++) {
-        debug_buf_pos += sprintf(debug_buf_pos, &quot;[%.2X] &quot;, buffer2[i]);
-        if (debug_buf_pos &gt; (char *) (&amp;debug_buf + 1000))
-          break;
-      }
-
-      if (option_debug &gt; 1)
-        DEBUGA_CVM(&quot;CTRL: %s was prepared to send\n&quot;, SKYPIAX_P_LOG, debug_buf);
-    }
-//    usleep(100);
-    celliax_serial_send_CVM_BUSMAIL(p, len, buffer2);
-  }
-
-  return 0;
-}
-
-int celliax_serial_send_ctrl_frame_CVM_BUSMAIL(private_t * tech_pvt,
-                                               unsigned char FrameType)
-{
-  /*FrameType parameter is really a busmail header with info neeeded to tell the frame type to send */
-  struct cvm_busmail_frame busmail_frame;
-
-  switch (FrameType &amp; 0xF0) {
-    /* only higher nibble is important for us, do not take PF bit into considration */
-
-  case BUSMAIL_HEADER_CTRL_FRAME | BUSMAIL_HEADER_CTRL_SU_FRAME | BUSMAIL_HEADER_SUID_RR:
-  case BUSMAIL_HEADER_CTRL_FRAME | BUSMAIL_HEADER_CTRL_SU_FRAME | BUSMAIL_HEADER_SUID_REJ:
-  case BUSMAIL_HEADER_CTRL_FRAME | BUSMAIL_HEADER_CTRL_SU_FRAME | BUSMAIL_HEADER_SUID_RNR:
-  case BUSMAIL_HEADER_CTRL_FRAME | BUSMAIL_HEADER_CTRL_UN_FRAME | BUSMAIL_HEADER_UNID_SABM:
-
-    busmail_frame.busmail_header =
-      (FrameType &amp; 0xF8);
-
-    break;
-
-  default:
-    WARNINGA(&quot;UNKNOWN CTRL TYPE specified, sending nothing!!!\n&quot;, SKYPIAX_P_LOG);
-    return -1;
-    break;
-  }
-
-  busmail_frame.busmail_mail_params_buffer_len = 0;
-
-  /* Sending to CVM */
-  return celliax_serial_write_CVM_BUSMAIL(p, &amp;busmail_frame);
-}
-
-int celliax_serial_send_info_frame_CVM_BUSMAIL(private_t * tech_pvt, int FrameType,
-                                               unsigned char ParamsLen,
-                                               unsigned char *Params)
-{
-  /*FrameType parameter is really a Primitive ID */
-  struct cvm_busmail_frame busmail_frame;
-  int i = 0;
-  busmail_frame.busmail_header =
-    (BUSMAIL_HEADER_PF_BIT_MASK &amp; 0xFF) | BUSMAIL_HEADER_INFO_FRAME;
-
-  busmail_frame.busmail_mail_primitive[BUSMAIL_MAIL_PRIMITIVE_LSB] = FrameType &amp; 0xFF;
-  busmail_frame.busmail_mail_primitive[BUSMAIL_MAIL_PRIMITIVE_MSB] =
-    (FrameType &gt;&gt; 8) &amp; 0xFF;
-
-  busmail_frame.busmail_mail_program_id = BUSMAIL_MAIL_PROGRAM_ID;
-  busmail_frame.busmail_mail_task_id = BUSMAIL_MAIL_TASK_ID;
-
-  for (i = 0; i &lt; ParamsLen; i++) {
-    busmail_frame.busmail_mail_params_buffer[i] = Params[i];
-  }
-
-  busmail_frame.busmail_mail_params_buffer_len = ParamsLen;
-
-  /* Sending to CVM */
-  return celliax_serial_write_CVM_BUSMAIL(p, &amp;busmail_frame);
-}
-
-int celliax_serial_lists_free_CVM_BUSMAIL(private_t * tech_pvt)
-{
-  struct cvm_busmail_msg *ptr, *prev;
-/*
-  if (option_debug &gt; 1) {
-    DEBUGA_CVM(&quot;START FREEING OUTGOING\n&quot;, SKYPIAX_P_LOG);
-    DEBUGA_CVM(&quot;OUTGOING list:\n&quot;, SKYPIAX_P_LOG);
-    celliax_serial_list_print_CVM_BUSMAIL(p, p-&gt;cvm_busmail_outgoing_list);
-    DEBUGA_CVM(&quot;OUTGOING list END\n&quot;, SKYPIAX_P_LOG);
-  }
-*/
-  ptr = p-&gt;cvm_busmail_outgoing_list;
-
-  if (ptr) {
-    while (ptr-&gt;next != NULL)
-      ptr = ptr-&gt;next;
-
-    while (ptr-&gt;previous != NULL) {
-
-      if (option_debug &gt; 1)
-        DEBUGA_CVM(&quot;FREED \n&quot;, SKYPIAX_P_LOG);
-
-      prev = ptr-&gt;previous;
-      free(ptr);
-      ptr = prev;
-    }
-
-    free(ptr);
-  }
-
-  if (option_debug &gt; 1)
-    DEBUGA_CVM(&quot;LAST FREED \n&quot;, SKYPIAX_P_LOG);
-
-  p-&gt;cvm_busmail_outgoing_list = NULL;
-  p-&gt;cvm_busmail_outgoing_list = celliax_serial_list_init_CVM_BUSMAIL(p);
-
-  if (option_debug &gt; 1) {
-    DEBUGA_CVM(&quot;OUTGOING list:\n&quot;, SKYPIAX_P_LOG);
-    celliax_serial_list_print_CVM_BUSMAIL(p, p-&gt;cvm_busmail_outgoing_list);
-    DEBUGA_CVM(&quot;OUTGOING list END\n&quot;, SKYPIAX_P_LOG);
-    DEBUGA_CVM(&quot;STARTING FREE INGOING\n&quot;, SKYPIAX_P_LOG);
-  }
-
-  return 0;
-}
-
-struct cvm_busmail_msg *celliax_serial_list_init_CVM_BUSMAIL(private_t * tech_pvt)
-{
-  struct cvm_busmail_msg *list;
-  list = p-&gt;cvm_busmail_outgoing_list;
-
-  PUSHA_UNLOCKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-  CVM_LOKKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-
-  if (list == NULL) {
-    list = malloc(sizeof(*(list)));
-    list-&gt;valid = 0;
-    list-&gt;busmail_msg_len = 0;
-    list-&gt;acknowledged = 0;
-    list-&gt;how_many_sent = 0;
-    list-&gt;sent = 0;
-    list-&gt;tv_sec = 0;
-    list-&gt;tv_usec = 0;
-    list-&gt;next = NULL;
-    list-&gt;previous = NULL;
-  }
-
-  if (list-&gt;valid != 0) {
-    struct cvm_busmail_msg *new;
-    new = malloc(sizeof(*new));
-    new-&gt;valid = 0;
-    new-&gt;busmail_msg_len = 0;
-    new-&gt;acknowledged = 0;
-    new-&gt;how_many_sent = 0;
-    new-&gt;sent = 0;
-    new-&gt;tv_sec = 0;
-    new-&gt;tv_usec = 0;
-    new-&gt;next = NULL;
-    new-&gt;previous = list;
-    list-&gt;next = new;
-    list = new;
-  }
-
-  CVM_UNLOCKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-  POPPA_UNLOCKA(&amp;p-&gt;cvm_busmail_outgoing_list_lock);
-
-  return list;
-}
-
-int celliax_serial_list_print_CVM_BUSMAIL(private_t * tech_pvt,
-                                          struct cvm_busmail_msg *list)
-{
-  struct cvm_busmail_msg *ptr;
-  ptr = list;
-
-  if (ptr) {
-    while (ptr-&gt;next != NULL)
-      ptr = ptr-&gt;next;
-
-    while (ptr) {
-
-      if (option_debug &gt; 3)
-        DEBUGA_CVM
-          (&quot;PTR msg is: %d, seqnum is %.2X, tv_sec is %d, tv_usec is %d, acknowledged is: %d,&quot;
-           &quot; sent is:%d, how_many_sent is: %d\n&quot;, SKYPIAX_P_LOG, ptr-&gt;valid,
-           /*ptr-&gt;seqnum */ 44,
-           ptr-&gt;tv_sec, ptr-&gt;tv_usec, ptr-&gt;acknowledged, ptr-&gt;sent, ptr-&gt;how_many_sent);
-
-      ptr = ptr-&gt;previous;
-    }
-  }
-
-  return 0;
-}
-
-#endif /* CELLIAX_CVM */
-#endif // CELLIAX_ADDITIONAL
-
-
-
</del><ins>+#endif// NOTDEF
</ins></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>