Revision
14676
Author
gmaruzz
Date
2009-08-29 08:24:59 -0500 (Sat, 29 Aug 2009)

Log Message

celliax: indented

Modified Paths

Diff

Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax.h (14675 => 14676)


--- freeswitch/branches/gmaruzz/mod_celliax/celliax.h	2009-08-29 13:15:21 UTC (rev 14675)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax.h	2009-08-29 13:24:59 UTC (rev 14676)
@@ -85,9 +85,9 @@
 
 #define		AT_BUFSIZ 8192
 //FIXME FIXME FIXME #define AT_MESG_MAX_LENGTH 2048 /* much more than 10 SMSs */
-#define AT_MESG_MAX_LENGTH 2048 /* much more than 10 SMSs */
+#define AT_MESG_MAX_LENGTH 2048	/* much more than 10 SMSs */
 //FIXME FIXME FIXME #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 */
-#define AT_MESG_MAX_LINES 20   /* 256 lines, so it can contains the results of AT+CLAC, that gives all the AT commands the phone supports */
+#define AT_MESG_MAX_LINES 20	/* 256 lines, so it can contains the results of AT+CLAC, that gives all the AT commands the phone supports */
 
 //#define SAMPLERATE_SKYPIAX 16000
 //#define SAMPLES_PER_FRAME SAMPLERATE_SKYPIAX/50
@@ -213,13 +213,13 @@
  * \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];
+	int elemcount;
+	char result[AT_MESG_MAX_LINES][AT_MESG_MAX_LENGTH];
 };
 
 struct ciapa_struct {
-int state;
-int hangupcause;
+	int state;
+	int hangupcause;
 };
 typedef struct ciapa_struct ciapa_t;
 
@@ -309,138 +309,138 @@
 	unsigned long ob_failed_calls;
 
 
-  char controldevice_name[50];  /*!< \brief name of the serial device controlling the interface, possibly none */
-  int controldevprotocol;       /*!< \brief which protocol is used for serial control of this interface */
-  char controldevprotocolname[50];  /*!< \brief name of the serial device controlling protocol, one of "at" "fbus2" "no_serial" "alsa_voicemodem" */
-  int controldevfd;             /*!< \brief serial controlling file descriptor for this interface */
-  //pthread_t controldev_thread;  /*!< \brief serial control thread for this interface, running during the call */
-  speed_t controldevice_speed;
-  int controldev_dead;
- 
-  char at_dial_pre_number[64];
-  char at_dial_post_number[64];
-  char at_dial_expect[64];
-  unsigned int at_early_audio;
-  char at_hangup[64];
-  char at_hangup_expect[64];
-  char at_answer[64];
-  char at_answer_expect[64];
-  unsigned int at_initial_pause;
-  char at_preinit_1[64];
-  char at_preinit_1_expect[64];
-  char at_preinit_2[64];
-  char at_preinit_2_expect[64];
-  char at_preinit_3[64];
-  char at_preinit_3_expect[64];
-  char at_preinit_4[64];
-  char at_preinit_4_expect[64];
-  char at_preinit_5[64];
-  char at_preinit_5_expect[64];
-  unsigned int at_after_preinit_pause;
+	char controldevice_name[50];	/*!< \brief name of the serial device controlling the interface, possibly none */
+	int controldevprotocol;		/*!< \brief which protocol is used for serial control of this interface */
+	char controldevprotocolname[50];	/*!< \brief name of the serial device controlling protocol, one of "at" "fbus2" "no_serial" "alsa_voicemodem" */
+	int controldevfd;			/*!< \brief serial controlling file descriptor for this interface */
+	//pthread_t controldev_thread;  /*!< \brief serial control thread for this interface, running during the call */
+	speed_t controldevice_speed;
+	int controldev_dead;
 
-  char at_postinit_1[64];
-  char at_postinit_1_expect[64];
-  char at_postinit_2[64];
-  char at_postinit_2_expect[64];
-  char at_postinit_3[64];
-  char at_postinit_3_expect[64];
-  char at_postinit_4[64];
-  char at_postinit_4_expect[64];
-  char at_postinit_5[64];
-  char at_postinit_5_expect[64];
+	char at_dial_pre_number[64];
+	char at_dial_post_number[64];
+	char at_dial_expect[64];
+	unsigned int at_early_audio;
+	char at_hangup[64];
+	char at_hangup_expect[64];
+	char at_answer[64];
+	char at_answer_expect[64];
+	unsigned int at_initial_pause;
+	char at_preinit_1[64];
+	char at_preinit_1_expect[64];
+	char at_preinit_2[64];
+	char at_preinit_2_expect[64];
+	char at_preinit_3[64];
+	char at_preinit_3_expect[64];
+	char at_preinit_4[64];
+	char at_preinit_4_expect[64];
+	char at_preinit_5[64];
+	char at_preinit_5_expect[64];
+	unsigned int at_after_preinit_pause;
 
-  char at_send_dtmf[64];
+	char at_postinit_1[64];
+	char at_postinit_1_expect[64];
+	char at_postinit_2[64];
+	char at_postinit_2_expect[64];
+	char at_postinit_3[64];
+	char at_postinit_3_expect[64];
+	char at_postinit_4[64];
+	char at_postinit_4_expect[64];
+	char at_postinit_5[64];
+	char at_postinit_5_expect[64];
 
-  char at_query_battchg[64];
-  char at_query_battchg_expect[64];
-  char at_query_signal[64];
-  char at_query_signal_expect[64];
-  char at_call_idle[64];
-  char at_call_incoming[64];
-  char at_call_active[64];
-  char at_call_failed[64];
-  char at_call_calling[64];
+	char at_send_dtmf[64];
 
+	char at_query_battchg[64];
+	char at_query_battchg_expect[64];
+	char at_query_signal[64];
+	char at_query_signal_expect[64];
+	char at_call_idle[64];
+	char at_call_incoming[64];
+	char at_call_active[64];
+	char at_call_failed[64];
+	char at_call_calling[64];
+
 #define CIEV_STRING_SIZE 64
-  char at_indicator_noservice_string[64];
-  char at_indicator_nosignal_string[64];
-  char at_indicator_lowsignal_string[64];
-  char at_indicator_lowbattchg_string[64];
-  char at_indicator_nobattchg_string[64];
-  char at_indicator_callactive_string[64];
-  char at_indicator_nocallactive_string[64];
-  char at_indicator_nocallsetup_string[64];
-  char at_indicator_callsetupincoming_string[64];
-  char at_indicator_callsetupoutgoing_string[64];
-  char at_indicator_callsetupremoteringing_string[64];
+	char at_indicator_noservice_string[64];
+	char at_indicator_nosignal_string[64];
+	char at_indicator_lowsignal_string[64];
+	char at_indicator_lowbattchg_string[64];
+	char at_indicator_nobattchg_string[64];
+	char at_indicator_callactive_string[64];
+	char at_indicator_nocallactive_string[64];
+	char at_indicator_nocallsetup_string[64];
+	char at_indicator_callsetupincoming_string[64];
+	char at_indicator_callsetupoutgoing_string[64];
+	char at_indicator_callsetupremoteringing_string[64];
 
-  int at_indicator_callp;
-  int at_indicator_callsetupp;
-  int at_indicator_roamp;
-  int at_indicator_battchgp;
-  int at_indicator_servicep;
-  int at_indicator_signalp;
+	int at_indicator_callp;
+	int at_indicator_callsetupp;
+	int at_indicator_roamp;
+	int at_indicator_battchgp;
+	int at_indicator_servicep;
+	int at_indicator_signalp;
 
-  int at_has_clcc;
-  int at_has_ecam;
+	int at_has_clcc;
+	int at_has_ecam;
 
-  char at_cmgw[16];
-  int no_ucs2;
-  time_t celliax_serial_sync_period;
+	char at_cmgw[16];
+	int no_ucs2;
+	time_t celliax_serial_sync_period;
 
-  time_t celliax_serial_synced_timestamp;
-  struct s_result line_array;
+	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];
+	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;           /*!< \brief 'callflow' of the phone interface (as opposed to skype interface) */
-  switch_mutex_t *controldev_lock;
+	struct timeval call_incoming_time;
+	int phone_callflow;			/*!< \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_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;
+	int phonebook_first_entry;
+	int phonebook_last_entry;
+	int phonebook_number_lenght;
+	int phonebook_text_lenght;
+	FILE *phonebook_writing_fp;
 
-  struct timeval ringtime;
-  ciapa_t *owner;
+	struct timeval ringtime;
+	ciapa_t *owner;
 #ifdef CELLIAX_ALSA
-  snd_pcm_t *alsac;             /*!< \brief handle of the ALSA capture audio device */
-  snd_pcm_t *alsap;             /*!< \brief handle of the ALSA playback audio device */
-  char alsacname[50];           /*!< \brief name of the ALSA capture audio device */
-  char alsapname[50];           /*!< \brief name of the ALSA playback audio device */
-  int alsa_period_size;         /*!< \brief ALSA period_size, in byte */
-  int alsa_periods_in_buffer;   /*!< \brief how many periods in ALSA buffer, to calculate buffer_size */
-  unsigned long int alsa_buffer_size;   /*!< \brief ALSA buffer_size, in byte */
-  int alsawrite_filled;
-  int alsa_capture_is_mono;
-  int alsa_play_is_mono;
-  struct pollfd pfd;
-#endif// CELLIAX_ALSA
+	snd_pcm_t *alsac;			/*!< \brief handle of the ALSA capture audio device */
+	snd_pcm_t *alsap;			/*!< \brief handle of the ALSA playback audio device */
+	char alsacname[50];			/*!< \brief name of the ALSA capture audio device */
+	char alsapname[50];			/*!< \brief name of the ALSA playback audio device */
+	int alsa_period_size;		/*!< \brief ALSA period_size, in byte */
+	int alsa_periods_in_buffer;	/*!< \brief how many periods in ALSA buffer, to calculate buffer_size */
+	unsigned long int alsa_buffer_size;	/*!< \brief ALSA buffer_size, in byte */
+	int alsawrite_filled;
+	int alsa_capture_is_mono;
+	int alsa_play_is_mono;
+	struct pollfd pfd;
+#endif							// CELLIAX_ALSA
 
-  time_t audio_play_reset_timestamp;
-  int audio_play_reset_period;
+	time_t audio_play_reset_timestamp;
+	int audio_play_reset_period;
 
-switch_timer_t timer;
-    teletone_dtmf_detect_state_t dtmf_detect;
-  switch_time_t old_dtmf_timestamp;
+	switch_timer_t timer;
+	teletone_dtmf_detect_state_t dtmf_detect;
+	switch_time_t old_dtmf_timestamp;
 
 };
 
 typedef struct private_object private_t;
 
-void *SWITCH_THREAD_FUNC celliax_api_thread_func(switch_thread_t * thread, void *obj);
+void *SWITCH_THREAD_FUNC celliax_api_thread_func(switch_thread_t *thread, void *obj);
 int celliax_audio_read(private_t * tech_pvt);
 int celliax_audio_init(private_t * tech_pvt);
 int celliax_signaling_read(private_t * tech_pvt);
@@ -449,21 +449,21 @@
 int celliax_senddigit(private_t * tech_pvt, char digit);
 
 void *celliax_do_tcp_srv_thread_func(void *obj);
-void *SWITCH_THREAD_FUNC celliax_do_tcp_srv_thread(switch_thread_t * thread, void *obj);
+void *SWITCH_THREAD_FUNC celliax_do_tcp_srv_thread(switch_thread_t *thread, void *obj);
 
 void *celliax_do_tcp_cli_thread_func(void *obj);
-void *SWITCH_THREAD_FUNC celliax_do_tcp_cli_thread(switch_thread_t * thread, void *obj);
+void *SWITCH_THREAD_FUNC celliax_do_tcp_cli_thread(switch_thread_t *thread, void *obj);
 
 void *celliax_do_skypeapi_thread_func(void *obj);
-void *SWITCH_THREAD_FUNC celliax_do_skypeapi_thread(switch_thread_t * thread, void *obj);
+void *SWITCH_THREAD_FUNC celliax_do_skypeapi_thread(switch_thread_t *thread, void *obj);
 int dtmf_received(private_t * tech_pvt, char *value);
 int start_audio_threads(private_t * tech_pvt);
 int new_inbound_channel(private_t * tech_pvt);
 int outbound_channel_answered(private_t * tech_pvt);
 //int celliax_signaling_write(private_t * tech_pvt, char *msg_to_skype);
 #if defined(WIN32) && !defined(__CYGWIN__)
-int celliax_pipe_read(switch_file_t * pipe, short *buf, int howmany);
-int celliax_pipe_write(switch_file_t * pipe, short *buf, int howmany);
+int celliax_pipe_read(switch_file_t *pipe, short *buf, int howmany);
+int celliax_pipe_write(switch_file_t *pipe, short *buf, int howmany);
 /* Visual C do not have strsep ? */
 char *strsep(char **stringp, const char *delim);
 #else
@@ -501,13 +501,9 @@
 int celliax_serial_write_AT_ack(private_t * tech_pvt, const char *data);
 int celliax_serial_write_AT_ack_nocr_longtime(private_t * tech_pvt, const char *data);
 int celliax_serial_write_AT_noack(private_t * tech_pvt, const char *data);
-int celliax_serial_write_AT_expect1(private_t * tech_pvt, const char *data,
-                                    const char *expected_string, int expect_crlf,
-                                    int seconds);
-int celliax_serial_AT_expect(private_t * tech_pvt, const char *expected_string,
-                             int expect_crlf, int seconds);
-int celliax_serial_read_AT(private_t * tech_pvt, int look_for_ack, int timeout_usec,
-                           int timeout_sec, const char *expected_string, int expect_crlf);
+int celliax_serial_write_AT_expect1(private_t * tech_pvt, const char *data, const char *expected_string, int expect_crlf, int seconds);
+int celliax_serial_AT_expect(private_t * tech_pvt, const char *expected_string, int expect_crlf, int seconds);
+int celliax_serial_read_AT(private_t * tech_pvt, int look_for_ack, int timeout_usec, int timeout_sec, const char *expected_string, int expect_crlf);
 int celliax_serial_read(private_t * tech_pvt);
 #ifdef NOTDEF
 int celliax_serial_getstatus(private_t * tech_pvt);
@@ -517,13 +513,11 @@
 int celliax_serial_hangup_AT(private_t * tech_pvt);
 int celliax_serial_call_AT(private_t * tech_pvt, char *dstr);
 int celliax_serial_getstatus_AT(private_t * tech_pvt);
-#endif// NOTDEF
+#endif // NOTDEF
 #define RESULT_FAILURE 0
 #define RESULT_SUCCESS 1
-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);
+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);
 
@@ -531,7 +525,7 @@
 #define POPPA_UNLOCKA(x)    if(option_debug > 100) ERRORA("POPPA_UNLOCKA: %p\n", SKYPIAX_P_LOG, (void *)x);
 //#define LOKKA(x)    if(option_debug > 100) ERRORA("LOKKA: %p\n", SKYPIAX_P_LOG, (void *)x);
 #define LOKKA(x)    switch_mutex_lock(x);
-#define UNLOCKA(x)  switch_mutex_unlock(x);  
+#define UNLOCKA(x)  switch_mutex_unlock(x);
 //#define UNLOCKA(x)    if(option_debug > 100) ERRORA("UNLOCKA: %p\n", SKYPIAX_P_LOG, (void *)x);
 
 #define celliax_queue_control(x, y) ERRORA("celliax_queue_control: %p, %d\n", SKYPIAX_P_LOG, (void *)x, y);
@@ -552,7 +546,7 @@
 int alsa_init(private_t * tech_pvt);
 int alsa_shutdown(private_t * tech_pvt);
 snd_pcm_t *alsa_open_dev(private_t * tech_pvt, snd_pcm_stream_t stream);
-int alsa_write(private_t * tech_pvt, short * data, int datalen);
-int alsa_read(private_t * tech_pvt, short * data, int datalen);
+int alsa_write(private_t * tech_pvt, short *data, int datalen);
+int alsa_read(private_t * tech_pvt, short *data, int datalen);
 
 #endif /* CELLIAX_ALSA */

Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c (14675 => 14676)


--- freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c	2009-08-29 13:15:21 UTC (rev 14675)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c	2009-08-29 13:24:59 UTC (rev 14676)
@@ -17,7 +17,7 @@
 extern int running;
 int celliax_dir_entry_extension = 1;
 
-int option_debug=100;
+int option_debug = 100;
 
 #ifdef NOTDEF
 /*************************************/
@@ -136,8 +136,7 @@
 				} else if (!strncasecmp(message, "ERROR 592 ALTER CALL", 19)) {
 					ERRORA("Skype got ERROR about TRANSFERRING, no problem: |||%s|||\n", SKYPIAX_P_LOG, message);
 				} else if (!strncasecmp(message, "ERROR 559 CALL", 13)) {
-					DEBUGA_SKYPE("Skype got ERROR about a failed action (probably TRYING to HANGUP A CALL), no problem: |||%s|||\n", SKYPIAX_P_LOG,
-								 message);
+					DEBUGA_SKYPE("Skype got ERROR about a failed action (probably TRYING to HANGUP A CALL), no problem: |||%s|||\n", SKYPIAX_P_LOG, message);
 				} else {
 					ERRORA("Skype got ERROR: |||%s|||\n", SKYPIAX_P_LOG, message);
 					tech_pvt->skype_callflow = CALLFLOW_STATUS_FINISHED;
@@ -178,8 +177,7 @@
 				if (!strcasecmp(id, tech_pvt->skype_user)) {
 					tech_pvt->SkypiaxHandles.currentuserhandle = 1;
 					DEBUGA_SKYPE
-						("Skype MSG: message: %s, currentuserhandle: %s, cuh: %s, skype_user: %s!\n",
-						 SKYPIAX_P_LOG, message, obj, id, tech_pvt->skype_user);
+						("Skype MSG: message: %s, currentuserhandle: %s, cuh: %s, skype_user: %s!\n", SKYPIAX_P_LOG, message, obj, id, tech_pvt->skype_user);
 				}
 			}
 			if (!strcasecmp(message, "USER")) {
@@ -496,7 +494,7 @@
 	}							//read_from_pipe
 	return 0;
 }
-#endif// NOTDEF
+#endif // NOTDEF
 
 void *celliax_do_tcp_srv_thread_func(void *obj)
 {
@@ -627,8 +625,7 @@
 								/* send the complete frame through the pipe to our code waiting for incoming audio */
 								howmany = celliax_pipe_write(tech_pvt->audiopipe[1], totalbuf, SAMPLES_PER_FRAME * sizeof(short));
 								if (howmany != SAMPLES_PER_FRAME * sizeof(short)) {
-									ERRORA("howmany is %d, but was expected to be %d\n", SKYPIAX_P_LOG,
-										   howmany, (int) (SAMPLES_PER_FRAME * sizeof(short)));
+									ERRORA("howmany is %d, but was expected to be %d\n", SKYPIAX_P_LOG, howmany, (int) (SAMPLES_PER_FRAME * sizeof(short)));
 								}
 								/* done with the stored half frame */
 								tech_pvt->audiobuf_is_loaded = 0;
@@ -874,7 +871,7 @@
 /* PLATFORM SPECIFIC */
 /***************************/
 #if defined(WIN32) && !defined(__CYGWIN__)
-int celliax_pipe_read(switch_file_t * pipe, short *buf, int howmany)
+int celliax_pipe_read(switch_file_t *pipe, short *buf, int howmany)
 {
 	switch_size_t quantity;
 
@@ -887,7 +884,7 @@
 	return howmany;
 }
 
-int celliax_pipe_write(switch_file_t * pipe, short *buf, int howmany)
+int celliax_pipe_write(switch_file_t *pipe, short *buf, int howmany)
 {
 	switch_size_t quantity;
 
@@ -1189,8 +1186,7 @@
 
 	celliax_sleep(200000);		//0,2 sec
 
-	if (tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIAttach != 0
-		&& tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIDiscover != 0) {
+	if (tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIAttach != 0 && tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIDiscover != 0) {
 		if (win32_Initialize_CreateWindowClass(tech_pvt)) {
 			if (win32_Initialize_CreateMainWindow(tech_pvt)) {
 				if (SendMessage
@@ -1373,1898 +1369,1746 @@
 
 
 
-int celliax_serial_init(private_t *tech_pvt, speed_t controldevice_speed)
+int celliax_serial_init(private_t * tech_pvt, speed_t controldevice_speed)
 {
-  int fd;
-  int rt;
-  struct termios tp;
+	int fd;
+	int rt;
+	struct termios tp;
 
 /* if there is a file descriptor, close it. But it is probably just an old value, so don't check for close success*/
-  fd = tech_pvt->controldevfd;
-  if (fd) {
-    close(fd);
-  }
+	fd = tech_pvt->controldevfd;
+	if (fd) {
+		close(fd);
+	}
 /*  open the serial port */
 #ifdef __CYGWIN__
-  fd = open(tech_pvt->controldevice_name, O_RDWR | O_NOCTTY | O_NONBLOCK);
-  sleep(1);
-  close(fd);
+	fd = open(tech_pvt->controldevice_name, O_RDWR | O_NOCTTY | O_NONBLOCK);
+	sleep(1);
+	close(fd);
 #endif /* __CYGWIN__ */
-  fd = open(tech_pvt->controldevice_name, O_RDWR | O_NOCTTY | O_NONBLOCK);
-  if (fd == -1) {
-    DEBUGA_SKYPE("serial error: %s\n", SKYPIAX_P_LOG, strerror(errno));
-    tech_pvt->controldevfd = fd;
-    return -1;
-  }
+	fd = open(tech_pvt->controldevice_name, O_RDWR | O_NOCTTY | O_NONBLOCK);
+	if (fd == -1) {
+		DEBUGA_SKYPE("serial error: %s\n", SKYPIAX_P_LOG, strerror(errno));
+		tech_pvt->controldevfd = fd;
+		return -1;
+	}
 /*  flush it */
-  rt = tcflush(fd, TCIFLUSH);
-  if (rt == -1) {
-    ERRORA("serial error: %s", SKYPIAX_P_LOG, strerror(errno));
-  }
+	rt = tcflush(fd, TCIFLUSH);
+	if (rt == -1) {
+		ERRORA("serial error: %s", SKYPIAX_P_LOG, strerror(errno));
+	}
 /*  attributes */
-  tp.c_cflag = B0 | CS8 | CLOCAL | CREAD | HUPCL;
-  tp.c_iflag = IGNPAR;
-  tp.c_cflag &= ~CRTSCTS;
-  tp.c_oflag = 0;
-  tp.c_lflag = 0;
-  tp.c_cc[VMIN] = 1;
-  tp.c_cc[VTIME] = 0;
+	tp.c_cflag = B0 | CS8 | CLOCAL | CREAD | HUPCL;
+	tp.c_iflag = IGNPAR;
+	tp.c_cflag &= ~CRTSCTS;
+	tp.c_oflag = 0;
+	tp.c_lflag = 0;
+	tp.c_cc[VMIN] = 1;
+	tp.c_cc[VTIME] = 0;
 /*  set controldevice_speed */
-  rt = cfsetispeed(&tp, tech_pvt->controldevice_speed);
-  if (rt == -1) {
-    ERRORA("serial error: %s, speed was: %d", SKYPIAX_P_LOG, strerror(errno), tech_pvt->controldevice_speed);
-  }
-  rt = cfsetospeed(&tp, tech_pvt->controldevice_speed);
-  if (rt == -1) {
-    ERRORA("serial error: %s", SKYPIAX_P_LOG, strerror(errno));
-  }
+	rt = cfsetispeed(&tp, tech_pvt->controldevice_speed);
+	if (rt == -1) {
+		ERRORA("serial error: %s, speed was: %d", SKYPIAX_P_LOG, strerror(errno), tech_pvt->controldevice_speed);
+	}
+	rt = cfsetospeed(&tp, tech_pvt->controldevice_speed);
+	if (rt == -1) {
+		ERRORA("serial error: %s", SKYPIAX_P_LOG, strerror(errno));
+	}
 /*  set port attributes */
-  if (tcsetattr(fd, TCSADRAIN, &tp) == -1) {
-    ERRORA("serial error: %s", SKYPIAX_P_LOG, strerror(errno));
-  }
-  rt = tcsetattr(fd, TCSANOW, &tp);
-  if (rt == -1) {
-    ERRORA("serial error: %s", SKYPIAX_P_LOG, strerror(errno));
-  }
-  unsigned int status = 0;
+	if (tcsetattr(fd, TCSADRAIN, &tp) == -1) {
+		ERRORA("serial error: %s", SKYPIAX_P_LOG, strerror(errno));
+	}
+	rt = tcsetattr(fd, TCSANOW, &tp);
+	if (rt == -1) {
+		ERRORA("serial error: %s", SKYPIAX_P_LOG, strerror(errno));
+	}
+	unsigned int status = 0;
 #ifndef __CYGWIN__
-  ioctl(fd, TIOCMGET, &status);
-  status |= TIOCM_DTR;          /*  Set DTR high */
-  status &= ~TIOCM_RTS;         /*  Set RTS low */
-  ioctl(fd, TIOCMSET, &status);
-  ioctl(fd, TIOCMGET, &status);
-  unsigned int flags = TIOCM_DTR;
-  ioctl(fd, TIOCMBIS, &flags);
-  flags = TIOCM_RTS;
-  ioctl(fd, TIOCMBIC, &flags);
-  ioctl(fd, TIOCMGET, &status);
+	ioctl(fd, TIOCMGET, &status);
+	status |= TIOCM_DTR;		/*  Set DTR high */
+	status &= ~TIOCM_RTS;		/*  Set RTS low */
+	ioctl(fd, TIOCMSET, &status);
+	ioctl(fd, TIOCMGET, &status);
+	unsigned int flags = TIOCM_DTR;
+	ioctl(fd, TIOCMBIS, &flags);
+	flags = TIOCM_RTS;
+	ioctl(fd, TIOCMBIC, &flags);
+	ioctl(fd, TIOCMGET, &status);
 #else /* __CYGWIN__ */
-  ioctl(fd, TIOCMGET, &status);
-  status |= TIOCM_DTR;          /*  Set DTR high */
-  status &= ~TIOCM_RTS;         /*  Set RTS low */
-  ioctl(fd, TIOCMSET, &status);
+	ioctl(fd, TIOCMGET, &status);
+	status |= TIOCM_DTR;		/*  Set DTR high */
+	status &= ~TIOCM_RTS;		/*  Set RTS low */
+	ioctl(fd, TIOCMSET, &status);
 #endif /* __CYGWIN__ */
-  tech_pvt->controldevfd = fd;
-  DEBUGA_SKYPE("Syncing Serial\n", SKYPIAX_P_LOG);
-  rt = celliax_serial_sync(tech_pvt);
-  if (rt == -1) {
-    ERRORA("Serial init error\n", SKYPIAX_P_LOG);
-    return -1;
-  }
-  return (fd);
+	tech_pvt->controldevfd = fd;
+	DEBUGA_SKYPE("Syncing Serial\n", SKYPIAX_P_LOG);
+	rt = celliax_serial_sync(tech_pvt);
+	if (rt == -1) {
+		ERRORA("Serial init error\n", SKYPIAX_P_LOG);
+		return -1;
+	}
+	return (fd);
 }
 
 int celliax_serial_read(private_t * tech_pvt)
 {
-  if (tech_pvt->controldevprotocol == PROTOCOL_AT)
-    return celliax_serial_read_AT(tech_pvt, 0, 100000, 0, NULL, 1);    // a 10th of a second timeout
+	if (tech_pvt->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->controldevprotocol == PROTOCOL_FBUS2)
-    return celliax_serial_read_FBUS2(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_FBUS2)
+		return celliax_serial_read_FBUS2(tech_pvt);
 #endif /* CELLIAX_FBUS2 */
 #ifdef CELLIAX_CVM
-  if (tech_pvt->controldevprotocol == PROTOCOL_CVM_BUSMAIL)
-    return celliax_serial_read_CVM_BUSMAIL(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_CVM_BUSMAIL)
+		return celliax_serial_read_CVM_BUSMAIL(tech_pvt);
 #endif /* CELLIAX_CVM */
-  return -1;
+	return -1;
 }
 
 
 int celliax_serial_sync(private_t * tech_pvt)
 {
-  if (tech_pvt->controldevprotocol == PROTOCOL_AT)
-    return celliax_serial_sync_AT(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_AT)
+		return celliax_serial_sync_AT(tech_pvt);
 #ifdef CELLIAX_FBUS2
-  if (tech_pvt->controldevprotocol == PROTOCOL_FBUS2)
-    return celliax_serial_sync_FBUS2(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_FBUS2)
+		return celliax_serial_sync_FBUS2(tech_pvt);
 #endif /* CELLIAX_FBUS2 */
 #ifdef CELLIAX_CVM
-  if (tech_pvt->controldevprotocol == PROTOCOL_CVM_BUSMAIL)
-    return celliax_serial_sync_CVM_BUSMAIL(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_CVM_BUSMAIL)
+		return celliax_serial_sync_CVM_BUSMAIL(tech_pvt);
 #endif /* CELLIAX_CVM */
 
-  return -1;
+	return -1;
 }
 
 int celliax_serial_config(private_t * tech_pvt)
 {
-  if (tech_pvt->controldevprotocol == PROTOCOL_AT)
-    return celliax_serial_config_AT(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_AT)
+		return celliax_serial_config_AT(tech_pvt);
 #ifdef CELLIAX_FBUS2
-  if (tech_pvt->controldevprotocol == PROTOCOL_FBUS2)
-    return celliax_serial_config_FBUS2(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_FBUS2)
+		return celliax_serial_config_FBUS2(tech_pvt);
 #endif /* CELLIAX_FBUS2 */
 #ifdef CELLIAX_CVM
-  if (tech_pvt->controldevprotocol == PROTOCOL_CVM_BUSMAIL)
-    return celliax_serial_config_CVM_BUSMAIL(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_CVM_BUSMAIL)
+		return celliax_serial_config_CVM_BUSMAIL(tech_pvt);
 #endif /* CELLIAX_CVM */
-  return -1;
+	return -1;
 }
 
 int celliax_serial_config_AT(private_t * tech_pvt)
 {
-  int res;
+	int res;
 
 /* initial_pause? */
-  if (tech_pvt->at_initial_pause) {
-    DEBUGA_SKYPE("sleeping for %d usec\n", SKYPIAX_P_LOG, tech_pvt->at_initial_pause);
-    usleep(tech_pvt->at_initial_pause);
-  }
+	if (tech_pvt->at_initial_pause) {
+		DEBUGA_SKYPE("sleeping for %d usec\n", SKYPIAX_P_LOG, tech_pvt->at_initial_pause);
+		usleep(tech_pvt->at_initial_pause);
+	}
 
 /* go until first empty preinit string, or last preinit string */
-  while (1) {
+	while (1) {
 
-    if (strlen(tech_pvt->at_preinit_1)) {
-      res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_1, tech_pvt->at_preinit_1_expect);
-      if (res) {
-        DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG,
-                  tech_pvt->at_preinit_1, tech_pvt->at_preinit_1_expect);
-      }
-    } else {
-      break;
-    }
+		if (strlen(tech_pvt->at_preinit_1)) {
+			res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_1, tech_pvt->at_preinit_1_expect);
+			if (res) {
+				DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG, tech_pvt->at_preinit_1, tech_pvt->at_preinit_1_expect);
+			}
+		} else {
+			break;
+		}
 
-    if (strlen(tech_pvt->at_preinit_2)) {
-      res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_2, tech_pvt->at_preinit_2_expect);
-      if (res) {
-        DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG,
-                  tech_pvt->at_preinit_2, tech_pvt->at_preinit_2_expect);
-      }
-    } else {
-      break;
-    }
+		if (strlen(tech_pvt->at_preinit_2)) {
+			res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_2, tech_pvt->at_preinit_2_expect);
+			if (res) {
+				DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG, tech_pvt->at_preinit_2, tech_pvt->at_preinit_2_expect);
+			}
+		} else {
+			break;
+		}
 
-    if (strlen(tech_pvt->at_preinit_3)) {
-      res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_3, tech_pvt->at_preinit_3_expect);
-      if (res) {
-        DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG,
-                  tech_pvt->at_preinit_3, tech_pvt->at_preinit_3_expect);
-      }
-    } else {
-      break;
-    }
+		if (strlen(tech_pvt->at_preinit_3)) {
+			res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_3, tech_pvt->at_preinit_3_expect);
+			if (res) {
+				DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG, tech_pvt->at_preinit_3, tech_pvt->at_preinit_3_expect);
+			}
+		} else {
+			break;
+		}
 
-    if (strlen(tech_pvt->at_preinit_4)) {
-      res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_4, tech_pvt->at_preinit_4_expect);
-      if (res) {
-        DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG,
-                  tech_pvt->at_preinit_4, tech_pvt->at_preinit_4_expect);
-      }
-    } else {
-      break;
-    }
+		if (strlen(tech_pvt->at_preinit_4)) {
+			res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_4, tech_pvt->at_preinit_4_expect);
+			if (res) {
+				DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG, tech_pvt->at_preinit_4, tech_pvt->at_preinit_4_expect);
+			}
+		} else {
+			break;
+		}
 
-    if (strlen(tech_pvt->at_preinit_5)) {
-      res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_5, tech_pvt->at_preinit_5_expect);
-      if (res) {
-        DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG,
-                  tech_pvt->at_preinit_5, tech_pvt->at_preinit_5_expect);
-      }
-    } else {
-      break;
-    }
+		if (strlen(tech_pvt->at_preinit_5)) {
+			res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_5, tech_pvt->at_preinit_5_expect);
+			if (res) {
+				DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG, tech_pvt->at_preinit_5, tech_pvt->at_preinit_5_expect);
+			}
+		} else {
+			break;
+		}
 
-    break;
-  }
+		break;
+	}
 
 /* after_preinit_pause? */
-  if (tech_pvt->at_after_preinit_pause) {
-    DEBUGA_SKYPE("sleeping for %d usec\n", SKYPIAX_P_LOG, tech_pvt->at_after_preinit_pause);
-    usleep(tech_pvt->at_after_preinit_pause);
-  }
+	if (tech_pvt->at_after_preinit_pause) {
+		DEBUGA_SKYPE("sleeping for %d usec\n", SKYPIAX_P_LOG, tech_pvt->at_after_preinit_pause);
+		usleep(tech_pvt->at_after_preinit_pause);
+	}
 
-  /* phone, brother, art you alive? */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT");
-  if (res) {
-    ERRORA("no response to AT\n", SKYPIAX_P_LOG);
-    return -1;
-  }
-  /* for motorola, bring it back to "normal" mode if it happens to be in another mode */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+mode=0");
-  if (res) {
-    DEBUGA_SKYPE("AT+mode=0 does not get OK from the phone. If it is NOT Motorola,"
-              " no problem.\n", SKYPIAX_P_LOG);
-  }
-  usleep(50000);
-  /* for motorola end */
+	/* phone, brother, art you alive? */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT");
+	if (res) {
+		ERRORA("no response to AT\n", SKYPIAX_P_LOG);
+		return -1;
+	}
+	/* for motorola, bring it back to "normal" mode if it happens to be in another mode */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+mode=0");
+	if (res) {
+		DEBUGA_SKYPE("AT+mode=0 does not get OK from the phone. If it is NOT Motorola," " no problem.\n", SKYPIAX_P_LOG);
+	}
+	usleep(50000);
+	/* for motorola end */
 
-  /* reset AT configuration to phone default */
-  res = celliax_serial_write_AT_ack(tech_pvt, "ATZ");
-  if (res) {
-    DEBUGA_SKYPE("ATZ failed\n", SKYPIAX_P_LOG);
-  }
+	/* reset AT configuration to phone default */
+	res = celliax_serial_write_AT_ack(tech_pvt, "ATZ");
+	if (res) {
+		DEBUGA_SKYPE("ATZ failed\n", SKYPIAX_P_LOG);
+	}
 
-  /* disable AT command echo */
-  res = celliax_serial_write_AT_ack(tech_pvt, "ATE0");
-  if (res) {
-    DEBUGA_SKYPE("ATE0 failed\n", SKYPIAX_P_LOG);
-  }
+	/* disable AT command echo */
+	res = celliax_serial_write_AT_ack(tech_pvt, "ATE0");
+	if (res) {
+		DEBUGA_SKYPE("ATE0 failed\n", SKYPIAX_P_LOG);
+	}
 
-  /* disable extended error reporting */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+CMEE=0");
-  if (res) {
-    DEBUGA_SKYPE("AT+CMEE failed\n", SKYPIAX_P_LOG);
-  }
+	/* disable extended error reporting */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+CMEE=0");
+	if (res) {
+		DEBUGA_SKYPE("AT+CMEE failed\n", SKYPIAX_P_LOG);
+	}
 
-  /* various phone manufacturer identifier */
-  char at_command[5];
-  int i;
-  for (i = 0; i < 10; i++) {
-    memset(at_command, 0, sizeof(at_command));
-    sprintf(at_command, "ATI%d", i);
-    res = celliax_serial_write_AT_ack(tech_pvt, at_command);
-    if (res) {
-      DEBUGA_SKYPE("ATI%d command failed, continue\n", SKYPIAX_P_LOG, i);
-    }
-  }
+	/* various phone manufacturer identifier */
+	char at_command[5];
+	int i;
+	for (i = 0; i < 10; i++) {
+		memset(at_command, 0, sizeof(at_command));
+		sprintf(at_command, "ATI%d", i);
+		res = celliax_serial_write_AT_ack(tech_pvt, at_command);
+		if (res) {
+			DEBUGA_SKYPE("ATI%d command failed, continue\n", SKYPIAX_P_LOG, i);
+		}
+	}
 
-  /* phone manufacturer */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+CGMI");
-  if (res) {
-    DEBUGA_SKYPE("AT+CGMI failed\n", SKYPIAX_P_LOG);
-  }
+	/* phone manufacturer */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+CGMI");
+	if (res) {
+		DEBUGA_SKYPE("AT+CGMI failed\n", SKYPIAX_P_LOG);
+	}
 
-  /* phone model */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+CGMM");
-  if (res) {
-    DEBUGA_SKYPE("AT+CGMM failed\n", SKYPIAX_P_LOG);
-  }
+	/* phone model */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+CGMM");
+	if (res) {
+		DEBUGA_SKYPE("AT+CGMM failed\n", SKYPIAX_P_LOG);
+	}
 
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+CGSN");
-  if (res) {
-    DEBUGA_SKYPE("AT+CGSN failed\n", SKYPIAX_P_LOG);
-  }
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+CGSN");
+	if (res) {
+		DEBUGA_SKYPE("AT+CGSN failed\n", SKYPIAX_P_LOG);
+	}
 
 /* this take a lot of time to complete on devices with slow serial link (eg.: 9600bps) */
-  /* signal incoming SMS with a +CMTI unsolicited msg */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+CNMI=3,1,0,0,0");
-  if (res) {
-    DEBUGA_SKYPE("AT+CNMI=3,1,0,0,0 failed, continue\n", SKYPIAX_P_LOG);
-    tech_pvt->sms_cnmi_not_supported = 1;
-    tech_pvt->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(tech_pvt, "AT+CSCA?");
-  if (res) {
-    DEBUGA_SKYPE("AT+CSCA? failed, continue\n", SKYPIAX_P_LOG);
-  }
-  /* what is the Message Format of SMSs? */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+CMGF?");
-  if (res) {
-    DEBUGA_SKYPE("AT+CMGF? failed, continue\n", SKYPIAX_P_LOG);
-  }
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+CMGF=1");    //TODO: support phones that only accept pdu mode
-  if (res) {
-    ERRORA("Error setting SMS sending mode to TEXT on the cellphone\n", SKYPIAX_P_LOG);
-    return RESULT_FAILURE;
-  }
-  /* what is the Charset of SMSs? */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS?");
-  if (res) {
-    DEBUGA_SKYPE("AT+CSCS? failed, continue\n", SKYPIAX_P_LOG);
-  }
+	/* signal incoming SMS with a +CMTI unsolicited msg */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+CNMI=3,1,0,0,0");
+	if (res) {
+		DEBUGA_SKYPE("AT+CNMI=3,1,0,0,0 failed, continue\n", SKYPIAX_P_LOG);
+		tech_pvt->sms_cnmi_not_supported = 1;
+		tech_pvt->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(tech_pvt, "AT+CSCA?");
+	if (res) {
+		DEBUGA_SKYPE("AT+CSCA? failed, continue\n", SKYPIAX_P_LOG);
+	}
+	/* what is the Message Format of SMSs? */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+CMGF?");
+	if (res) {
+		DEBUGA_SKYPE("AT+CMGF? failed, continue\n", SKYPIAX_P_LOG);
+	}
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+CMGF=1");	//TODO: support phones that only accept pdu mode
+	if (res) {
+		ERRORA("Error setting SMS sending mode to TEXT on the cellphone\n", SKYPIAX_P_LOG);
+		return RESULT_FAILURE;
+	}
+	/* what is the Charset of SMSs? */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS?");
+	if (res) {
+		DEBUGA_SKYPE("AT+CSCS? failed, continue\n", SKYPIAX_P_LOG);
+	}
 
-  tech_pvt->no_ucs2 = 0;
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"UCS2\"");
-  if (res) {
-    WARNINGA
-      ("AT+CSCS=\"UCS2\" (set TE messages to ucs2)  do not got OK from the phone, let's try with 'GSM'\n",
-       SKYPIAX_P_LOG);
-    tech_pvt->no_ucs2 = 1;
-  }
+	tech_pvt->no_ucs2 = 0;
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"UCS2\"");
+	if (res) {
+		WARNINGA("AT+CSCS=\"UCS2\" (set TE messages to ucs2)  do not got OK from the phone, let's try with 'GSM'\n", SKYPIAX_P_LOG);
+		tech_pvt->no_ucs2 = 1;
+	}
 
-  if (tech_pvt->no_ucs2) {
-    res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"GSM\"");
-    if (res) {
-      WARNINGA("AT+CSCS=\"GSM\" (set TE messages to GSM)  do not got OK from the phone\n",
-               SKYPIAX_P_LOG);
-    }
-    //res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSMP=17,167,0,16"); //"flash", class 0  sms 7 bit
-    res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSMP=17,167,0,0"); //normal, 7 bit message
-    if (res) {
-      WARNINGA("AT+CSMP do not got OK from the phone, continuing\n", SKYPIAX_P_LOG);
-    }
-  } else {
-    //res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSMP=17,167,0,20"); //"flash", class 0 sms 16 bit unicode
-    res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSMP=17,167,0,8"); //unicode, 16 bit message
-    if (res) {
-      WARNINGA("AT+CSMP do not got OK from the phone, continuing\n", SKYPIAX_P_LOG);
-    }
-  }
+	if (tech_pvt->no_ucs2) {
+		res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"GSM\"");
+		if (res) {
+			WARNINGA("AT+CSCS=\"GSM\" (set TE messages to GSM)  do not got OK from the phone\n", SKYPIAX_P_LOG);
+		}
+		//res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSMP=17,167,0,16"); //"flash", class 0  sms 7 bit
+		res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSMP=17,167,0,0");	//normal, 7 bit message
+		if (res) {
+			WARNINGA("AT+CSMP do not got OK from the phone, continuing\n", SKYPIAX_P_LOG);
+		}
+	} else {
+		//res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSMP=17,167,0,20"); //"flash", class 0 sms 16 bit unicode
+		res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSMP=17,167,0,8");	//unicode, 16 bit message
+		if (res) {
+			WARNINGA("AT+CSMP do not got OK from the phone, continuing\n", SKYPIAX_P_LOG);
+		}
+	}
 
-  /* is the unsolicited reporting of mobile equipment event supported? */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+CMER=?");
-  if (res) {
-    DEBUGA_SKYPE("AT+CMER=? failed, continue\n", 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(tech_pvt, "AT+CMER=3,0,0,1");
-  if (res) {
-    DEBUGA_SKYPE("AT+CMER=? failed, continue\n", SKYPIAX_P_LOG);
-  }
+	/* is the unsolicited reporting of mobile equipment event supported? */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+CMER=?");
+	if (res) {
+		DEBUGA_SKYPE("AT+CMER=? failed, continue\n", 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(tech_pvt, "AT+CMER=3,0,0,1");
+	if (res) {
+		DEBUGA_SKYPE("AT+CMER=? failed, continue\n", SKYPIAX_P_LOG);
+	}
 
-  /* is the solicited reporting of mobile equipment indications supported? */
+	/* is the solicited reporting of mobile equipment indications supported? */
 
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+CIND=?");
-  if (res) {
-    DEBUGA_SKYPE("AT+CIND=? failed, continue\n", SKYPIAX_P_LOG);
-  }
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+CIND=?");
+	if (res) {
+		DEBUGA_SKYPE("AT+CIND=? failed, continue\n", SKYPIAX_P_LOG);
+	}
 
-  /* is the unsolicited reporting of call monitoring supported? sony-ericsson specific */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT*ECAM=?");
-  if (res) {
-    DEBUGA_SKYPE("AT*ECAM=? failed, continue\n", SKYPIAX_P_LOG);
-  }
-  /* enable the unsolicited reporting of call monitoring. sony-ericsson specific */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT*ECAM=1");
-  if (res) {
-    DEBUGA_SKYPE("AT*ECAM=1 failed, continue\n", SKYPIAX_P_LOG);
-    tech_pvt->at_has_ecam = 0;
-  } else {
-    tech_pvt->at_has_ecam = 1;
-  }
+	/* is the unsolicited reporting of call monitoring supported? sony-ericsson specific */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT*ECAM=?");
+	if (res) {
+		DEBUGA_SKYPE("AT*ECAM=? failed, continue\n", SKYPIAX_P_LOG);
+	}
+	/* enable the unsolicited reporting of call monitoring. sony-ericsson specific */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT*ECAM=1");
+	if (res) {
+		DEBUGA_SKYPE("AT*ECAM=1 failed, continue\n", SKYPIAX_P_LOG);
+		tech_pvt->at_has_ecam = 0;
+	} else {
+		tech_pvt->at_has_ecam = 1;
+	}
 
-  /* disable unsolicited signaling of call list */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+CLCC=0");
-  if (res) {
-    DEBUGA_SKYPE("AT+CLCC=0 failed, continue\n", SKYPIAX_P_LOG);
-    tech_pvt->at_has_clcc = 0;
-  } else {
-    tech_pvt->at_has_clcc = 1;
-  }
+	/* disable unsolicited signaling of call list */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+CLCC=0");
+	if (res) {
+		DEBUGA_SKYPE("AT+CLCC=0 failed, continue\n", SKYPIAX_P_LOG);
+		tech_pvt->at_has_clcc = 0;
+	} else {
+		tech_pvt->at_has_clcc = 1;
+	}
 
-  /* give unsolicited caller id when incoming call */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+CLIP=1");
-  if (res) {
-    DEBUGA_SKYPE("AT+CLIP failed, continue\n", SKYPIAX_P_LOG);
-  }
-  /* for motorola */
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT+MCST=1");    /* motorola call control codes
-                                                           (to know when call is disconnected (they
-                                                           don't give you "no carrier") */
-  if (res) {
-    DEBUGA_SKYPE("AT+MCST=1 does not get OK from the phone. If it is NOT Motorola,"
-              " no problem.\n", SKYPIAX_P_LOG);
-  }
-  /* for motorola end */
+	/* give unsolicited caller id when incoming call */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+CLIP=1");
+	if (res) {
+		DEBUGA_SKYPE("AT+CLIP failed, continue\n", SKYPIAX_P_LOG);
+	}
+	/* for motorola */
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT+MCST=1");	/* motorola call control codes
+																   (to know when call is disconnected (they
+																   don't give you "no carrier") */
+	if (res) {
+		DEBUGA_SKYPE("AT+MCST=1 does not get OK from the phone. If it is NOT Motorola," " no problem.\n", SKYPIAX_P_LOG);
+	}
+	/* for motorola end */
 
 /* go until first empty postinit string, or last postinit string */
-  while (1) {
+	while (1) {
 
-    if (strlen(tech_pvt->at_postinit_1)) {
-      res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_1, tech_pvt->at_postinit_1_expect);
-      if (res) {
-        DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG,
-                  tech_pvt->at_postinit_1, tech_pvt->at_postinit_1_expect);
-      }
-    } else {
-      break;
-    }
+		if (strlen(tech_pvt->at_postinit_1)) {
+			res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_1, tech_pvt->at_postinit_1_expect);
+			if (res) {
+				DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG, tech_pvt->at_postinit_1, tech_pvt->at_postinit_1_expect);
+			}
+		} else {
+			break;
+		}
 
-    if (strlen(tech_pvt->at_postinit_2)) {
-      res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_2, tech_pvt->at_postinit_2_expect);
-      if (res) {
-        DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG,
-                  tech_pvt->at_postinit_2, tech_pvt->at_postinit_2_expect);
-      }
-    } else {
-      break;
-    }
+		if (strlen(tech_pvt->at_postinit_2)) {
+			res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_2, tech_pvt->at_postinit_2_expect);
+			if (res) {
+				DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG, tech_pvt->at_postinit_2, tech_pvt->at_postinit_2_expect);
+			}
+		} else {
+			break;
+		}
 
-    if (strlen(tech_pvt->at_postinit_3)) {
-      res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_3, tech_pvt->at_postinit_3_expect);
-      if (res) {
-        DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG,
-                  tech_pvt->at_postinit_3, tech_pvt->at_postinit_3_expect);
-      }
-    } else {
-      break;
-    }
+		if (strlen(tech_pvt->at_postinit_3)) {
+			res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_3, tech_pvt->at_postinit_3_expect);
+			if (res) {
+				DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG, tech_pvt->at_postinit_3, tech_pvt->at_postinit_3_expect);
+			}
+		} else {
+			break;
+		}
 
-    if (strlen(tech_pvt->at_postinit_4)) {
-      res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_4, tech_pvt->at_postinit_4_expect);
-      if (res) {
-        DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG,
-                  tech_pvt->at_postinit_4, tech_pvt->at_postinit_4_expect);
-      }
-    } else {
-      break;
-    }
+		if (strlen(tech_pvt->at_postinit_4)) {
+			res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_4, tech_pvt->at_postinit_4_expect);
+			if (res) {
+				DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG, tech_pvt->at_postinit_4, tech_pvt->at_postinit_4_expect);
+			}
+		} else {
+			break;
+		}
 
-    if (strlen(tech_pvt->at_postinit_5)) {
-      res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_5, tech_pvt->at_postinit_5_expect);
-      if (res) {
-        DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG,
-                  tech_pvt->at_postinit_5, tech_pvt->at_postinit_5_expect);
-      }
-    } else {
-      break;
-    }
+		if (strlen(tech_pvt->at_postinit_5)) {
+			res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_5, tech_pvt->at_postinit_5_expect);
+			if (res) {
+				DEBUGA_SKYPE("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG, tech_pvt->at_postinit_5, tech_pvt->at_postinit_5_expect);
+			}
+		} else {
+			break;
+		}
 
-    break;
-  }
+		break;
+	}
 
-  return 0;
+	return 0;
 }
 
 
 int celliax_serial_sync_AT(private_t * tech_pvt)
 {
-  usleep(10000);                /* 10msec */
-  time(&tech_pvt->celliax_serial_synced_timestamp);
-  return 0;
+	usleep(10000);				/* 10msec */
+	time(&tech_pvt->celliax_serial_synced_timestamp);
+	return 0;
 }
-int celliax_serial_read_AT(private_t * tech_pvt, int look_for_ack, int timeout_usec,
-                           int timeout_sec, const char *expected_string, int expect_crlf)
+int celliax_serial_read_AT(private_t * tech_pvt, int look_for_ack, int timeout_usec, int timeout_sec, const char *expected_string, int expect_crlf)
 {
-  int select_err;
-  int res;
-  fd_set read_fds;
-  struct timeval timeout;
-  char tmp_answer[AT_BUFSIZ];
-  char tmp_answer2[AT_BUFSIZ];
-  char *tmp_answer_ptr;
-  char *last_line_ptr;
-  int i = 0;
-  int read_count = 0;
-  int la_counter = 0;
-  int at_ack = -1;
-  int la_read = 0;
+	int select_err;
+	int res;
+	fd_set read_fds;
+	struct timeval timeout;
+	char tmp_answer[AT_BUFSIZ];
+	char tmp_answer2[AT_BUFSIZ];
+	char *tmp_answer_ptr;
+	char *last_line_ptr;
+	int i = 0;
+	int read_count = 0;
+	int la_counter = 0;
+	int at_ack = -1;
+	int la_read = 0;
 
-  FD_ZERO(&read_fds);
-  FD_SET(tech_pvt->controldevfd, &read_fds);
+	FD_ZERO(&read_fds);
+	FD_SET(tech_pvt->controldevfd, &read_fds);
 
-  //NOTICA (" INSIDE this celliax_serial_device %s \n", SKYPIAX_P_LOG, tech_pvt->controldevice_name);
-  tmp_answer_ptr = tmp_answer;
-  memset(tmp_answer, 0, sizeof(char) * AT_BUFSIZ);
+	//NOTICA (" INSIDE this celliax_serial_device %s \n", SKYPIAX_P_LOG, tech_pvt->controldevice_name);
+	tmp_answer_ptr = tmp_answer;
+	memset(tmp_answer, 0, sizeof(char) * AT_BUFSIZ);
 
-  timeout.tv_sec = timeout_sec;
-  timeout.tv_usec = timeout_usec;
-  PUSHA_UNLOCKA(tech_pvt->controldev_lock);
-  LOKKA(tech_pvt->controldev_lock);
+	timeout.tv_sec = timeout_sec;
+	timeout.tv_usec = timeout_usec;
+	PUSHA_UNLOCKA(tech_pvt->controldev_lock);
+	LOKKA(tech_pvt->controldev_lock);
 
-  while ((select_err = select(tech_pvt->controldevfd + 1, &read_fds, NULL, NULL, &timeout)) > 0) {
-    timeout.tv_sec = timeout_sec;   //reset the timeout, linux modify it
-    timeout.tv_usec = timeout_usec; //reset the timeout, linux modify it
-    read_count =
-      read(tech_pvt->controldevfd, tmp_answer_ptr, AT_BUFSIZ - (tmp_answer_ptr - tmp_answer));
+	while ((select_err = select(tech_pvt->controldevfd + 1, &read_fds, NULL, NULL, &timeout)) > 0) {
+		timeout.tv_sec = timeout_sec;	//reset the timeout, linux modify it
+		timeout.tv_usec = timeout_usec;	//reset the timeout, linux modify it
+		read_count = read(tech_pvt->controldevfd, tmp_answer_ptr, AT_BUFSIZ - (tmp_answer_ptr - tmp_answer));
 
-    if (read_count == 0) {
-      ERRORA
-        ("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",
-         SKYPIAX_P_LOG, tech_pvt->controldevice_name);
-      tech_pvt->controldev_dead = 1;
-      close(tech_pvt->controldevfd);
-      UNLOCKA(tech_pvt->controldev_lock);
-      if (tech_pvt->owner) {
-        tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
-        celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
-      }
-      return -1;
-    }
+		if (read_count == 0) {
+			ERRORA
+				("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",
+				 SKYPIAX_P_LOG, tech_pvt->controldevice_name);
+			tech_pvt->controldev_dead = 1;
+			close(tech_pvt->controldevfd);
+			UNLOCKA(tech_pvt->controldev_lock);
+			if (tech_pvt->owner) {
+				tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
+				celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
+			}
+			return -1;
+		}
 
-    if (option_debug > 90) {
-      //DEBUGA_SKYPE("1 read %d bytes, --|%s|--\n", SKYPIAX_P_LOG, read_count, tmp_answer_ptr);
-      //DEBUGA_SKYPE("2 read %d bytes, --|%s|--\n", SKYPIAX_P_LOG, read_count, tmp_answer);
-    }
-    tmp_answer_ptr = tmp_answer_ptr + read_count;
+		if (option_debug > 90) {
+			//DEBUGA_SKYPE("1 read %d bytes, --|%s|--\n", SKYPIAX_P_LOG, read_count, tmp_answer_ptr);
+			//DEBUGA_SKYPE("2 read %d bytes, --|%s|--\n", SKYPIAX_P_LOG, read_count, tmp_answer);
+		}
+		tmp_answer_ptr = tmp_answer_ptr + read_count;
 
-    char *token_ptr;
+		char *token_ptr;
 
-    la_counter = 0;
-    memset(tmp_answer2, 0, sizeof(char) * AT_BUFSIZ);
-    strcpy(tmp_answer2, tmp_answer);
-    if ((token_ptr = strtok(tmp_answer2, "\n\r"))) {
-      last_line_ptr = token_ptr;
-      strncpy(tech_pvt->line_array.result[la_counter], token_ptr, AT_MESG_MAX_LENGTH);
-      if (strlen(token_ptr) > AT_MESG_MAX_LENGTH) {
-        WARNINGA
-          ("AT mesg longer than buffer, original message was: |%s|, in buffer only: |%s|\n",
-           SKYPIAX_P_LOG, token_ptr, tech_pvt->line_array.result[la_counter]);
-      }
-      la_counter++;
-      while ((token_ptr = strtok(NULL, "\n\r"))) {
-        last_line_ptr = token_ptr;
-        strncpy(tech_pvt->line_array.result[la_counter], token_ptr, AT_MESG_MAX_LENGTH);
-        if (strlen(token_ptr) > AT_MESG_MAX_LENGTH) {
-          WARNINGA
-            ("AT mesg longer than buffer, original message was: |%s|, in buffer only: |%s|\n",
-             SKYPIAX_P_LOG, token_ptr, tech_pvt->line_array.result[la_counter]);
-        }
-        la_counter++;
-      }
-    } else {
-      last_line_ptr = tmp_answer;
-    }
+		la_counter = 0;
+		memset(tmp_answer2, 0, sizeof(char) * AT_BUFSIZ);
+		strcpy(tmp_answer2, tmp_answer);
+		if ((token_ptr = strtok(tmp_answer2, "\n\r"))) {
+			last_line_ptr = token_ptr;
+			strncpy(tech_pvt->line_array.result[la_counter], token_ptr, AT_MESG_MAX_LENGTH);
+			if (strlen(token_ptr) > AT_MESG_MAX_LENGTH) {
+				WARNINGA
+					("AT mesg longer than buffer, original message was: |%s|, in buffer only: |%s|\n",
+					 SKYPIAX_P_LOG, token_ptr, tech_pvt->line_array.result[la_counter]);
+			}
+			la_counter++;
+			while ((token_ptr = strtok(NULL, "\n\r"))) {
+				last_line_ptr = token_ptr;
+				strncpy(tech_pvt->line_array.result[la_counter], token_ptr, AT_MESG_MAX_LENGTH);
+				if (strlen(token_ptr) > AT_MESG_MAX_LENGTH) {
+					WARNINGA
+						("AT mesg longer than buffer, original message was: |%s|, in buffer only: |%s|\n",
+						 SKYPIAX_P_LOG, token_ptr, tech_pvt->line_array.result[la_counter]);
+				}
+				la_counter++;
+			}
+		} else {
+			last_line_ptr = tmp_answer;
+		}
 
-    if (expected_string && !expect_crlf) {
-      DEBUGA_SKYPE
-        ("last_line_ptr=|%s|, expected_string=|%s|, expect_crlf=%d, memcmp(last_line_ptr, expected_string, strlen(expected_string)) = %d\n",
-         SKYPIAX_P_LOG, last_line_ptr, expected_string, expect_crlf, memcmp(last_line_ptr,
-                                                                            expected_string,
-                                                                            strlen
-                                                                            (expected_string)));
-    }
+		if (expected_string && !expect_crlf) {
+			DEBUGA_SKYPE
+				("last_line_ptr=|%s|, expected_string=|%s|, expect_crlf=%d, memcmp(last_line_ptr, expected_string, strlen(expected_string)) = %d\n",
+				 SKYPIAX_P_LOG, last_line_ptr, expected_string, expect_crlf, memcmp(last_line_ptr, expected_string, strlen(expected_string)));
+		}
 
-    if (expected_string && !expect_crlf
-        && !memcmp(last_line_ptr, expected_string, strlen(expected_string))
-      ) {
-      strncpy(tech_pvt->line_array.result[la_counter], last_line_ptr, AT_MESG_MAX_LENGTH);
-      // match expected string -> accept it withtout CRLF
-      la_counter++;
+		if (expected_string && !expect_crlf && !memcmp(last_line_ptr, expected_string, strlen(expected_string))
+			) {
+			strncpy(tech_pvt->line_array.result[la_counter], last_line_ptr, AT_MESG_MAX_LENGTH);
+			// match expected string -> accept it withtout CRLF
+			la_counter++;
 
-    }
-    /* if the last line read was not a complete line, we'll read the rest in the future */
-    else if (tmp_answer[strlen(tmp_answer) - 1] != '\r'
-             && tmp_answer[strlen(tmp_answer) - 1] != '\n')
-      la_counter--;
+		}
+		/* if the last line read was not a complete line, we'll read the rest in the future */
+		else if (tmp_answer[strlen(tmp_answer) - 1] != '\r' && tmp_answer[strlen(tmp_answer) - 1] != '\n')
+			la_counter--;
 
-    /* let's list the complete lines read so far, without re-listing the lines that has yet been listed */
-    if (option_debug > 1) {
-      for (i = la_read; i < la_counter; i++)
-        DEBUGA_SKYPE("Read line %d: |%s|\n", SKYPIAX_P_LOG, i, tech_pvt->line_array.result[i]);
-    }
+		/* let's list the complete lines read so far, without re-listing the lines that has yet been listed */
+		if (option_debug > 1) {
+			for (i = la_read; i < la_counter; i++)
+				DEBUGA_SKYPE("Read line %d: |%s|\n", SKYPIAX_P_LOG, i, tech_pvt->line_array.result[i]);
+		}
 
-    /* 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 */
-    for (i = la_read; i < la_counter; i++) {
+		/* 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 */
+		for (i = la_read; i < la_counter; i++) {
 
-      if ((strcmp(tech_pvt->line_array.result[i], "RING") == 0)) {
-        /* with first RING we wait for callid */
-        gettimeofday(&(tech_pvt->ringtime), NULL);
-        /* give CALLID (+CLIP) a chance, wait for the next RING before answering */
-        if (tech_pvt->phone_callflow == CALLFLOW_INCOMING_RING) {
-          /* we're at the second ring, set the interface state, will be answered by celliax_do_monitor */
-          DEBUGA_SKYPE("|%s| got second RING\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
-          tech_pvt->interface_state = SKYPIAX_STATE_RING;
-        } else {
-          /* we're at the first ring, so there is no CALLID yet thus clean the previous one 
-             just in case we don't receive the caller identification in this new call */
-          memset(tech_pvt->callid_name, 0, sizeof(tech_pvt->callid_name));
-          memset(tech_pvt->callid_number, 0, sizeof(tech_pvt->callid_number));
-          /* only send AT+CLCC? if the device previously reported its support */
-          if (tech_pvt->at_has_clcc != 0) {
-            /* we're at the first ring, try to get CALLID (with +CLCC) */
-            DEBUGA_SKYPE("|%s| got first RING, sending AT+CLCC?\n", SKYPIAX_P_LOG,
-                      tech_pvt->line_array.result[i]);
-            res = celliax_serial_write_AT_noack(tech_pvt, "AT+CLCC?");
-            if (res) {
-              ERRORA("AT+CLCC? (call list) was not correctly sent to the phone\n",
-                     SKYPIAX_P_LOG);
-            }
-          } else {
-            DEBUGA_SKYPE("|%s| got first RING, but not sending AT+CLCC? as this device "
-                      "seems not to support\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
-          }
-        }
-        tech_pvt->phone_callflow = CALLFLOW_INCOMING_RING;
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], "RING") == 0)) {
+				/* with first RING we wait for callid */
+				gettimeofday(&(tech_pvt->ringtime), NULL);
+				/* give CALLID (+CLIP) a chance, wait for the next RING before answering */
+				if (tech_pvt->phone_callflow == CALLFLOW_INCOMING_RING) {
+					/* we're at the second ring, set the interface state, will be answered by celliax_do_monitor */
+					DEBUGA_SKYPE("|%s| got second RING\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+					tech_pvt->interface_state = SKYPIAX_STATE_RING;
+				} else {
+					/* we're at the first ring, so there is no CALLID yet thus clean the previous one 
+					   just in case we don't receive the caller identification in this new call */
+					memset(tech_pvt->callid_name, 0, sizeof(tech_pvt->callid_name));
+					memset(tech_pvt->callid_number, 0, sizeof(tech_pvt->callid_number));
+					/* only send AT+CLCC? if the device previously reported its support */
+					if (tech_pvt->at_has_clcc != 0) {
+						/* we're at the first ring, try to get CALLID (with +CLCC) */
+						DEBUGA_SKYPE("|%s| got first RING, sending AT+CLCC?\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+						res = celliax_serial_write_AT_noack(tech_pvt, "AT+CLCC?");
+						if (res) {
+							ERRORA("AT+CLCC? (call list) was not correctly sent to the phone\n", SKYPIAX_P_LOG);
+						}
+					} else {
+						DEBUGA_SKYPE("|%s| got first RING, but not sending AT+CLCC? as this device "
+									 "seems not to support\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+					}
+				}
+				tech_pvt->phone_callflow = CALLFLOW_INCOMING_RING;
+			}
 
-      if ((strncmp(tech_pvt->line_array.result[i], "+CLCC", 5) == 0)) {
-        /* with clcc we wait for clip */
-        memset(tech_pvt->callid_name, 0, sizeof(tech_pvt->callid_name));
-        memset(tech_pvt->callid_number, 0, sizeof(tech_pvt->callid_number));
-        int commacount = 0;
-        int a = 0;
-        int b = 0;
-        int c = 0;
+			if ((strncmp(tech_pvt->line_array.result[i], "+CLCC", 5) == 0)) {
+				/* with clcc we wait for clip */
+				memset(tech_pvt->callid_name, 0, sizeof(tech_pvt->callid_name));
+				memset(tech_pvt->callid_number, 0, sizeof(tech_pvt->callid_number));
+				int commacount = 0;
+				int a = 0;
+				int b = 0;
+				int c = 0;
 
-        for (a = 0; a < strlen(tech_pvt->line_array.result[i]); a++) {
+				for (a = 0; a < strlen(tech_pvt->line_array.result[i]); a++) {
 
-          if (tech_pvt->line_array.result[i][a] == ',') {
-            commacount++;
-          }
-          if (commacount == 5) {
-            if (tech_pvt->line_array.result[i][a] != ',' && tech_pvt->line_array.result[i][a] != '"') {
-              tech_pvt->callid_number[b] = tech_pvt->line_array.result[i][a];
-              b++;
-            }
-          }
-          if (commacount == 7) {
-            if (tech_pvt->line_array.result[i][a] != ',' && tech_pvt->line_array.result[i][a] != '"') {
-              tech_pvt->callid_name[c] = tech_pvt->line_array.result[i][a];
-              c++;
-            }
-          }
-        }
+					if (tech_pvt->line_array.result[i][a] == ',') {
+						commacount++;
+					}
+					if (commacount == 5) {
+						if (tech_pvt->line_array.result[i][a] != ',' && tech_pvt->line_array.result[i][a] != '"') {
+							tech_pvt->callid_number[b] = tech_pvt->line_array.result[i][a];
+							b++;
+						}
+					}
+					if (commacount == 7) {
+						if (tech_pvt->line_array.result[i][a] != ',' && tech_pvt->line_array.result[i][a] != '"') {
+							tech_pvt->callid_name[c] = tech_pvt->line_array.result[i][a];
+							c++;
+						}
+					}
+				}
 
-        tech_pvt->phone_callflow = CALLFLOW_INCOMING_RING;
-        DEBUGA_SKYPE("|%s| CLCC CALLID: name is %s, number is %s\n", SKYPIAX_P_LOG,
-                  tech_pvt->line_array.result[i],
-                  tech_pvt->callid_name[0] ? tech_pvt->callid_name : "not available",
-                  tech_pvt->callid_number[0] ? tech_pvt->callid_number : "not available");
-      }
+				tech_pvt->phone_callflow = CALLFLOW_INCOMING_RING;
+				DEBUGA_SKYPE("|%s| CLCC CALLID: name is %s, number is %s\n", SKYPIAX_P_LOG,
+							 tech_pvt->line_array.result[i],
+							 tech_pvt->callid_name[0] ? tech_pvt->callid_name : "not available",
+							 tech_pvt->callid_number[0] ? tech_pvt->callid_number : "not available");
+			}
 
-      if ((strncmp(tech_pvt->line_array.result[i], "+CLIP", 5) == 0)) {
-        /* with CLIP, we want to answer right away */
-        memset(tech_pvt->callid_name, 0, sizeof(tech_pvt->callid_name));
-        memset(tech_pvt->callid_number, 0, sizeof(tech_pvt->callid_number));
+			if ((strncmp(tech_pvt->line_array.result[i], "+CLIP", 5) == 0)) {
+				/* with CLIP, we want to answer right away */
+				memset(tech_pvt->callid_name, 0, sizeof(tech_pvt->callid_name));
+				memset(tech_pvt->callid_number, 0, sizeof(tech_pvt->callid_number));
 
-        int commacount = 0;
-        int a = 0;
-        int b = 0;
-        int c = 0;
+				int commacount = 0;
+				int a = 0;
+				int b = 0;
+				int c = 0;
 
-        for (a = 7; a < strlen(tech_pvt->line_array.result[i]); a++) {
-          if (tech_pvt->line_array.result[i][a] == ',') {
-            commacount++;
-          }
-          if (commacount == 0) {
-            if (tech_pvt->line_array.result[i][a] != ',' && tech_pvt->line_array.result[i][a] != '"') {
-              tech_pvt->callid_number[b] = tech_pvt->line_array.result[i][a];
-              b++;
-            }
-          }
-          if (commacount == 4) {
-            if (tech_pvt->line_array.result[i][a] != ',' && tech_pvt->line_array.result[i][a] != '"') {
-              tech_pvt->callid_name[c] = tech_pvt->line_array.result[i][a];
-              c++;
-            }
-          }
-        }
+				for (a = 7; a < strlen(tech_pvt->line_array.result[i]); a++) {
+					if (tech_pvt->line_array.result[i][a] == ',') {
+						commacount++;
+					}
+					if (commacount == 0) {
+						if (tech_pvt->line_array.result[i][a] != ',' && tech_pvt->line_array.result[i][a] != '"') {
+							tech_pvt->callid_number[b] = tech_pvt->line_array.result[i][a];
+							b++;
+						}
+					}
+					if (commacount == 4) {
+						if (tech_pvt->line_array.result[i][a] != ',' && tech_pvt->line_array.result[i][a] != '"') {
+							tech_pvt->callid_name[c] = tech_pvt->line_array.result[i][a];
+							c++;
+						}
+					}
+				}
 
-        if (tech_pvt->interface_state != SKYPIAX_STATE_RING) {
-          gettimeofday(&(tech_pvt->call_incoming_time), NULL);
-          DEBUGA_SKYPE("SKYPIAX_STATE_RING call_incoming_time.tv_sec=%ld\n",
-                    SKYPIAX_P_LOG, tech_pvt->call_incoming_time.tv_sec);
+				if (tech_pvt->interface_state != SKYPIAX_STATE_RING) {
+					gettimeofday(&(tech_pvt->call_incoming_time), NULL);
+					DEBUGA_SKYPE("SKYPIAX_STATE_RING call_incoming_time.tv_sec=%ld\n", SKYPIAX_P_LOG, tech_pvt->call_incoming_time.tv_sec);
 
-        }
+				}
 
-        tech_pvt->interface_state = SKYPIAX_STATE_RING;
-        tech_pvt->phone_callflow = CALLFLOW_INCOMING_RING;
-        DEBUGA_SKYPE("|%s| CLIP INCOMING CALLID: name is %s, number is %s\n", SKYPIAX_P_LOG,
-                  tech_pvt->line_array.result[i],
-                  tech_pvt->callid_name[0] != 1 ? tech_pvt->callid_name : "not available",
-                  tech_pvt->callid_number[0] ? tech_pvt->callid_number : "not available");
-      }
+				tech_pvt->interface_state = SKYPIAX_STATE_RING;
+				tech_pvt->phone_callflow = CALLFLOW_INCOMING_RING;
+				DEBUGA_SKYPE("|%s| CLIP INCOMING CALLID: name is %s, number is %s\n", SKYPIAX_P_LOG,
+							 tech_pvt->line_array.result[i],
+							 tech_pvt->callid_name[0] != 1 ? tech_pvt->callid_name : "not available",
+							 tech_pvt->callid_number[0] ? tech_pvt->callid_number : "not available");
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], "BUSY") == 0)) {
-        tech_pvt->phone_callflow = CALLFLOW_CALL_LINEBUSY;
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| CALLFLOW_CALL_LINEBUSY\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-        if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
-          ast_setstate(tech_pvt->owner, SKYPIAX_STATE_BUSY);
-          celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_BUSY);
-        } else {
-          ERRORA("Why BUSY now?\n", SKYPIAX_P_LOG);
-        }
-      }
-      if ((strcmp(tech_pvt->line_array.result[i], "NO ANSWER") == 0)) {
-        tech_pvt->phone_callflow = CALLFLOW_CALL_NOANSWER;
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| CALLFLOW_CALL_NOANSWER\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-        if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
-          tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_NO_ANSWER;
-          celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
-        } else {
-          ERRORA("Why NO ANSWER now?\n", SKYPIAX_P_LOG);
-        }
-      }
-      if ((strcmp(tech_pvt->line_array.result[i], "NO CARRIER") == 0)) {
-        tech_pvt->phone_callflow = CALLFLOW_CALL_NOCARRIER;
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| CALLFLOW_CALL_NOCARRIER\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-        if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN) {
-			//cicopet
-		celliax_hangup(tech_pvt);
-          //tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
-          //celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
-        } else {
-          ERRORA("Why NO CARRIER now?\n", SKYPIAX_P_LOG);
-        }
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], "BUSY") == 0)) {
+				tech_pvt->phone_callflow = CALLFLOW_CALL_LINEBUSY;
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| CALLFLOW_CALL_LINEBUSY\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
+					ast_setstate(tech_pvt->owner, SKYPIAX_STATE_BUSY);
+					celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_BUSY);
+				} else {
+					ERRORA("Why BUSY now?\n", SKYPIAX_P_LOG);
+				}
+			}
+			if ((strcmp(tech_pvt->line_array.result[i], "NO ANSWER") == 0)) {
+				tech_pvt->phone_callflow = CALLFLOW_CALL_NOANSWER;
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| CALLFLOW_CALL_NOANSWER\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
+					tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_NO_ANSWER;
+					celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
+				} else {
+					ERRORA("Why NO ANSWER now?\n", SKYPIAX_P_LOG);
+				}
+			}
+			if ((strcmp(tech_pvt->line_array.result[i], "NO CARRIER") == 0)) {
+				tech_pvt->phone_callflow = CALLFLOW_CALL_NOCARRIER;
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| CALLFLOW_CALL_NOCARRIER\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN) {
+					//cicopet
+					celliax_hangup(tech_pvt);
+					//tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
+					//celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
+				} else {
+					ERRORA("Why NO CARRIER now?\n", SKYPIAX_P_LOG);
+				}
+			}
 
-      if ((strncmp(tech_pvt->line_array.result[i], "+CBC:", 5) == 0)) {
-        int power_supply, battery_strenght, err;
+			if ((strncmp(tech_pvt->line_array.result[i], "+CBC:", 5) == 0)) {
+				int power_supply, battery_strenght, err;
 
-        power_supply = battery_strenght = 0;
+				power_supply = battery_strenght = 0;
 
-        err =
-          sscanf(&tech_pvt->line_array.result[i][6], "%d,%d", &power_supply, &battery_strenght);
-        if (err < 2) {
-          DEBUGA_SKYPE("|%s| is not formatted as: |+CBC: xx,yy| now trying  |+CBC:xx,yy|\n",
-                    SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				err = sscanf(&tech_pvt->line_array.result[i][6], "%d,%d", &power_supply, &battery_strenght);
+				if (err < 2) {
+					DEBUGA_SKYPE("|%s| is not formatted as: |+CBC: xx,yy| now trying  |+CBC:xx,yy|\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
 
-          err =
-            sscanf(&tech_pvt->line_array.result[i][5], "%d,%d", &power_supply,
-                   &battery_strenght);
-          DEBUGA_SKYPE("|%s| +CBC: Powered by %s, battery strenght=%d\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i], power_supply ? "power supply" : "battery",
-                    battery_strenght);
+					err = sscanf(&tech_pvt->line_array.result[i][5], "%d,%d", &power_supply, &battery_strenght);
+					DEBUGA_SKYPE("|%s| +CBC: Powered by %s, battery strenght=%d\n", SKYPIAX_P_LOG,
+								 tech_pvt->line_array.result[i], power_supply ? "power supply" : "battery", battery_strenght);
 
-        }
+				}
 
-        if (err < 2) {
-          DEBUGA_SKYPE("|%s| is not formatted as: |+CBC:xx,yy| giving up\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-        }
+				if (err < 2) {
+					DEBUGA_SKYPE("|%s| is not formatted as: |+CBC:xx,yy| giving up\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				}
 
-        else {
-          if (option_debug > 1)
-            DEBUGA_SKYPE("|%s| +CBC: Powered by %s, battery strenght=%d\n", SKYPIAX_P_LOG,
-                      tech_pvt->line_array.result[i], power_supply ? "power supply" : "battery",
-                      battery_strenght);
-          if (!power_supply) {
-            if (battery_strenght < 10) {
-              ERRORA("|%s| BATTERY ALMOST EXHAUSTED\n", SKYPIAX_P_LOG,
-                     tech_pvt->line_array.result[i]);
-            } else if (battery_strenght < 20) {
-              WARNINGA("|%s| BATTERY LOW\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				else {
+					if (option_debug > 1)
+						DEBUGA_SKYPE("|%s| +CBC: Powered by %s, battery strenght=%d\n", SKYPIAX_P_LOG,
+									 tech_pvt->line_array.result[i], power_supply ? "power supply" : "battery", battery_strenght);
+					if (!power_supply) {
+						if (battery_strenght < 10) {
+							ERRORA("|%s| BATTERY ALMOST EXHAUSTED\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+						} else if (battery_strenght < 20) {
+							WARNINGA("|%s| BATTERY LOW\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
 
-            }
+						}
 
-          }
-        }
+					}
+				}
 
-      }
+			}
 
-      if ((strncmp(tech_pvt->line_array.result[i], "+CSQ:", 5) == 0)) {
-        int signal_quality, ber, err;
+			if ((strncmp(tech_pvt->line_array.result[i], "+CSQ:", 5) == 0)) {
+				int signal_quality, ber, err;
 
-        signal_quality = ber = 0;
+				signal_quality = ber = 0;
 
-        err = sscanf(&tech_pvt->line_array.result[i][6], "%d,%d", &signal_quality, &ber);
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| +CSQ: Signal Quality: %d, Error Rate=%d\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i], signal_quality, ber);
-        if (err < 2) {
-          ERRORA("|%s| is not formatted as: |+CSQ: xx,yy|\n", SKYPIAX_P_LOG,
-                 tech_pvt->line_array.result[i]);
-        } else {
-          if (signal_quality < 11 || signal_quality == 99) {
-            WARNINGA
-              ("|%s| CELLPHONE GETS ALMOST NO SIGNAL, consider to move it or additional antenna\n",
-               SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
-          } else if (signal_quality < 15) {
-            WARNINGA("|%s| CELLPHONE GETS SIGNAL LOW\n", SKYPIAX_P_LOG,
-                     tech_pvt->line_array.result[i]);
+				err = sscanf(&tech_pvt->line_array.result[i][6], "%d,%d", &signal_quality, &ber);
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| +CSQ: Signal Quality: %d, Error Rate=%d\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i], signal_quality, ber);
+				if (err < 2) {
+					ERRORA("|%s| is not formatted as: |+CSQ: xx,yy|\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				} else {
+					if (signal_quality < 11 || signal_quality == 99) {
+						WARNINGA
+							("|%s| CELLPHONE GETS ALMOST NO SIGNAL, consider to move it or additional antenna\n",
+							 SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+					} else if (signal_quality < 15) {
+						WARNINGA("|%s| CELLPHONE GETS SIGNAL LOW\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
 
-          }
+					}
 
-        }
+				}
 
-      }
-      if ((strncmp(tech_pvt->line_array.result[i], "+CMGW:", 6) == 0)) {
-        int err;
+			}
+			if ((strncmp(tech_pvt->line_array.result[i], "+CMGW:", 6) == 0)) {
+				int err;
 
-        err = sscanf(&tech_pvt->line_array.result[i][7], "%s", tech_pvt->at_cmgw);
-        DEBUGA_SKYPE("|%s| +CMGW: %s\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i], tech_pvt->at_cmgw);
-        if (err < 1) {
-          ERRORA("|%s| is not formatted as: |+CMGW: xxxx|\n", SKYPIAX_P_LOG,
-                 tech_pvt->line_array.result[i]);
-        }
+				err = sscanf(&tech_pvt->line_array.result[i][7], "%s", tech_pvt->at_cmgw);
+				DEBUGA_SKYPE("|%s| +CMGW: %s\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i], tech_pvt->at_cmgw);
+				if (err < 1) {
+					ERRORA("|%s| is not formatted as: |+CMGW: xxxx|\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				}
 
-      }
+			}
 
-      /* at_call_* are unsolicited messages sent by the modem to signal us about call processing activity and events */
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_call_idle) == 0)) {
-        tech_pvt->phone_callflow = CALLFLOW_CALL_IDLE;
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| CALLFLOW_CALL_IDLE\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
-        if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
-          DEBUGA_SKYPE("just received a remote HANGUP\n", SKYPIAX_P_LOG);
-          tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_NORMAL;
-          celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
-          DEBUGA_SKYPE("just sent SKYPIAX_CONTROL_HANGUP\n", SKYPIAX_P_LOG);
-        }
-      }
+			/* at_call_* are unsolicited messages sent by the modem to signal us about call processing activity and events */
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_call_idle) == 0)) {
+				tech_pvt->phone_callflow = CALLFLOW_CALL_IDLE;
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| CALLFLOW_CALL_IDLE\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
+					DEBUGA_SKYPE("just received a remote HANGUP\n", SKYPIAX_P_LOG);
+					tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_NORMAL;
+					celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
+					DEBUGA_SKYPE("just sent SKYPIAX_CONTROL_HANGUP\n", SKYPIAX_P_LOG);
+				}
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_call_incoming) == 0)) {
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_call_incoming) == 0)) {
 
-        //char list_command[64];
+				//char list_command[64];
 
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| CALLFLOW_CALL_INCOMING\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| CALLFLOW_CALL_INCOMING\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
 
-        if (tech_pvt->phone_callflow != CALLFLOW_CALL_INCOMING
-            && tech_pvt->phone_callflow != CALLFLOW_INCOMING_RING) {
-          //mark the time of CALLFLOW_CALL_INCOMING
-          gettimeofday(&(tech_pvt->call_incoming_time), NULL);
-          tech_pvt->phone_callflow = CALLFLOW_CALL_INCOMING;
-          DEBUGA_SKYPE("CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld\n",
-                    SKYPIAX_P_LOG, tech_pvt->call_incoming_time.tv_sec);
+				if (tech_pvt->phone_callflow != CALLFLOW_CALL_INCOMING && tech_pvt->phone_callflow != CALLFLOW_INCOMING_RING) {
+					//mark the time of CALLFLOW_CALL_INCOMING
+					gettimeofday(&(tech_pvt->call_incoming_time), NULL);
+					tech_pvt->phone_callflow = CALLFLOW_CALL_INCOMING;
+					DEBUGA_SKYPE("CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld\n", SKYPIAX_P_LOG, tech_pvt->call_incoming_time.tv_sec);
 
-        }
-      }
+				}
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_call_active) == 0)) {
-	      tech_pvt->phone_callflow = CALLFLOW_CALL_ACTIVE;
-	      DEBUGA_SKYPE("|%s| CALLFLOW_CALL_ACTIVE\n", SKYPIAX_P_LOG,
-			      tech_pvt->line_array.result[i]);
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_call_active) == 0)) {
+				tech_pvt->phone_callflow = CALLFLOW_CALL_ACTIVE;
+				DEBUGA_SKYPE("|%s| CALLFLOW_CALL_ACTIVE\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
 
-	      if (tech_pvt->interface_state == CALLFLOW_CALL_DIALING) {
-		      DEBUGA_PBX("just received a remote ANSWER\n", SKYPIAX_P_LOG);
-		      if (tech_pvt->phone_callflow == SKYPIAX_STATE_UP) {
-			      //celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_RINGING);
-			      DEBUGA_PBX("just sent SKYPIAX_CONTROL_RINGING\n", SKYPIAX_P_LOG);
-			      DEBUGA_PBX("going to send SKYPIAX_CONTROL_ANSWER\n", SKYPIAX_P_LOG);
-			      //celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_ANSWER);
-			      tech_pvt->interface_state = CALLFLOW_CALL_REMOTEANSWER;
-			      DEBUGA_PBX("just sent SKYPIAX_CONTROL_ANSWER\n", SKYPIAX_P_LOG);
-		      }
-	      } else {
-	      }
-	      //tech_pvt->interface_state = SKYPIAX_STATE_UP;
-	      //DEBUGA_PBX("just interface_state UP\n", SKYPIAX_P_LOG);
-      }
+				if (tech_pvt->interface_state == CALLFLOW_CALL_DIALING) {
+					DEBUGA_PBX("just received a remote ANSWER\n", SKYPIAX_P_LOG);
+					if (tech_pvt->phone_callflow == SKYPIAX_STATE_UP) {
+						//celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_RINGING);
+						DEBUGA_PBX("just sent SKYPIAX_CONTROL_RINGING\n", SKYPIAX_P_LOG);
+						DEBUGA_PBX("going to send SKYPIAX_CONTROL_ANSWER\n", SKYPIAX_P_LOG);
+						//celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_ANSWER);
+						tech_pvt->interface_state = CALLFLOW_CALL_REMOTEANSWER;
+						DEBUGA_PBX("just sent SKYPIAX_CONTROL_ANSWER\n", SKYPIAX_P_LOG);
+					}
+				} else {
+				}
+				//tech_pvt->interface_state = SKYPIAX_STATE_UP;
+				//DEBUGA_PBX("just interface_state UP\n", SKYPIAX_P_LOG);
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_call_calling) == 0)) {
-        tech_pvt->phone_callflow = CALLFLOW_CALL_DIALING;
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| CALLFLOW_CALL_DIALING\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      }
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_call_failed) == 0)) {
-        tech_pvt->phone_callflow = CALLFLOW_CALL_FAILED;
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| CALLFLOW_CALL_FAILED\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-        if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
-          tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
-          celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
-        }
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_call_calling) == 0)) {
+				tech_pvt->phone_callflow = CALLFLOW_CALL_DIALING;
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| CALLFLOW_CALL_DIALING\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_call_failed) == 0)) {
+				tech_pvt->phone_callflow = CALLFLOW_CALL_FAILED;
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| CALLFLOW_CALL_FAILED\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
+					tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
+					celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
+				}
+			}
 
-      if ((strncmp(tech_pvt->line_array.result[i], "+CSCA:", 6) == 0)) {   //TODO SMS FIXME in config!
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| +CSCA: Message Center Address!\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      }
+			if ((strncmp(tech_pvt->line_array.result[i], "+CSCA:", 6) == 0)) {	//TODO SMS FIXME in config!
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| +CSCA: Message Center Address!\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-      if ((strncmp(tech_pvt->line_array.result[i], "+CMGF:", 6) == 0)) {   //TODO SMS FIXME in config!
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| +CMGF: Message Format!\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      }
+			if ((strncmp(tech_pvt->line_array.result[i], "+CMGF:", 6) == 0)) {	//TODO SMS FIXME in config!
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| +CMGF: Message Format!\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-      if ((strncmp(tech_pvt->line_array.result[i], "+CMTI:", 6) == 0)) {   //TODO SMS FIXME in config!
-        int err;
-        int pos;
+			if ((strncmp(tech_pvt->line_array.result[i], "+CMTI:", 6) == 0)) {	//TODO SMS FIXME in config!
+				int err;
+				int pos;
 
-        //FIXME all the following commands in config!
-        if (option_debug)
-          DEBUGA_SKYPE("|%s| +CMTI: Incoming SMS!\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
+				//FIXME all the following commands in config!
+				if (option_debug)
+					DEBUGA_SKYPE("|%s| +CMTI: Incoming SMS!\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
 
-        err = sscanf(&tech_pvt->line_array.result[i][12], "%d", &pos);
-        if (err < 1) {
-          ERRORA("|%s| is not formatted as: |+CMTI: \"MT\",xx|\n", SKYPIAX_P_LOG,
-                 tech_pvt->line_array.result[i]);
-        } else {
-          DEBUGA_SKYPE("|%s| +CMTI: Incoming SMS in position: %d!\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i], pos);
-          tech_pvt->unread_sms_msg_id = pos;
-          usleep(1000);
+				err = sscanf(&tech_pvt->line_array.result[i][12], "%d", &pos);
+				if (err < 1) {
+					ERRORA("|%s| is not formatted as: |+CMTI: \"MT\",xx|\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				} else {
+					DEBUGA_SKYPE("|%s| +CMTI: Incoming SMS in position: %d!\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i], pos);
+					tech_pvt->unread_sms_msg_id = pos;
+					usleep(1000);
 
-          if (tech_pvt->unread_sms_msg_id) {
-            char at_command[256];
+					if (tech_pvt->unread_sms_msg_id) {
+						char at_command[256];
 
-            if (tech_pvt->no_ucs2 == 0) {
-              res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"UCS2\"");
-              if (res) {
-                ERRORA
-                  ("AT+CSCS=\"UCS2\" (set TE messages to ucs2)  do not got OK from the phone, continuing\n",
-                   SKYPIAX_P_LOG);
-                //memset(tech_pvt->sms_message, 0, sizeof(tech_pvt->sms_message));
-              }
-            }
+						if (tech_pvt->no_ucs2 == 0) {
+							res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"UCS2\"");
+							if (res) {
+								ERRORA("AT+CSCS=\"UCS2\" (set TE messages to ucs2)  do not got OK from the phone, continuing\n", SKYPIAX_P_LOG);
+								//memset(tech_pvt->sms_message, 0, sizeof(tech_pvt->sms_message));
+							}
+						}
 
-            memset(at_command, 0, sizeof(at_command));
-            sprintf(at_command, "AT+CMGR=%d", tech_pvt->unread_sms_msg_id);
-            memset(tech_pvt->sms_message, 0, sizeof(tech_pvt->sms_message));
+						memset(at_command, 0, sizeof(at_command));
+						sprintf(at_command, "AT+CMGR=%d", tech_pvt->unread_sms_msg_id);
+						memset(tech_pvt->sms_message, 0, sizeof(tech_pvt->sms_message));
 
-            tech_pvt->reading_sms_msg = 1;
-            res = celliax_serial_write_AT_ack(tech_pvt, at_command);
-            tech_pvt->reading_sms_msg = 0;
-            if (res) {
-              ERRORA
-                ("AT+CMGR (read SMS) do not got OK from the phone, message sent was:|||%s|||\n",
-                 SKYPIAX_P_LOG, at_command);
-            }
-            res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"GSM\"");
-            if (res) {
-              ERRORA
-                ("AT+CSCS=\"GSM\" (set TE messages to GSM) do not got OK from the phone\n",
-                 SKYPIAX_P_LOG);
-            }
-            memset(at_command, 0, sizeof(at_command));
-            sprintf(at_command, "AT+CMGD=%d", tech_pvt->unread_sms_msg_id);    /* delete the message */
-            tech_pvt->unread_sms_msg_id = 0;
-            res = celliax_serial_write_AT_ack(tech_pvt, at_command);
-            if (res) {
-              ERRORA
-                ("AT+CMGD (Delete SMS) do not got OK from the phone, message sent was:|||%s|||\n",
-                 SKYPIAX_P_LOG, at_command);
-            }
+						tech_pvt->reading_sms_msg = 1;
+						res = celliax_serial_write_AT_ack(tech_pvt, at_command);
+						tech_pvt->reading_sms_msg = 0;
+						if (res) {
+							ERRORA("AT+CMGR (read SMS) do not got OK from the phone, message sent was:|||%s|||\n", SKYPIAX_P_LOG, at_command);
+						}
+						res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"GSM\"");
+						if (res) {
+							ERRORA("AT+CSCS=\"GSM\" (set TE messages to GSM) do not got OK from the phone\n", SKYPIAX_P_LOG);
+						}
+						memset(at_command, 0, sizeof(at_command));
+						sprintf(at_command, "AT+CMGD=%d", tech_pvt->unread_sms_msg_id);	/* delete the message */
+						tech_pvt->unread_sms_msg_id = 0;
+						res = celliax_serial_write_AT_ack(tech_pvt, at_command);
+						if (res) {
+							ERRORA("AT+CMGD (Delete SMS) do not got OK from the phone, message sent was:|||%s|||\n", SKYPIAX_P_LOG, at_command);
+						}
 
-            if (strlen(tech_pvt->sms_message)) {
-              //FIXME manager_event(EVENT_FLAG_SYSTEM, "CELLIAXincomingsms",
-                            //FIXME "Interface: %s\r\nSMS_Message: %s\r\n", tech_pvt->name,
-                            //FIXME tech_pvt->sms_message);
-              if (strlen(tech_pvt->sms_receiving_program)) {
-                int fd1[2];
-                pid_t pid1;
-                char *arg1[] = { tech_pvt->sms_receiving_program, (char *) NULL };
-                int i;
+						if (strlen(tech_pvt->sms_message)) {
+							//FIXME manager_event(EVENT_FLAG_SYSTEM, "CELLIAXincomingsms",
+							//FIXME "Interface: %s\r\nSMS_Message: %s\r\n", tech_pvt->name,
+							//FIXME tech_pvt->sms_message);
+							if (strlen(tech_pvt->sms_receiving_program)) {
+								int fd1[2];
+								pid_t pid1;
+								char *arg1[] = { tech_pvt->sms_receiving_program, (char *) NULL };
+								int i;
 
-                NOTICA("incoming SMS message:>>>%s<<<\n", SKYPIAX_P_LOG, tech_pvt->sms_message);
-                pipe(fd1);
-                pid1 = fork();
+								NOTICA("incoming SMS message:>>>%s<<<\n", SKYPIAX_P_LOG, tech_pvt->sms_message);
+								pipe(fd1);
+								pid1 = fork();
 
-                if (pid1 == 0) {    //child
-                  int err;
+								if (pid1 == 0) {	//child
+									int err;
 
-                  dup2(fd1[0], 0);  // Connect stdin to pipe output
-                  close(fd1[1]);    // close input pipe side
-		close(tech_pvt->controldevfd);
-                  setsid();     //session id
-                  err = execvp(arg1[0], arg1);  //exec our program, with stdin connected to pipe output
-                  if (err) {
-                    ERRORA
-                      ("'sms_receiving_program' is set in config file to '%s', and it gave us back this error: %d, (%s). SMS received was:---%s---\n",
-                       SKYPIAX_P_LOG, tech_pvt->sms_receiving_program, err, strerror(errno),
-                       tech_pvt->sms_message);
-                  }
-                  close(fd1[0]);    // close output pipe side
-                }
+									dup2(fd1[0], 0);	// Connect stdin to pipe output
+									close(fd1[1]);	// close input pipe side
+									close(tech_pvt->controldevfd);
+									setsid();	//session id
+									err = execvp(arg1[0], arg1);	//exec our program, with stdin connected to pipe output
+									if (err) {
+										ERRORA
+											("'sms_receiving_program' is set in config file to '%s', and it gave us back this error: %d, (%s). SMS received was:---%s---\n",
+											 SKYPIAX_P_LOG, tech_pvt->sms_receiving_program, err, strerror(errno), tech_pvt->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 < strlen(tech_pvt->sms_message); i++) {
-                  write(fd1[1], &tech_pvt->sms_message[i], 1);
-                }
-                close(fd1[1]);  // close pipe input, let our program know we've finished
-              } else {
-                ERRORA
-                  ("got SMS incoming message, but 'sms_receiving_program' is not set in config file. SMS received was:---%s---\n",
-                   SKYPIAX_P_LOG, tech_pvt->sms_message);
-              }
-            }
-#if 1                           //is this one needed? maybe it can interrupt an incoming call that is just to announce itself
-            if (tech_pvt->phone_callflow == CALLFLOW_CALL_IDLE
-                && tech_pvt->interface_state == SKYPIAX_STATE_DOWN && tech_pvt->owner == NULL) {
-              /* we're not in a call, neither calling */
-              res = celliax_serial_write_AT_ack(tech_pvt, "AT+CKPD=\"EEE\"");
-              if (res) {
-                ERRORA
-                  ("AT+CKPD=\"EEE\" (cellphone screen back to user) do not got OK from the phone\n",
-                   SKYPIAX_P_LOG);
-              }
-            }
+								close(fd1[0]);	// close output pipe side
+								// write the msg on the pipe input
+								for (i = 0; i < strlen(tech_pvt->sms_message); i++) {
+									write(fd1[1], &tech_pvt->sms_message[i], 1);
+								}
+								close(fd1[1]);	// close pipe input, let our program know we've finished
+							} else {
+								ERRORA
+									("got SMS incoming message, but 'sms_receiving_program' is not set in config file. SMS received was:---%s---\n",
+									 SKYPIAX_P_LOG, tech_pvt->sms_message);
+							}
+						}
+#if 1							//is this one needed? maybe it can interrupt an incoming call that is just to announce itself
+						if (tech_pvt->phone_callflow == CALLFLOW_CALL_IDLE && tech_pvt->interface_state == SKYPIAX_STATE_DOWN && tech_pvt->owner == NULL) {
+							/* we're not in a call, neither calling */
+							res = celliax_serial_write_AT_ack(tech_pvt, "AT+CKPD=\"EEE\"");
+							if (res) {
+								ERRORA("AT+CKPD=\"EEE\" (cellphone screen back to user) do not got OK from the phone\n", SKYPIAX_P_LOG);
+							}
+						}
 #endif
-          }                     //unread_msg_id
+					}			//unread_msg_id
 
-        }                       //CMTI well formatted
+				}				//CMTI well formatted
 
-      }                         //CMTI
+			}					//CMTI
 
-      if ((strncmp(tech_pvt->line_array.result[i], "+MMGL:", 6) == 0)) {   //TODO MOTOROLA SMS FIXME in config!
-        int err = 0;
-        //int unread_msg_id=0;
+			if ((strncmp(tech_pvt->line_array.result[i], "+MMGL:", 6) == 0)) {	//TODO MOTOROLA SMS FIXME in config!
+				int err = 0;
+				//int unread_msg_id=0;
 
-        if (option_debug)
-          DEBUGA_SKYPE("|%s| +MMGL: Listing Motorola SMSs!\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
+				if (option_debug)
+					DEBUGA_SKYPE("|%s| +MMGL: Listing Motorola SMSs!\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
 
-        err = sscanf(&tech_pvt->line_array.result[i][7], "%d", &tech_pvt->unread_sms_msg_id);
-        if (err < 1) {
-          ERRORA("|%s| is not formatted as: |+MMGL: xx|\n", SKYPIAX_P_LOG,
-                 tech_pvt->line_array.result[i]);
-        }
-      }
-      if ((strncmp(tech_pvt->line_array.result[i], "+CMGL:", 6) == 0)) {   //TODO  SMS FIXME in config!
-        if (option_debug)
-          DEBUGA_SKYPE("|%s| +CMGL: Listing SMSs!\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      }
-      if ((strncmp(tech_pvt->line_array.result[i], "+MMGR:", 6) == 0)) {   //TODO MOTOROLA SMS FIXME in config!
-        if (option_debug)
-          DEBUGA_SKYPE("|%s| +MMGR: Reading Motorola SMS!\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-        if (tech_pvt->reading_sms_msg)
-          tech_pvt->reading_sms_msg++;
-      }
-      if ((strncmp(tech_pvt->line_array.result[i], "+CMGR: \"STO U", 13) == 0)) {  //TODO  SMS FIXME in config!
-        if (option_debug)
-          DEBUGA_SKYPE("|%s| +CMGR: Reading stored UNSENT SMS!\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      } else if ((strncmp(tech_pvt->line_array.result[i], "+CMGR: \"STO S", 13) == 0)) {   //TODO  SMS FIXME in config!
-        if (option_debug)
-          DEBUGA_SKYPE("|%s| +CMGR: Reading stored SENT SMS!\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      } else if ((strncmp(tech_pvt->line_array.result[i], "+CMGR: \"REC R", 13) == 0)) {   //TODO  SMS FIXME in config!
-        if (option_debug)
-          DEBUGA_SKYPE("|%s| +CMGR: Reading received READ SMS!\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      } else if ((strncmp(tech_pvt->line_array.result[i], "+CMGR: \"REC U", 13) == 0)) {   //TODO  SMS FIXME in config!
-        if (option_debug)
-          DEBUGA_SKYPE("|%s| +CMGR: Reading received UNREAD SMS!\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-        if (tech_pvt->reading_sms_msg)
-          tech_pvt->reading_sms_msg++;
-      }
+				err = sscanf(&tech_pvt->line_array.result[i][7], "%d", &tech_pvt->unread_sms_msg_id);
+				if (err < 1) {
+					ERRORA("|%s| is not formatted as: |+MMGL: xx|\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				}
+			}
+			if ((strncmp(tech_pvt->line_array.result[i], "+CMGL:", 6) == 0)) {	//TODO  SMS FIXME in config!
+				if (option_debug)
+					DEBUGA_SKYPE("|%s| +CMGL: Listing SMSs!\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
+			if ((strncmp(tech_pvt->line_array.result[i], "+MMGR:", 6) == 0)) {	//TODO MOTOROLA SMS FIXME in config!
+				if (option_debug)
+					DEBUGA_SKYPE("|%s| +MMGR: Reading Motorola SMS!\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				if (tech_pvt->reading_sms_msg)
+					tech_pvt->reading_sms_msg++;
+			}
+			if ((strncmp(tech_pvt->line_array.result[i], "+CMGR: \"STO U", 13) == 0)) {	//TODO  SMS FIXME in config!
+				if (option_debug)
+					DEBUGA_SKYPE("|%s| +CMGR: Reading stored UNSENT SMS!\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			} else if ((strncmp(tech_pvt->line_array.result[i], "+CMGR: \"STO S", 13) == 0)) {	//TODO  SMS FIXME in config!
+				if (option_debug)
+					DEBUGA_SKYPE("|%s| +CMGR: Reading stored SENT SMS!\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			} else if ((strncmp(tech_pvt->line_array.result[i], "+CMGR: \"REC R", 13) == 0)) {	//TODO  SMS FIXME in config!
+				if (option_debug)
+					DEBUGA_SKYPE("|%s| +CMGR: Reading received READ SMS!\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			} else if ((strncmp(tech_pvt->line_array.result[i], "+CMGR: \"REC U", 13) == 0)) {	//TODO  SMS FIXME in config!
+				if (option_debug)
+					DEBUGA_SKYPE("|%s| +CMGR: Reading received UNREAD SMS!\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				if (tech_pvt->reading_sms_msg)
+					tech_pvt->reading_sms_msg++;
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], "+MCST: 17") == 0)) {    /* motorola call processing unsolicited messages */
-        tech_pvt->phone_callflow = CALLFLOW_CALL_INFLUX;
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| CALLFLOW_CALL_INFLUX\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], "+MCST: 17") == 0)) {	/* motorola call processing unsolicited messages */
+				tech_pvt->phone_callflow = CALLFLOW_CALL_INFLUX;
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| CALLFLOW_CALL_INFLUX\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], "+MCST: 68") == 0)) {    /* motorola call processing unsolicited messages */
-        tech_pvt->phone_callflow = CALLFLOW_CALL_NOSERVICE;
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| CALLFLOW_CALL_NOSERVICE\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-        if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
-          tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
-          celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
-        }
-      }
-      if ((strcmp(tech_pvt->line_array.result[i], "+MCST: 70") == 0)) {    /* motorola call processing unsolicited messages */
-        tech_pvt->phone_callflow = CALLFLOW_CALL_OUTGOINGRESTRICTED;
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| CALLFLOW_CALL_OUTGOINGRESTRICTED\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-        if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
-          tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
-          celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
-        }
-      }
-      if ((strcmp(tech_pvt->line_array.result[i], "+MCST: 72") == 0)) {    /* motorola call processing unsolicited messages */
-        tech_pvt->phone_callflow = CALLFLOW_CALL_SECURITYFAIL;
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| CALLFLOW_CALL_SECURITYFAIL\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-        if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
-          tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
-          celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
-        }
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], "+MCST: 68") == 0)) {	/* motorola call processing unsolicited messages */
+				tech_pvt->phone_callflow = CALLFLOW_CALL_NOSERVICE;
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| CALLFLOW_CALL_NOSERVICE\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
+					tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
+					celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
+				}
+			}
+			if ((strcmp(tech_pvt->line_array.result[i], "+MCST: 70") == 0)) {	/* motorola call processing unsolicited messages */
+				tech_pvt->phone_callflow = CALLFLOW_CALL_OUTGOINGRESTRICTED;
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| CALLFLOW_CALL_OUTGOINGRESTRICTED\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
+					tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
+					celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
+				}
+			}
+			if ((strcmp(tech_pvt->line_array.result[i], "+MCST: 72") == 0)) {	/* motorola call processing unsolicited messages */
+				tech_pvt->phone_callflow = CALLFLOW_CALL_SECURITYFAIL;
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| CALLFLOW_CALL_SECURITYFAIL\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN && tech_pvt->owner) {
+					tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
+					celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
+				}
+			}
 
-      if ((strncmp(tech_pvt->line_array.result[i], "+CPBR", 5) == 0)) {    /* phonebook stuff begins */
+			if ((strncmp(tech_pvt->line_array.result[i], "+CPBR", 5) == 0)) {	/* phonebook stuff begins */
 
-        if (tech_pvt->phonebook_querying) {    /* probably phonebook struct begins */
-          int err, first_entry, last_entry, number_lenght, text_lenght;
+				if (tech_pvt->phonebook_querying) {	/* probably phonebook struct begins */
+					int err, first_entry, last_entry, number_lenght, text_lenght;
 
-          if (option_debug)
-            DEBUGA_SKYPE("phonebook struct: |%s|\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+					if (option_debug)
+						DEBUGA_SKYPE("phonebook struct: |%s|\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
 
-          err =
-            sscanf(&tech_pvt->line_array.result[i][8], "%d-%d),%d,%d", &first_entry, &last_entry,
-                   &number_lenght, &text_lenght);
-          if (err < 4) {
+					err = sscanf(&tech_pvt->line_array.result[i][8], "%d-%d),%d,%d", &first_entry, &last_entry, &number_lenght, &text_lenght);
+					if (err < 4) {
 
-            err =
-              sscanf(&tech_pvt->line_array.result[i][7], "%d-%d,%d,%d", &first_entry,
-                     &last_entry, &number_lenght, &text_lenght);
-          }
+						err = sscanf(&tech_pvt->line_array.result[i][7], "%d-%d,%d,%d", &first_entry, &last_entry, &number_lenght, &text_lenght);
+					}
 
-          if (err < 4) {
-            ERRORA
-              ("phonebook struct: |%s| is nor formatted as: |+CPBR: (1-750),40,14| neither as: |+CPBR: 1-750,40,14|\n",
-               SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
-          } else {
+					if (err < 4) {
+						ERRORA
+							("phonebook struct: |%s| is nor formatted as: |+CPBR: (1-750),40,14| neither as: |+CPBR: 1-750,40,14|\n",
+							 SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+					} else {
 
-            if (option_debug)
-              DEBUGA_SKYPE
-                ("First entry: %d, last entry: %d, phone number max lenght: %d, text max lenght: %d\n",
-                 SKYPIAX_P_LOG, first_entry, last_entry, number_lenght, text_lenght);
-            tech_pvt->phonebook_first_entry = first_entry;
-            tech_pvt->phonebook_last_entry = last_entry;
-            tech_pvt->phonebook_number_lenght = number_lenght;
-            tech_pvt->phonebook_text_lenght = text_lenght;
-          }
+						if (option_debug)
+							DEBUGA_SKYPE
+								("First entry: %d, last entry: %d, phone number max lenght: %d, text max lenght: %d\n",
+								 SKYPIAX_P_LOG, first_entry, last_entry, number_lenght, text_lenght);
+						tech_pvt->phonebook_first_entry = first_entry;
+						tech_pvt->phonebook_last_entry = last_entry;
+						tech_pvt->phonebook_number_lenght = number_lenght;
+						tech_pvt->phonebook_text_lenght = text_lenght;
+					}
 
-        } else {                /* probably phonebook entry begins */
+				} else {		/* probably phonebook entry begins */
 
-          if (tech_pvt->phonebook_listing) {
-            int err, entry_id, entry_type;
+					if (tech_pvt->phonebook_listing) {
+						int err, entry_id, entry_type;
 
-            char entry_number[256];
-            char entry_text[256];
+						char entry_number[256];
+						char entry_text[256];
 
-            if (option_debug)
-              DEBUGA_SKYPE("phonebook entry: |%s|\n", SKYPIAX_P_LOG,
-                        tech_pvt->line_array.result[i]);
+						if (option_debug)
+							DEBUGA_SKYPE("phonebook entry: |%s|\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
 
-            err =
-              sscanf(&tech_pvt->line_array.result[i][7], "%d,\"%255[0-9+]\",%d,\"%255[^\"]\"",
-                     &entry_id, entry_number, &entry_type, entry_text);
-            if (err < 4) {
-              ERRORA
-                ("err=%d, phonebook entry: |%s| is not formatted as: |+CPBR: 504,\"+39025458068\",145,\"ciao a tutti\"|\n",
-                 SKYPIAX_P_LOG, err, tech_pvt->line_array.result[i]);
-            } else {
-              //TODO: sanitize entry_text
-              if (option_debug)
-                DEBUGA_SKYPE("Number: %s, Text: %s, Type: %d\n", SKYPIAX_P_LOG, entry_number,
-                          entry_text, entry_type);
-              /* write entry in phonebook file */
-              if (tech_pvt->phonebook_writing_fp) {
-                celliax_dir_entry_extension++;
+						err =
+							sscanf(&tech_pvt->line_array.result[i][7], "%d,\"%255[0-9+]\",%d,\"%255[^\"]\"", &entry_id, entry_number, &entry_type, entry_text);
+						if (err < 4) {
+							ERRORA
+								("err=%d, phonebook entry: |%s| is not formatted as: |+CPBR: 504,\"+39025458068\",145,\"ciao a tutti\"|\n",
+								 SKYPIAX_P_LOG, err, tech_pvt->line_array.result[i]);
+						} else {
+							//TODO: sanitize entry_text
+							if (option_debug)
+								DEBUGA_SKYPE("Number: %s, Text: %s, Type: %d\n", SKYPIAX_P_LOG, entry_number, entry_text, entry_type);
+							/* write entry in phonebook file */
+							if (tech_pvt->phonebook_writing_fp) {
+								celliax_dir_entry_extension++;
 
-                fprintf(tech_pvt->phonebook_writing_fp,
-                        "%s  => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromcell=%s|phonebook_entry_owner=%s\n",
-                        entry_number, entry_text, "no",
-                        tech_pvt->celliax_dir_entry_extension_prefix, "2",
-                        celliax_dir_entry_extension, "yes", "not_specified");
-                fprintf(tech_pvt->phonebook_writing_fp,
-                        "%s  => ,%sDO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromcell=%s|phonebook_entry_owner=%s\n",
-                        entry_number, entry_text, "no",
-                        tech_pvt->celliax_dir_entry_extension_prefix, "3",
-                        celliax_dir_entry_extension, "yes", "not_specified");
-              }
-            }
+								fprintf(tech_pvt->phonebook_writing_fp,
+										"%s  => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromcell=%s|phonebook_entry_owner=%s\n",
+										entry_number, entry_text, "no",
+										tech_pvt->celliax_dir_entry_extension_prefix, "2", celliax_dir_entry_extension, "yes", "not_specified");
+								fprintf(tech_pvt->phonebook_writing_fp,
+										"%s  => ,%sDO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromcell=%s|phonebook_entry_owner=%s\n",
+										entry_number, entry_text, "no",
+										tech_pvt->celliax_dir_entry_extension_prefix, "3", celliax_dir_entry_extension, "yes", "not_specified");
+							}
+						}
 
-          }
+					}
 
-          if (tech_pvt->phonebook_listing_received_calls) {
-            int err, entry_id, entry_type;
+					if (tech_pvt->phonebook_listing_received_calls) {
+						int err, entry_id, entry_type;
 
-            char entry_number[256] = "";
-            char entry_text[256] = "";
+						char entry_number[256] = "";
+						char entry_text[256] = "";
 
-            if (option_debug)
-              DEBUGA_SKYPE("phonebook entry: |%s|\n", SKYPIAX_P_LOG,
-                        tech_pvt->line_array.result[i]);
+						if (option_debug)
+							DEBUGA_SKYPE("phonebook entry: |%s|\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
 
-            err =
-              sscanf(&tech_pvt->line_array.result[i][7], "%d,\"%255[0-9+]\",%d,\"%255[^\"]\"",
-                     &entry_id, entry_number, &entry_type, entry_text);
-            if (err < 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
-              ERRORA
-                ("err=%d, phonebook entry: |%s| is not formatted as: |+CPBR: 504,\"+39025458068\",145,\"ciao a tutti\"|\n",
-                 SKYPIAX_P_LOG, err, tech_pvt->line_array.result[i]);
-            } else {
-              //TODO: sanitize entry_text
+						err =
+							sscanf(&tech_pvt->line_array.result[i][7], "%d,\"%255[0-9+]\",%d,\"%255[^\"]\"", &entry_id, entry_number, &entry_type, entry_text);
+						if (err < 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
+							ERRORA
+								("err=%d, phonebook entry: |%s| is not formatted as: |+CPBR: 504,\"+39025458068\",145,\"ciao a tutti\"|\n",
+								 SKYPIAX_P_LOG, err, tech_pvt->line_array.result[i]);
+						} else {
+							//TODO: sanitize entry_text
 
-              if (option_debug)
-                DEBUGA_SKYPE("Number: %s, Text: %s, Type: %d\n", SKYPIAX_P_LOG, entry_number,
-                          entry_text, entry_type);
-              memset(tech_pvt->callid_name, 0, sizeof(tech_pvt->callid_name));
-              memset(tech_pvt->callid_number, 0, sizeof(tech_pvt->callid_number));
-              strncpy(tech_pvt->callid_name, entry_text, sizeof(tech_pvt->callid_name));
-              strncpy(tech_pvt->callid_number, entry_number, sizeof(tech_pvt->callid_number));
-              if (option_debug)
-                DEBUGA_SKYPE("incoming callid: Text: %s, Number: %s\n", SKYPIAX_P_LOG,
-                          tech_pvt->callid_name, tech_pvt->callid_number);
+							if (option_debug)
+								DEBUGA_SKYPE("Number: %s, Text: %s, Type: %d\n", SKYPIAX_P_LOG, entry_number, entry_text, entry_type);
+							memset(tech_pvt->callid_name, 0, sizeof(tech_pvt->callid_name));
+							memset(tech_pvt->callid_number, 0, sizeof(tech_pvt->callid_number));
+							strncpy(tech_pvt->callid_name, entry_text, sizeof(tech_pvt->callid_name));
+							strncpy(tech_pvt->callid_number, entry_number, sizeof(tech_pvt->callid_number));
+							if (option_debug)
+								DEBUGA_SKYPE("incoming callid: Text: %s, Number: %s\n", SKYPIAX_P_LOG, tech_pvt->callid_name, tech_pvt->callid_number);
 
-              DEBUGA_SKYPE("|%s| CPBR INCOMING CALLID: name is %s, number is %s\n",
-                        SKYPIAX_P_LOG, tech_pvt->line_array.result[i],
-                        tech_pvt->callid_name[0] != 1 ? tech_pvt->callid_name : "not available",
-                        tech_pvt->callid_number[0] ? tech_pvt->callid_number : "not available");
+							DEBUGA_SKYPE("|%s| CPBR INCOMING CALLID: name is %s, number is %s\n",
+										 SKYPIAX_P_LOG, tech_pvt->line_array.result[i],
+										 tech_pvt->callid_name[0] != 1 ? tech_pvt->callid_name : "not available",
+										 tech_pvt->callid_number[0] ? tech_pvt->callid_number : "not available");
 
-              /* mark the time of RING */
-              gettimeofday(&(tech_pvt->ringtime), NULL);
-              tech_pvt->interface_state = SKYPIAX_STATE_RING;
-              tech_pvt->phone_callflow = CALLFLOW_INCOMING_RING;
+							/* mark the time of RING */
+							gettimeofday(&(tech_pvt->ringtime), NULL);
+							tech_pvt->interface_state = SKYPIAX_STATE_RING;
+							tech_pvt->phone_callflow = CALLFLOW_INCOMING_RING;
 
-            }
+						}
 
-          }
+					}
 
-          else {
-            DEBUGA_SKYPE("phonebook entry: |%s|\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+					else {
+						DEBUGA_SKYPE("phonebook entry: |%s|\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
 
-          }
-        }
+					}
+				}
 
-      }
+			}
 
-      if ((strncmp(tech_pvt->line_array.result[i], "*ECAV", 5) == 0) || (strncmp(tech_pvt->line_array.result[i], "*ECAM", 5) == 0)) { /* sony-ericsson call processing unsolicited messages */
-        int res, ccid, ccstatus, calltype, processid, exitcause, number, type;
-        res = ccid = ccstatus = calltype = processid = exitcause = number = type = 0;
-        res =
-          sscanf(&tech_pvt->line_array.result[i][6], "%d,%d,%d,%d,%d,%d,%d", &ccid, &ccstatus,
-                 &calltype, &processid, &exitcause, &number, &type);
-        /* only changes the phone_callflow if enought parameters were parsed */
-        if (res >= 3) {
-          switch (ccstatus) {
-          case 0:
-            if (tech_pvt->owner) {
-              ast_setstate(tech_pvt->owner, SKYPIAX_STATE_DOWN);
-              tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_NORMAL;
-              celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
-            }
-            tech_pvt->phone_callflow = CALLFLOW_CALL_IDLE;
-            tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-            if (option_debug > 1)
-              DEBUGA_SKYPE("|%s| Sony-Ericsson *ECAM/*ECAV: IDLE\n", SKYPIAX_P_LOG,
-                        tech_pvt->line_array.result[i]);
-            break;
-          case 1:
-            if (option_debug > 1)
-              DEBUGA_SKYPE("|%s| Sony-Ericsson *ECAM/*ECAV: CALLING\n", SKYPIAX_P_LOG,
-                        tech_pvt->line_array.result[i]);
-            break;
-          case 2:
-            if (tech_pvt->owner) {
-              ast_setstate(tech_pvt->owner, SKYPIAX_STATE_DIALING);
-            }
-            tech_pvt->interface_state = CALLFLOW_CALL_DIALING;
-            if (option_debug > 1)
-              DEBUGA_SKYPE("|%s| Sony-Ericsson *ECAM/*ECAV: CONNECTING\n", SKYPIAX_P_LOG,
-                        tech_pvt->line_array.result[i]);
-            break;
-          case 3:
-            if (tech_pvt->owner) {
-              ast_setstate(tech_pvt->owner, SKYPIAX_STATE_UP);
-              celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_ANSWER);
-            }
-            tech_pvt->phone_callflow = CALLFLOW_CALL_ACTIVE;
-            tech_pvt->interface_state = SKYPIAX_STATE_UP;
-            if (option_debug > 1)
-              DEBUGA_SKYPE("|%s| Sony-Ericsson *ECAM/*ECAV: ACTIVE\n", SKYPIAX_P_LOG,
-                        tech_pvt->line_array.result[i]);
-            break;
-          case 4:
-            if (option_debug > 1)
-              DEBUGA_SKYPE
-                ("|%s| Sony-Ericsson *ECAM/*ECAV: don't know how to handle HOLD event\n",
-                 SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
-            break;
-          case 5:
-            if (option_debug > 1)
-              DEBUGA_SKYPE
-                ("|%s| Sony-Ericsson *ECAM/*ECAV: don't know how to handle WAITING event\n",
-                 SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
-            break;
-          case 6:
-            if (option_debug > 1)
-              DEBUGA_SKYPE
-                ("|%s| Sony-Ericsson *ECAM/*ECAV: don't know how to handle ALERTING event\n",
-                 SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
-            break;
-          case 7:
-            if (tech_pvt->owner) {
-              ast_setstate(tech_pvt->owner, SKYPIAX_STATE_BUSY);
-              celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_BUSY);
-            }
-            tech_pvt->phone_callflow = CALLFLOW_CALL_LINEBUSY;
-            tech_pvt->interface_state = SKYPIAX_STATE_BUSY;
-            if (option_debug > 1)
-              DEBUGA_SKYPE("|%s| Sony-Ericsson *ECAM/*ECAV: BUSY\n", SKYPIAX_P_LOG,
-                        tech_pvt->line_array.result[i]);
-            break;
-          }
-        } else {
-          if (option_debug > 1)
-            DEBUGA_SKYPE("|%s| Sony-Ericsson *ECAM/*ECAV: could not parse parameters\n",
-                      SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
-        }
+			if ((strncmp(tech_pvt->line_array.result[i], "*ECAV", 5) == 0) || (strncmp(tech_pvt->line_array.result[i], "*ECAM", 5) == 0)) {	/* sony-ericsson call processing unsolicited messages */
+				int res, ccid, ccstatus, calltype, processid, exitcause, number, type;
+				res = ccid = ccstatus = calltype = processid = exitcause = number = type = 0;
+				res = sscanf(&tech_pvt->line_array.result[i][6], "%d,%d,%d,%d,%d,%d,%d", &ccid, &ccstatus, &calltype, &processid, &exitcause, &number, &type);
+				/* only changes the phone_callflow if enought parameters were parsed */
+				if (res >= 3) {
+					switch (ccstatus) {
+					case 0:
+						if (tech_pvt->owner) {
+							ast_setstate(tech_pvt->owner, SKYPIAX_STATE_DOWN);
+							tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_NORMAL;
+							celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
+						}
+						tech_pvt->phone_callflow = CALLFLOW_CALL_IDLE;
+						tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+						if (option_debug > 1)
+							DEBUGA_SKYPE("|%s| Sony-Ericsson *ECAM/*ECAV: IDLE\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+						break;
+					case 1:
+						if (option_debug > 1)
+							DEBUGA_SKYPE("|%s| Sony-Ericsson *ECAM/*ECAV: CALLING\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+						break;
+					case 2:
+						if (tech_pvt->owner) {
+							ast_setstate(tech_pvt->owner, SKYPIAX_STATE_DIALING);
+						}
+						tech_pvt->interface_state = CALLFLOW_CALL_DIALING;
+						if (option_debug > 1)
+							DEBUGA_SKYPE("|%s| Sony-Ericsson *ECAM/*ECAV: CONNECTING\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+						break;
+					case 3:
+						if (tech_pvt->owner) {
+							ast_setstate(tech_pvt->owner, SKYPIAX_STATE_UP);
+							celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_ANSWER);
+						}
+						tech_pvt->phone_callflow = CALLFLOW_CALL_ACTIVE;
+						tech_pvt->interface_state = SKYPIAX_STATE_UP;
+						if (option_debug > 1)
+							DEBUGA_SKYPE("|%s| Sony-Ericsson *ECAM/*ECAV: ACTIVE\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+						break;
+					case 4:
+						if (option_debug > 1)
+							DEBUGA_SKYPE
+								("|%s| Sony-Ericsson *ECAM/*ECAV: don't know how to handle HOLD event\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+						break;
+					case 5:
+						if (option_debug > 1)
+							DEBUGA_SKYPE
+								("|%s| Sony-Ericsson *ECAM/*ECAV: don't know how to handle WAITING event\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+						break;
+					case 6:
+						if (option_debug > 1)
+							DEBUGA_SKYPE
+								("|%s| Sony-Ericsson *ECAM/*ECAV: don't know how to handle ALERTING event\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+						break;
+					case 7:
+						if (tech_pvt->owner) {
+							ast_setstate(tech_pvt->owner, SKYPIAX_STATE_BUSY);
+							celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_BUSY);
+						}
+						tech_pvt->phone_callflow = CALLFLOW_CALL_LINEBUSY;
+						tech_pvt->interface_state = SKYPIAX_STATE_BUSY;
+						if (option_debug > 1)
+							DEBUGA_SKYPE("|%s| Sony-Ericsson *ECAM/*ECAV: BUSY\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+						break;
+					}
+				} else {
+					if (option_debug > 1)
+						DEBUGA_SKYPE("|%s| Sony-Ericsson *ECAM/*ECAV: could not parse parameters\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+				}
 
-      }
+			}
 
-      /* 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 */
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_noservice_string) == 0)) {
-        if (option_debug > 1)
-          ERRORA("|%s| at_indicator_noservice_string\n", SKYPIAX_P_LOG,
-                 tech_pvt->line_array.result[i]);
-      }
+			/* 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 */
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_noservice_string) == 0)) {
+				if (option_debug > 1)
+					ERRORA("|%s| at_indicator_noservice_string\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_nosignal_string) == 0)) {
-        if (option_debug > 1)
-          ERRORA("|%s| at_indicator_nosignal_string\n", SKYPIAX_P_LOG,
-                 tech_pvt->line_array.result[i]);
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_nosignal_string) == 0)) {
+				if (option_debug > 1)
+					ERRORA("|%s| at_indicator_nosignal_string\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_lowsignal_string) == 0)) {
-        if (option_debug > 1)
-          WARNINGA("|%s| at_indicator_lowsignal_string\n", SKYPIAX_P_LOG,
-                   tech_pvt->line_array.result[i]);
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_lowsignal_string) == 0)) {
+				if (option_debug > 1)
+					WARNINGA("|%s| at_indicator_lowsignal_string\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_lowbattchg_string) == 0)) {
-        if (option_debug > 1)
-          WARNINGA("|%s| at_indicator_lowbattchg_string\n", SKYPIAX_P_LOG,
-                   tech_pvt->line_array.result[i]);
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_lowbattchg_string) == 0)) {
+				if (option_debug > 1)
+					WARNINGA("|%s| at_indicator_lowbattchg_string\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_nobattchg_string) == 0)) {
-        if (option_debug > 1)
-          ERRORA("|%s| at_indicator_nobattchg_string\n", SKYPIAX_P_LOG,
-                 tech_pvt->line_array.result[i]);
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_nobattchg_string) == 0)) {
+				if (option_debug > 1)
+					ERRORA("|%s| at_indicator_nobattchg_string\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_callactive_string) == 0)) {
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| at_indicator_callactive_string\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_callactive_string) == 0)) {
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| at_indicator_callactive_string\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_nocallactive_string) == 0)) {
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| at_indicator_nocallactive_string\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_nocallactive_string) == 0)) {
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| at_indicator_nocallactive_string\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_nocallsetup_string) == 0)) {
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| at_indicator_nocallsetup_string\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_nocallsetup_string) == 0)) {
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| at_indicator_nocallsetup_string\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_callsetupincoming_string) ==
-           0)) {
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| at_indicator_callsetupincoming_string\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_callsetupincoming_string) == 0)) {
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| at_indicator_callsetupincoming_string\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_callsetupoutgoing_string) ==
-           0)) {
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| at_indicator_callsetupoutgoing_string\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_callsetupoutgoing_string) == 0)) {
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| at_indicator_callsetupoutgoing_string\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-      if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_callsetupremoteringing_string)
-           == 0)) {
-        if (option_debug > 1)
-          DEBUGA_SKYPE("|%s| at_indicator_callsetupremoteringing_string\n", SKYPIAX_P_LOG,
-                    tech_pvt->line_array.result[i]);
-      }
+			if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_indicator_callsetupremoteringing_string)
+				 == 0)) {
+				if (option_debug > 1)
+					DEBUGA_SKYPE("|%s| at_indicator_callsetupremoteringing_string\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+			}
 
-    }
+		}
 
-    /* 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 */
-    for (i = la_read; i < la_counter; i++) {
-      if (expected_string) {
-        if ((strncmp(tech_pvt->line_array.result[i], expected_string, strlen(expected_string))
-             == 0)) {
-          if (option_debug > 1)
-            DEBUGA_SKYPE("|%s| got what EXPECTED\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
-          at_ack = AT_OK;
-        }
-      } else {
-        if ((strcmp(tech_pvt->line_array.result[i], "OK") == 0)) {
-          if (option_debug > 1)
-            DEBUGA_SKYPE("got OK\n", SKYPIAX_P_LOG);
-          at_ack = AT_OK;
-        }
-      }
-      if ((strcmp(tech_pvt->line_array.result[i], "ERROR") == 0)) {
-        if (option_debug > 1)
-          DEBUGA_SKYPE("got ERROR\n", SKYPIAX_P_LOG);
-        at_ack = AT_ERROR;
-      }
+		/* 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 */
+		for (i = la_read; i < la_counter; i++) {
+			if (expected_string) {
+				if ((strncmp(tech_pvt->line_array.result[i], expected_string, strlen(expected_string))
+					 == 0)) {
+					if (option_debug > 1)
+						DEBUGA_SKYPE("|%s| got what EXPECTED\n", SKYPIAX_P_LOG, tech_pvt->line_array.result[i]);
+					at_ack = AT_OK;
+				}
+			} else {
+				if ((strcmp(tech_pvt->line_array.result[i], "OK") == 0)) {
+					if (option_debug > 1)
+						DEBUGA_SKYPE("got OK\n", SKYPIAX_P_LOG);
+					at_ack = AT_OK;
+				}
+			}
+			if ((strcmp(tech_pvt->line_array.result[i], "ERROR") == 0)) {
+				if (option_debug > 1)
+					DEBUGA_SKYPE("got ERROR\n", SKYPIAX_P_LOG);
+				at_ack = AT_ERROR;
+			}
 
-      /* if we are reading an sms message from memory, put the line into the sms buffer if the line is not "OK" or "ERROR" */
-      if (tech_pvt->reading_sms_msg > 1 && at_ack == -1) {
-        int c;
-        char sms_body[16000];
-        int err;
+			/* if we are reading an sms message from memory, put the line into the sms buffer if the line is not "OK" or "ERROR" */
+			if (tech_pvt->reading_sms_msg > 1 && at_ack == -1) {
+				int c;
+				char sms_body[16000];
+				int err;
 
-        if (strncmp(tech_pvt->line_array.result[i], "+CMGR", 5) == 0) {    /* we are reading the "header" of an SMS */
-          char content[512];
-          char content2[512];
+				if (strncmp(tech_pvt->line_array.result[i], "+CMGR", 5) == 0) {	/* we are reading the "header" of an SMS */
+					char content[512];
+					char content2[512];
 
-          memset(content, '\0', sizeof(content));
+					memset(content, '\0', sizeof(content));
 
-          int inside_comma = 0;
-          int inside_quote = 0;
-          int d = 0;
+					int inside_comma = 0;
+					int inside_quote = 0;
+					int d = 0;
 
-          for (c = 0; c < strlen(tech_pvt->line_array.result[i]); c++) {
-            if (tech_pvt->line_array.result[i][c] == ','
-                && tech_pvt->line_array.result[i][c - 1] != '\\' && inside_quote == 0) {
-              if (inside_comma) {
-                inside_comma = 0;
-                //NOTICA("inside_comma=%d, inside_quote=%d, we're at=%s\n", SKYPIAX_P_LOG, inside_comma, inside_quote, &tech_pvt->line_array.result[i][c]);
-              } else {
-                inside_comma = 1;
-                //NOTICA("inside_comma=%d, inside_quote=%d, we're at=%s\n", SKYPIAX_P_LOG, inside_comma, inside_quote, &tech_pvt->line_array.result[i][c]);
-              }
-            }
-            if (tech_pvt->line_array.result[i][c] == '"'
-                && tech_pvt->line_array.result[i][c - 1] != '\\') {
-              if (inside_quote) {
-                inside_quote = 0;
-                //ERRORA("END_CONTENT inside_comma=%d, inside_quote=%d, we're at=%s\n", SKYPIAX_P_LOG, inside_comma, inside_quote, &tech_pvt->line_array.result[i][c]);
-                DEBUGA_SKYPE("content=%s\n", SKYPIAX_P_LOG, content);
+					for (c = 0; c < strlen(tech_pvt->line_array.result[i]); c++) {
+						if (tech_pvt->line_array.result[i][c] == ',' && tech_pvt->line_array.result[i][c - 1] != '\\' && inside_quote == 0) {
+							if (inside_comma) {
+								inside_comma = 0;
+								//NOTICA("inside_comma=%d, inside_quote=%d, we're at=%s\n", SKYPIAX_P_LOG, inside_comma, inside_quote, &tech_pvt->line_array.result[i][c]);
+							} else {
+								inside_comma = 1;
+								//NOTICA("inside_comma=%d, inside_quote=%d, we're at=%s\n", SKYPIAX_P_LOG, inside_comma, inside_quote, &tech_pvt->line_array.result[i][c]);
+							}
+						}
+						if (tech_pvt->line_array.result[i][c] == '"' && tech_pvt->line_array.result[i][c - 1] != '\\') {
+							if (inside_quote) {
+								inside_quote = 0;
+								//ERRORA("END_CONTENT inside_comma=%d, inside_quote=%d, we're at=%s\n", SKYPIAX_P_LOG, inside_comma, inside_quote, &tech_pvt->line_array.result[i][c]);
+								DEBUGA_SKYPE("content=%s\n", SKYPIAX_P_LOG, content);
 
-                strncat(tech_pvt->sms_message, "---",
-                        ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
-                strncat(tech_pvt->sms_message, content,
-                        ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
-                strncat(tech_pvt->sms_message, "|||",
-                        ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
+								strncat(tech_pvt->sms_message, "---", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
+								strncat(tech_pvt->sms_message, content, ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
+								strncat(tech_pvt->sms_message, "|||", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
 
-                memset(content2, '\0', sizeof(content2));
-                err = ucs2_to_utf8(tech_pvt, content, content2, sizeof(content2));
+								memset(content2, '\0', sizeof(content2));
+								err = ucs2_to_utf8(tech_pvt, content, content2, sizeof(content2));
 
-                strncat(tech_pvt->sms_message, "---",
-                        ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
-                if (!err)
-                  strncat(tech_pvt->sms_message, content2,
-                          ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
-                strncat(tech_pvt->sms_message, "|||",
-                        ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
-                memset(content, '\0', sizeof(content));
-                d = 0;
-              } else {
-                inside_quote = 1;
-                //WARNINGA("START_CONTENT inside_comma=%d, inside_quote=%d, we're at=%s\n", SKYPIAX_P_LOG, inside_comma, inside_quote, &tech_pvt->line_array.result[i][c]);
-              }
-            }
-            if (inside_quote && tech_pvt->line_array.result[i][c] != '"') {
+								strncat(tech_pvt->sms_message, "---", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
+								if (!err)
+									strncat(tech_pvt->sms_message, content2, ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
+								strncat(tech_pvt->sms_message, "|||", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
+								memset(content, '\0', sizeof(content));
+								d = 0;
+							} else {
+								inside_quote = 1;
+								//WARNINGA("START_CONTENT inside_comma=%d, inside_quote=%d, we're at=%s\n", SKYPIAX_P_LOG, inside_comma, inside_quote, &tech_pvt->line_array.result[i][c]);
+							}
+						}
+						if (inside_quote && tech_pvt->line_array.result[i][c] != '"') {
 
-              content[d] = tech_pvt->line_array.result[i][c];
-              d++;
+							content[d] = tech_pvt->line_array.result[i][c];
+							d++;
 
-            }
+						}
 
-          }
-        }                       //it was the +CMGR answer from the cellphone
-        else {
-          strncat(tech_pvt->sms_message, "---",
-                  ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
-          strncat(tech_pvt->sms_message, tech_pvt->line_array.result[i],
-                  ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
-          strncat(tech_pvt->sms_message, "|||",
-                  ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
+					}
+				}				//it was the +CMGR answer from the cellphone
+				else {
+					strncat(tech_pvt->sms_message, "---", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
+					strncat(tech_pvt->sms_message, tech_pvt->line_array.result[i], ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
+					strncat(tech_pvt->sms_message, "|||", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
 
-          memset(sms_body, '\0', sizeof(sms_body));
-          err = ucs2_to_utf8(tech_pvt, tech_pvt->line_array.result[i], sms_body, sizeof(sms_body));
+					memset(sms_body, '\0', sizeof(sms_body));
+					err = ucs2_to_utf8(tech_pvt, tech_pvt->line_array.result[i], sms_body, sizeof(sms_body));
 
-          strncat(tech_pvt->sms_message, "---",
-                  ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
-          if (!err)
-            strncat(tech_pvt->sms_message, sms_body,
-                    ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
-          strncat(tech_pvt->sms_message, "|||",
-                  ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
+					strncat(tech_pvt->sms_message, "---", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
+					if (!err)
+						strncat(tech_pvt->sms_message, sms_body, ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
+					strncat(tech_pvt->sms_message, "|||", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
 
-          DEBUGA_SKYPE("sms_message=%s\n", SKYPIAX_P_LOG, tech_pvt->sms_message);
+					DEBUGA_SKYPE("sms_message=%s\n", SKYPIAX_P_LOG, tech_pvt->sms_message);
 
-        }                       //it was the UCS2 from cellphone
+				}				//it was the UCS2 from cellphone
 
-      }                         //we were reading the SMS
+			}					//we were reading the SMS
 
-    }
+		}
 
-    la_read = la_counter;
+		la_read = la_counter;
 
-    if (look_for_ack && at_ack > -1)
-      break;
+		if (look_for_ack && at_ack > -1)
+			break;
 
-    if (la_counter > AT_MESG_MAX_LINES) {
-      ERRORA("Too many lines in result (>%d). Stopping reader.\n", SKYPIAX_P_LOG,
-             AT_MESG_MAX_LINES);
-      at_ack = AT_ERROR;
-      break;
-    }
-  }
+		if (la_counter > AT_MESG_MAX_LINES) {
+			ERRORA("Too many lines in result (>%d). Stopping reader.\n", SKYPIAX_P_LOG, AT_MESG_MAX_LINES);
+			at_ack = AT_ERROR;
+			break;
+		}
+	}
 
-  UNLOCKA(tech_pvt->controldev_lock);
-  POPPA_UNLOCKA(tech_pvt->controldev_lock);
-  if (select_err == -1) {
-    ERRORA("select returned -1 on %s, setting controldev_dead, error was: %s\n",
-           SKYPIAX_P_LOG, tech_pvt->controldevice_name, strerror(errno));
-    tech_pvt->controldev_dead = 1;
-    close(tech_pvt->controldevfd);
-    if (tech_pvt->owner)
-      celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
-    return -1;
-  }
+	UNLOCKA(tech_pvt->controldev_lock);
+	POPPA_UNLOCKA(tech_pvt->controldev_lock);
+	if (select_err == -1) {
+		ERRORA("select returned -1 on %s, setting controldev_dead, error was: %s\n", SKYPIAX_P_LOG, tech_pvt->controldevice_name, strerror(errno));
+		tech_pvt->controldev_dead = 1;
+		close(tech_pvt->controldevfd);
+		if (tech_pvt->owner)
+			celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
+		return -1;
+	}
 
-  if (tech_pvt->phone_callflow == CALLFLOW_CALL_INCOMING && tech_pvt->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
-    char list_command[64];
-    struct timeval call_incoming_timeout;
-    gettimeofday(&call_incoming_timeout, NULL);
-    call_incoming_timeout.tv_sec -= 3;
-    DEBUGA_SKYPE
-      ("CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld, call_incoming_timeout.tv_sec=%ld\n",
-       SKYPIAX_P_LOG, tech_pvt->call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
-    if (call_incoming_timeout.tv_sec > tech_pvt->call_incoming_time.tv_sec) {
+	if (tech_pvt->phone_callflow == CALLFLOW_CALL_INCOMING && tech_pvt->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
+		char list_command[64];
+		struct timeval call_incoming_timeout;
+		gettimeofday(&call_incoming_timeout, NULL);
+		call_incoming_timeout.tv_sec -= 3;
+		DEBUGA_SKYPE
+			("CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld, call_incoming_timeout.tv_sec=%ld\n",
+			 SKYPIAX_P_LOG, tech_pvt->call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
+		if (call_incoming_timeout.tv_sec > tech_pvt->call_incoming_time.tv_sec) {
 
-      tech_pvt->call_incoming_time.tv_sec = 0;
-      tech_pvt->call_incoming_time.tv_usec = 0;
-      DEBUGA_SKYPE
-        ("CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld, call_incoming_timeout.tv_sec=%ld\n",
-         SKYPIAX_P_LOG, tech_pvt->call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
-      res = celliax_serial_write_AT_ack(tech_pvt, "AT+CPBS=RC");
-      if (res) {
-        ERRORA
-          ("AT+CPBS=RC (select memory of received calls) was not answered by the phone\n",
-           SKYPIAX_P_LOG);
-      }
-      tech_pvt->phonebook_querying = 1;
-      res = celliax_serial_write_AT_ack(tech_pvt, "AT+CPBR=?");
-      if (res) {
-        ERRORA
-          ("AT+CPBS=RC (select memory of received calls) was not answered by the phone\n",
-           SKYPIAX_P_LOG);
-      }
-      tech_pvt->phonebook_querying = 0;
-      sprintf(list_command, "AT+CPBR=%d,%d", tech_pvt->phonebook_first_entry,
-              tech_pvt->phonebook_last_entry);
-      tech_pvt->phonebook_listing_received_calls = 1;
-      res = celliax_serial_write_AT_expect_longtime(tech_pvt, list_command, "OK");
-      if (res) {
-        WARNINGA("AT+CPBR=%d,%d failed, continue\n", SKYPIAX_P_LOG,
-                 tech_pvt->phonebook_first_entry, tech_pvt->phonebook_last_entry);
-      }
-      tech_pvt->phonebook_listing_received_calls = 0;
-    }
-  }
+			tech_pvt->call_incoming_time.tv_sec = 0;
+			tech_pvt->call_incoming_time.tv_usec = 0;
+			DEBUGA_SKYPE
+				("CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld, call_incoming_timeout.tv_sec=%ld\n",
+				 SKYPIAX_P_LOG, tech_pvt->call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
+			res = celliax_serial_write_AT_ack(tech_pvt, "AT+CPBS=RC");
+			if (res) {
+				ERRORA("AT+CPBS=RC (select memory of received calls) was not answered by the phone\n", SKYPIAX_P_LOG);
+			}
+			tech_pvt->phonebook_querying = 1;
+			res = celliax_serial_write_AT_ack(tech_pvt, "AT+CPBR=?");
+			if (res) {
+				ERRORA("AT+CPBS=RC (select memory of received calls) was not answered by the phone\n", SKYPIAX_P_LOG);
+			}
+			tech_pvt->phonebook_querying = 0;
+			sprintf(list_command, "AT+CPBR=%d,%d", tech_pvt->phonebook_first_entry, tech_pvt->phonebook_last_entry);
+			tech_pvt->phonebook_listing_received_calls = 1;
+			res = celliax_serial_write_AT_expect_longtime(tech_pvt, list_command, "OK");
+			if (res) {
+				WARNINGA("AT+CPBR=%d,%d failed, continue\n", SKYPIAX_P_LOG, tech_pvt->phonebook_first_entry, tech_pvt->phonebook_last_entry);
+			}
+			tech_pvt->phonebook_listing_received_calls = 0;
+		}
+	}
 
-  if (tech_pvt->phone_callflow == CALLFLOW_INCOMING_RING) {
-    struct timeval call_incoming_timeout;
-    gettimeofday(&call_incoming_timeout, NULL);
-    call_incoming_timeout.tv_sec -= 10;
-    DEBUGA_SKYPE
-      ("CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld, call_incoming_timeout.tv_sec=%ld\n",
-       SKYPIAX_P_LOG, tech_pvt->call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
-    if (call_incoming_timeout.tv_sec > tech_pvt->ringtime.tv_sec) {
-      ERRORA("Ringing stopped and I have not answered. Why?\n", SKYPIAX_P_LOG);
-      DEBUGA_SKYPE
-        ("CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld, call_incoming_timeout.tv_sec=%ld\n",
-         SKYPIAX_P_LOG, tech_pvt->call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
-      if (tech_pvt->owner) {
-        celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
-        tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
-      }
-    }
-  }
-  tech_pvt->line_array.elemcount = la_counter;
-  //NOTICA (" OUTSIDE this celliax_serial_device %s \n", SKYPIAX_P_LOG, tech_pvt->controldevice_name);
-  if (look_for_ack)
-    return at_ack;
-  else
-    return 0;
+	if (tech_pvt->phone_callflow == CALLFLOW_INCOMING_RING) {
+		struct timeval call_incoming_timeout;
+		gettimeofday(&call_incoming_timeout, NULL);
+		call_incoming_timeout.tv_sec -= 10;
+		DEBUGA_SKYPE
+			("CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld, call_incoming_timeout.tv_sec=%ld\n",
+			 SKYPIAX_P_LOG, tech_pvt->call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
+		if (call_incoming_timeout.tv_sec > tech_pvt->ringtime.tv_sec) {
+			ERRORA("Ringing stopped and I have not answered. Why?\n", SKYPIAX_P_LOG);
+			DEBUGA_SKYPE
+				("CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld, call_incoming_timeout.tv_sec=%ld\n",
+				 SKYPIAX_P_LOG, tech_pvt->call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
+			if (tech_pvt->owner) {
+				celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_HANGUP);
+				tech_pvt->owner->hangupcause = SKYPIAX_CAUSE_FAILURE;
+			}
+		}
+	}
+	tech_pvt->line_array.elemcount = la_counter;
+	//NOTICA (" OUTSIDE this celliax_serial_device %s \n", SKYPIAX_P_LOG, tech_pvt->controldevice_name);
+	if (look_for_ack)
+		return at_ack;
+	else
+		return 0;
 }
 
 int celliax_serial_write_AT(private_t * tech_pvt, const char *data)
 {
-  int howmany;
-  int i;
-  int res;
-  int count;
+	int howmany;
+	int i;
+	int res;
+	int count;
 
-  howmany = strlen(data);
+	howmany = strlen(data);
 
-  for (i = 0; i < howmany; i++) {
-    res = write(tech_pvt->controldevfd, &data[i], 1);
+	for (i = 0; i < howmany; i++) {
+		res = write(tech_pvt->controldevfd, &data[i], 1);
 
-    if (res != 1) {
-      DEBUGA_SKYPE("Error sending (%.1s): %d (%s)\n", SKYPIAX_P_LOG, &data[i], res,
-                strerror(errno));
-      usleep(100000);
-      for (count = 0; count < 10; count++) {
-        res = write(tech_pvt->controldevfd, &data[i], 1);
-        if (res == 1) {
-          DEBUGA_SKYPE("Successfully RE-sent (%.1s): %d %d (%s)\n", SKYPIAX_P_LOG, &data[i],
-                    count, res, strerror(errno));
-          break;
-        } else
-          DEBUGA_SKYPE("Error RE-sending (%.1s): %d %d (%s)\n", SKYPIAX_P_LOG, &data[i],
-                    count, res, strerror(errno));
-        usleep(100000);
+		if (res != 1) {
+			DEBUGA_SKYPE("Error sending (%.1s): %d (%s)\n", SKYPIAX_P_LOG, &data[i], res, strerror(errno));
+			usleep(100000);
+			for (count = 0; count < 10; count++) {
+				res = write(tech_pvt->controldevfd, &data[i], 1);
+				if (res == 1) {
+					DEBUGA_SKYPE("Successfully RE-sent (%.1s): %d %d (%s)\n", SKYPIAX_P_LOG, &data[i], count, res, strerror(errno));
+					break;
+				} else
+					DEBUGA_SKYPE("Error RE-sending (%.1s): %d %d (%s)\n", SKYPIAX_P_LOG, &data[i], count, res, strerror(errno));
+				usleep(100000);
 
-      }
-      if (res != 1) {
-        ERRORA("Error RE-sending (%.1s): %d %d (%s)\n", SKYPIAX_P_LOG, &data[i], count,
-               res, strerror(errno));
-        return -1;
-      }
-    }
-    if (option_debug > 1)
-      DEBUGA_SKYPE("sent data... (%.1s)\n", SKYPIAX_P_LOG, &data[i]);
-    usleep(1000);               /* release the cpu */
-  }
+			}
+			if (res != 1) {
+				ERRORA("Error RE-sending (%.1s): %d %d (%s)\n", SKYPIAX_P_LOG, &data[i], count, res, strerror(errno));
+				return -1;
+			}
+		}
+		if (option_debug > 1)
+			DEBUGA_SKYPE("sent data... (%.1s)\n", SKYPIAX_P_LOG, &data[i]);
+		usleep(1000);			/* release the cpu */
+	}
 
-  res = write(tech_pvt->controldevfd, "\r", 1);
+	res = write(tech_pvt->controldevfd, "\r", 1);
 
-  if (res != 1) {
-    DEBUGA_SKYPE("Error sending (carriage return): %d (%s)\n", SKYPIAX_P_LOG, res,
-              strerror(errno));
-    usleep(100000);
-    for (count = 0; count < 10; count++) {
-      res = write(tech_pvt->controldevfd, "\r", 1);
+	if (res != 1) {
+		DEBUGA_SKYPE("Error sending (carriage return): %d (%s)\n", SKYPIAX_P_LOG, res, strerror(errno));
+		usleep(100000);
+		for (count = 0; count < 10; count++) {
+			res = write(tech_pvt->controldevfd, "\r", 1);
 
-      if (res == 1) {
-        DEBUGA_SKYPE("Successfully RE-sent carriage return: %d %d (%s)\n", SKYPIAX_P_LOG,
-                  count, res, strerror(errno));
-        break;
-      } else
-        DEBUGA_SKYPE("Error RE-sending (carriage return): %d %d (%s)\n", SKYPIAX_P_LOG,
-                  count, res, strerror(errno));
-      usleep(100000);
+			if (res == 1) {
+				DEBUGA_SKYPE("Successfully RE-sent carriage return: %d %d (%s)\n", SKYPIAX_P_LOG, count, res, strerror(errno));
+				break;
+			} else
+				DEBUGA_SKYPE("Error RE-sending (carriage return): %d %d (%s)\n", SKYPIAX_P_LOG, count, res, strerror(errno));
+			usleep(100000);
 
-    }
-    if (res != 1) {
-      ERRORA("Error RE-sending (carriage return): %d %d (%s)\n", SKYPIAX_P_LOG, count,
-             res, strerror(errno));
-      return -1;
-    }
-  }
-  if (option_debug > 1)
-    DEBUGA_SKYPE("sent (carriage return)\n", SKYPIAX_P_LOG);
-  usleep(1000);                 /* release the cpu */
+		}
+		if (res != 1) {
+			ERRORA("Error RE-sending (carriage return): %d %d (%s)\n", SKYPIAX_P_LOG, count, res, strerror(errno));
+			return -1;
+		}
+	}
+	if (option_debug > 1)
+		DEBUGA_SKYPE("sent (carriage return)\n", SKYPIAX_P_LOG);
+	usleep(1000);				/* release the cpu */
 
-  return howmany;
+	return howmany;
 }
 
 int celliax_serial_write_AT_nocr(private_t * tech_pvt, const char *data)
 {
-  int howmany;
-  int i;
-  int res;
-  int count;
+	int howmany;
+	int i;
+	int res;
+	int count;
 
-  howmany = strlen(data);
+	howmany = strlen(data);
 
-  for (i = 0; i < howmany; i++) {
-    res = write(tech_pvt->controldevfd, &data[i], 1);
+	for (i = 0; i < howmany; i++) {
+		res = write(tech_pvt->controldevfd, &data[i], 1);
 
-    if (res != 1) {
-      DEBUGA_SKYPE("Error sending (%.1s): %d (%s)\n", SKYPIAX_P_LOG, &data[i], res,
-                strerror(errno));
-      usleep(100000);
-      for (count = 0; count < 10; count++) {
-        res = write(tech_pvt->controldevfd, &data[i], 1);
-        if (res == 1)
-          break;
-        else
-          DEBUGA_SKYPE("Error RE-sending (%.1s): %d %d (%s)\n", SKYPIAX_P_LOG, &data[i],
-                    count, res, strerror(errno));
-        usleep(100000);
+		if (res != 1) {
+			DEBUGA_SKYPE("Error sending (%.1s): %d (%s)\n", SKYPIAX_P_LOG, &data[i], res, strerror(errno));
+			usleep(100000);
+			for (count = 0; count < 10; count++) {
+				res = write(tech_pvt->controldevfd, &data[i], 1);
+				if (res == 1)
+					break;
+				else
+					DEBUGA_SKYPE("Error RE-sending (%.1s): %d %d (%s)\n", SKYPIAX_P_LOG, &data[i], count, res, strerror(errno));
+				usleep(100000);
 
-      }
-      if (res != 1) {
-        ERRORA("Error RE-sending (%.1s): %d %d (%s)\n", SKYPIAX_P_LOG, &data[i], count,
-               res, strerror(errno));
-        return -1;
-      }
-    }
-    if (option_debug > 1)
-      DEBUGA_SKYPE("sent data... (%.1s)\n", SKYPIAX_P_LOG, &data[i]);
-    usleep(1000);               /* release the cpu */
-  }
+			}
+			if (res != 1) {
+				ERRORA("Error RE-sending (%.1s): %d %d (%s)\n", SKYPIAX_P_LOG, &data[i], count, res, strerror(errno));
+				return -1;
+			}
+		}
+		if (option_debug > 1)
+			DEBUGA_SKYPE("sent data... (%.1s)\n", SKYPIAX_P_LOG, &data[i]);
+		usleep(1000);			/* release the cpu */
+	}
 
-  usleep(1000);                 /* release the cpu */
+	usleep(1000);				/* release the cpu */
 
-  return howmany;
+	return howmany;
 }
 
 int celliax_serial_write_AT_noack(private_t * tech_pvt, const char *data)
 {
 
-  if (option_debug > 1)
-    DEBUGA_SKYPE("celliax_serial_write_AT_noack: %s\n", SKYPIAX_P_LOG, data);
+	if (option_debug > 1)
+		DEBUGA_SKYPE("celliax_serial_write_AT_noack: %s\n", SKYPIAX_P_LOG, data);
 
-  PUSHA_UNLOCKA(tech_pvt->controldev_lock);
-  LOKKA(tech_pvt->controldev_lock);
-  if (celliax_serial_write_AT(tech_pvt, data) != strlen(data)) {
+	PUSHA_UNLOCKA(tech_pvt->controldev_lock);
+	LOKKA(tech_pvt->controldev_lock);
+	if (celliax_serial_write_AT(tech_pvt, data) != strlen(data)) {
 
-    ERRORA("Error sending data... (%s)\n", SKYPIAX_P_LOG, strerror(errno));
-    UNLOCKA(tech_pvt->controldev_lock);
-    return -1;
-  }
-  UNLOCKA(tech_pvt->controldev_lock);
-  POPPA_UNLOCKA(tech_pvt->controldev_lock);
+		ERRORA("Error sending data... (%s)\n", SKYPIAX_P_LOG, strerror(errno));
+		UNLOCKA(tech_pvt->controldev_lock);
+		return -1;
+	}
+	UNLOCKA(tech_pvt->controldev_lock);
+	POPPA_UNLOCKA(tech_pvt->controldev_lock);
 
-  return 0;
+	return 0;
 }
 
 int celliax_serial_write_AT_ack(private_t * tech_pvt, const char *data)
 {
-  int at_result = AT_ERROR;
+	int at_result = AT_ERROR;
 
-  PUSHA_UNLOCKA(tech_pvt->controldev_lock);
-  LOKKA(tech_pvt->controldev_lock);
-  if (option_debug > 1)
-    DEBUGA_SKYPE("sending: %s\n", SKYPIAX_P_LOG, data);
-  if (celliax_serial_write_AT(tech_pvt, data) != strlen(data)) {
-    ERRORA("Error sending data... (%s) \n", SKYPIAX_P_LOG, strerror(errno));
-    UNLOCKA(tech_pvt->controldev_lock);
-    return -1;
-  }
+	PUSHA_UNLOCKA(tech_pvt->controldev_lock);
+	LOKKA(tech_pvt->controldev_lock);
+	if (option_debug > 1)
+		DEBUGA_SKYPE("sending: %s\n", SKYPIAX_P_LOG, data);
+	if (celliax_serial_write_AT(tech_pvt, data) != strlen(data)) {
+		ERRORA("Error sending data... (%s) \n", SKYPIAX_P_LOG, strerror(errno));
+		UNLOCKA(tech_pvt->controldev_lock);
+		return -1;
+	}
 
-  at_result = celliax_serial_read_AT(tech_pvt, 1, 500000, 2, NULL, 1); // 2.5 sec timeout
-  UNLOCKA(tech_pvt->controldev_lock);
-  POPPA_UNLOCKA(tech_pvt->controldev_lock);
+	at_result = celliax_serial_read_AT(tech_pvt, 1, 500000, 2, NULL, 1);	// 2.5 sec timeout
+	UNLOCKA(tech_pvt->controldev_lock);
+	POPPA_UNLOCKA(tech_pvt->controldev_lock);
 
-  return at_result;
+	return at_result;
 
 }
 
 int celliax_serial_write_AT_ack_nocr_longtime(private_t * tech_pvt, const char *data)
 {
-  int at_result = AT_ERROR;
+	int at_result = AT_ERROR;
 
-  PUSHA_UNLOCKA(tech_pvt->controldev_lock);
-  LOKKA(tech_pvt->controldev_lock);
-  if (option_debug > 1)
-    DEBUGA_SKYPE("sending: %s\n", SKYPIAX_P_LOG, data);
-  if (celliax_serial_write_AT_nocr(tech_pvt, data) != strlen(data)) {
-    ERRORA("Error sending data... (%s) \n", SKYPIAX_P_LOG, strerror(errno));
-    UNLOCKA(tech_pvt->controldev_lock);
-    return -1;
-  }
+	PUSHA_UNLOCKA(tech_pvt->controldev_lock);
+	LOKKA(tech_pvt->controldev_lock);
+	if (option_debug > 1)
+		DEBUGA_SKYPE("sending: %s\n", SKYPIAX_P_LOG, data);
+	if (celliax_serial_write_AT_nocr(tech_pvt, data) != strlen(data)) {
+		ERRORA("Error sending data... (%s) \n", SKYPIAX_P_LOG, strerror(errno));
+		UNLOCKA(tech_pvt->controldev_lock);
+		return -1;
+	}
 
-  at_result = celliax_serial_read_AT(tech_pvt, 1, 500000, 20, NULL, 1);    // 20.5 sec timeout
-  UNLOCKA(tech_pvt->controldev_lock);
-  POPPA_UNLOCKA(tech_pvt->controldev_lock);
+	at_result = celliax_serial_read_AT(tech_pvt, 1, 500000, 20, NULL, 1);	// 20.5 sec timeout
+	UNLOCKA(tech_pvt->controldev_lock);
+	POPPA_UNLOCKA(tech_pvt->controldev_lock);
 
-  return at_result;
+	return at_result;
 
 }
 
-int celliax_serial_write_AT_expect1(private_t * tech_pvt, const char *data,
-                                    const char *expected_string, int expect_crlf,
-                                    int seconds)
+int celliax_serial_write_AT_expect1(private_t * tech_pvt, const char *data, const char *expected_string, int expect_crlf, int seconds)
 {
-  int at_result = AT_ERROR;
+	int at_result = AT_ERROR;
 
-  PUSHA_UNLOCKA(tech_pvt->controldev_lock);
-  LOKKA(tech_pvt->controldev_lock);
-  if (option_debug > 1)
-    DEBUGA_SKYPE("sending: %s, expecting: %s\n", SKYPIAX_P_LOG, data, expected_string);
-  if (celliax_serial_write_AT(tech_pvt, data) != strlen(data)) {
-    ERRORA("Error sending data... (%s) \n", SKYPIAX_P_LOG, strerror(errno));
-    UNLOCKA(tech_pvt->controldev_lock);
-    return -1;
-  }
+	PUSHA_UNLOCKA(tech_pvt->controldev_lock);
+	LOKKA(tech_pvt->controldev_lock);
+	if (option_debug > 1)
+		DEBUGA_SKYPE("sending: %s, expecting: %s\n", SKYPIAX_P_LOG, data, expected_string);
+	if (celliax_serial_write_AT(tech_pvt, data) != strlen(data)) {
+		ERRORA("Error sending data... (%s) \n", SKYPIAX_P_LOG, strerror(errno));
+		UNLOCKA(tech_pvt->controldev_lock);
+		return -1;
+	}
 
-  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(tech_pvt->controldev_lock);
-  POPPA_UNLOCKA(tech_pvt->controldev_lock);
+	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(tech_pvt->controldev_lock);
+	POPPA_UNLOCKA(tech_pvt->controldev_lock);
 
-  return at_result;
+	return at_result;
 
 }
 
-int celliax_serial_AT_expect(private_t * tech_pvt, const char *expected_string,
-                             int expect_crlf, int seconds)
+int celliax_serial_AT_expect(private_t * tech_pvt, const char *expected_string, int expect_crlf, int seconds)
 {
-  int at_result = AT_ERROR;
+	int at_result = AT_ERROR;
 
-  PUSHA_UNLOCKA(tech_pvt->controldev_lock);
-  LOKKA(tech_pvt->controldev_lock);
-  if (option_debug > 1)
-    DEBUGA_SKYPE("expecting: %s\n", SKYPIAX_P_LOG, expected_string);
+	PUSHA_UNLOCKA(tech_pvt->controldev_lock);
+	LOKKA(tech_pvt->controldev_lock);
+	if (option_debug > 1)
+		DEBUGA_SKYPE("expecting: %s\n", SKYPIAX_P_LOG, expected_string);
 
-  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(tech_pvt->controldev_lock);
-  POPPA_UNLOCKA(tech_pvt->controldev_lock);
+	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(tech_pvt->controldev_lock);
+	POPPA_UNLOCKA(tech_pvt->controldev_lock);
 
-  return at_result;
+	return at_result;
 
 }
 
 int celliax_serial_answer(private_t * tech_pvt)
 {
-  if (tech_pvt->controldevprotocol == PROTOCOL_AT)
-    return celliax_serial_answer_AT(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_AT)
+		return celliax_serial_answer_AT(tech_pvt);
 #ifdef CELLIAX_FBUS2
-  if (tech_pvt->controldevprotocol == PROTOCOL_FBUS2)
-    return celliax_serial_answer_FBUS2(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_FBUS2)
+		return celliax_serial_answer_FBUS2(tech_pvt);
 #endif /* CELLIAX_FBUS2 */
 #ifdef CELLIAX_CVM
-  if (tech_pvt->controldevprotocol == PROTOCOL_CVM_BUSMAIL)
-    return celliax_serial_answer_CVM_BUSMAIL(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_CVM_BUSMAIL)
+		return celliax_serial_answer_CVM_BUSMAIL(tech_pvt);
 #endif /* CELLIAX_CVM */
-  return -1;
+	return -1;
 }
 
 
 int celliax_serial_answer_AT(private_t * tech_pvt)
 {
-  int res;
+	int res;
 
-  res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_answer, tech_pvt->at_answer_expect);
-  if (res) {
-    DEBUGA_SKYPE
-      ("at_answer command failed, command used: %s, expecting: %s, trying with AT+CKPD=\"S\"\n",
-       SKYPIAX_P_LOG, tech_pvt->at_answer, tech_pvt->at_answer_expect);
+	res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_answer, tech_pvt->at_answer_expect);
+	if (res) {
+		DEBUGA_SKYPE
+			("at_answer command failed, command used: %s, expecting: %s, trying with AT+CKPD=\"S\"\n",
+			 SKYPIAX_P_LOG, tech_pvt->at_answer, tech_pvt->at_answer_expect);
 
-    res = celliax_serial_write_AT_ack(tech_pvt, "AT+CKPD=\"S\"");
-    if (res) {
-      ERRORA("at_answer command failed, command used: 'AT+CKPD=\"S\"', giving up\n",
-             SKYPIAX_P_LOG);
-      return -1;
-    }
-  }
-  //tech_pvt->interface_state = SKYPIAX_STATE_UP;
-  //tech_pvt->phone_callflow = CALLFLOW_CALL_ACTIVE;
-  DEBUGA_SKYPE("AT: call answered\n", SKYPIAX_P_LOG);
-  return 0;
+		res = celliax_serial_write_AT_ack(tech_pvt, "AT+CKPD=\"S\"");
+		if (res) {
+			ERRORA("at_answer command failed, command used: 'AT+CKPD=\"S\"', giving up\n", SKYPIAX_P_LOG);
+			return -1;
+		}
+	}
+	//tech_pvt->interface_state = SKYPIAX_STATE_UP;
+	//tech_pvt->phone_callflow = CALLFLOW_CALL_ACTIVE;
+	DEBUGA_SKYPE("AT: call answered\n", SKYPIAX_P_LOG);
+	return 0;
 }
 
 int celliax_serial_hangup(private_t * tech_pvt)
 {
-  if (tech_pvt->controldevprotocol == PROTOCOL_AT)
-    return celliax_serial_hangup_AT(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_AT)
+		return celliax_serial_hangup_AT(tech_pvt);
 #ifdef CELLIAX_FBUS2
-  if (tech_pvt->controldevprotocol == PROTOCOL_FBUS2)
-    return celliax_serial_hangup_FBUS2(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_FBUS2)
+		return celliax_serial_hangup_FBUS2(tech_pvt);
 #endif /* CELLIAX_FBUS2 */
 #ifdef CELLIAX_CVM
-  if (tech_pvt->controldevprotocol == PROTOCOL_CVM_BUSMAIL)
-    return celliax_serial_hangup_CVM_BUSMAIL(tech_pvt);
+	if (tech_pvt->controldevprotocol == PROTOCOL_CVM_BUSMAIL)
+		return celliax_serial_hangup_CVM_BUSMAIL(tech_pvt);
 #endif /* CELLIAX_CVM */
-  return -1;
+	return -1;
 }
 
 
 int celliax_serial_hangup_AT(private_t * tech_pvt)
 {
-  int res;
+	int res;
 
-  if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN) {
-    res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_hangup, tech_pvt->at_hangup_expect);
-    if (res) {
-      DEBUGA_SKYPE
-        ("at_hangup command failed, command used: %s, trying to use AT+CKPD=\"EEE\"\n",
-         SKYPIAX_P_LOG, tech_pvt->at_hangup);
-      res = celliax_serial_write_AT_ack(tech_pvt, "AT+CKPD=\"EEE\"");
-      if (res) {
-        ERRORA("at_hangup command failed, command used: 'AT+CKPD=\"EEE\"'\n",
-               SKYPIAX_P_LOG);
-        return -1;
-      }
-    }
-  }
-  tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-  tech_pvt->phone_callflow = CALLFLOW_CALL_IDLE;
-  return 0;
+	if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN) {
+		res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_hangup, tech_pvt->at_hangup_expect);
+		if (res) {
+			DEBUGA_SKYPE("at_hangup command failed, command used: %s, trying to use AT+CKPD=\"EEE\"\n", SKYPIAX_P_LOG, tech_pvt->at_hangup);
+			res = celliax_serial_write_AT_ack(tech_pvt, "AT+CKPD=\"EEE\"");
+			if (res) {
+				ERRORA("at_hangup command failed, command used: 'AT+CKPD=\"EEE\"'\n", SKYPIAX_P_LOG);
+				return -1;
+			}
+		}
+	}
+	tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+	tech_pvt->phone_callflow = CALLFLOW_CALL_IDLE;
+	return 0;
 }
 
 
 int celliax_serial_call(private_t * tech_pvt, char *dstr)
 {
-  if (tech_pvt->controldevprotocol == PROTOCOL_AT)
-    return celliax_serial_call_AT(tech_pvt, dstr);
+	if (tech_pvt->controldevprotocol == PROTOCOL_AT)
+		return celliax_serial_call_AT(tech_pvt, dstr);
 #ifdef CELLIAX_FBUS2
-  if (tech_pvt->controldevprotocol == PROTOCOL_FBUS2)
-    return celliax_serial_call_FBUS2(tech_pvt, dstr);
+	if (tech_pvt->controldevprotocol == PROTOCOL_FBUS2)
+		return celliax_serial_call_FBUS2(tech_pvt, dstr);
 #endif /* CELLIAX_FBUS2 */
-  if (tech_pvt->controldevprotocol == PROTOCOL_NO_SERIAL)
-    return 0;
+	if (tech_pvt->controldevprotocol == PROTOCOL_NO_SERIAL)
+		return 0;
 #ifdef CELLIAX_CVM
-  if (tech_pvt->controldevprotocol == PROTOCOL_CVM_BUSMAIL)
-    return celliax_serial_call_CVM_BUSMAIL(tech_pvt, dstr);
+	if (tech_pvt->controldevprotocol == PROTOCOL_CVM_BUSMAIL)
+		return celliax_serial_call_CVM_BUSMAIL(tech_pvt, dstr);
 #endif /* CELLIAX_CVM */
-  return -1;
+	return -1;
 }
 
 int celliax_serial_call_AT(private_t * tech_pvt, char *dstr)
 {
-  int res;
-  char at_command[256];
+	int res;
+	char at_command[256];
 
-  if (option_debug)
-    DEBUGA_PBX("Dialing %s\n", SKYPIAX_P_LOG, dstr);
-  memset(at_command, 0, sizeof(at_command));
-  tech_pvt->phone_callflow = CALLFLOW_CALL_DIALING;
-  tech_pvt->interface_state = SKYPIAX_STATE_DIALING;
-  //ast_uri_decode(dstr);
+	if (option_debug)
+		DEBUGA_PBX("Dialing %s\n", SKYPIAX_P_LOG, dstr);
+	memset(at_command, 0, sizeof(at_command));
+	tech_pvt->phone_callflow = CALLFLOW_CALL_DIALING;
+	tech_pvt->interface_state = SKYPIAX_STATE_DIALING;
+	//ast_uri_decode(dstr);
 /*
   size_t fixdstr = strspn(dstr, AST_DIGIT_ANYDIG);
   if (fixdstr == 0) {
@@ -3273,125 +3117,119 @@
     return -1;
   }
 */
-  //dstr[fixdstr] = '\0';
-  sprintf(at_command, "%s%s%s", tech_pvt->at_dial_pre_number, dstr, tech_pvt->at_dial_post_number);
-    DEBUGA_PBX("Dialstring %s\n", SKYPIAX_P_LOG, at_command);
-  res = celliax_serial_write_AT_expect(tech_pvt, at_command, tech_pvt->at_dial_expect);
-  if (res) {
-    ERRORA("dial command failed, dial string was: %s\n", SKYPIAX_P_LOG, at_command);
-    return -1;
-  }
-  // jet - early audio
-  //if (tech_pvt->at_early_audio) {
-    //ast_queue_control(tech_pvt->owner, AST_CONTROL_ANSWER);
-  //}
+	//dstr[fixdstr] = '\0';
+	sprintf(at_command, "%s%s%s", tech_pvt->at_dial_pre_number, dstr, tech_pvt->at_dial_post_number);
+	DEBUGA_PBX("Dialstring %s\n", SKYPIAX_P_LOG, at_command);
+	res = celliax_serial_write_AT_expect(tech_pvt, at_command, tech_pvt->at_dial_expect);
+	if (res) {
+		ERRORA("dial command failed, dial string was: %s\n", SKYPIAX_P_LOG, at_command);
+		return -1;
+	}
+	// jet - early audio
+	//if (tech_pvt->at_early_audio) {
+	//ast_queue_control(tech_pvt->owner, AST_CONTROL_ANSWER);
+	//}
 
-  return 0;
+	return 0;
 }
 
-int ucs2_to_utf8(private_t * tech_pvt, char *ucs2_in, char *utf8_out,
-                 size_t outbytesleft)
+int ucs2_to_utf8(private_t * tech_pvt, char *ucs2_in, char *utf8_out, size_t outbytesleft)
 {
-  char converted[16000];
-  iconv_t iconv_format;
-  int iconv_res;
-  char *outbuf;
-  char *inbuf;
-  size_t inbytesleft;
-  int c;
-  char stringa[5];
-  double hexnum;
-  int i = 0;
+	char converted[16000];
+	iconv_t iconv_format;
+	int iconv_res;
+	char *outbuf;
+	char *inbuf;
+	size_t inbytesleft;
+	int c;
+	char stringa[5];
+	double hexnum;
+	int i = 0;
 
-  memset(converted, '\0', sizeof(converted));
+	memset(converted, '\0', sizeof(converted));
 
-  DEBUGA_SKYPE("ucs2_in=%s\n", SKYPIAX_P_LOG, ucs2_in);
-  /* cicopet */
-  for (c = 0; c < strlen(ucs2_in); c++) {
-    sprintf(stringa, "0x%c%c", ucs2_in[c], ucs2_in[c + 1]);
-    c++;
-    hexnum = strtod(stringa, NULL);
-    converted[i] = hexnum;
-    i++;
-  }
+	DEBUGA_SKYPE("ucs2_in=%s\n", SKYPIAX_P_LOG, ucs2_in);
+	/* cicopet */
+	for (c = 0; c < strlen(ucs2_in); c++) {
+		sprintf(stringa, "0x%c%c", ucs2_in[c], ucs2_in[c + 1]);
+		c++;
+		hexnum = strtod(stringa, NULL);
+		converted[i] = hexnum;
+		i++;
+	}
 
-  outbuf = utf8_out;
-  inbuf = converted;
+	outbuf = utf8_out;
+	inbuf = converted;
 
-  iconv_format = iconv_open("UTF8", "UCS-2BE");
-  if (iconv_format == (iconv_t) - 1) {
-    ERRORA("error: %s\n", SKYPIAX_P_LOG, strerror(errno));
-    return -1;
-  }
+	iconv_format = iconv_open("UTF8", "UCS-2BE");
+	if (iconv_format == (iconv_t) - 1) {
+		ERRORA("error: %s\n", SKYPIAX_P_LOG, strerror(errno));
+		return -1;
+	}
 
-  inbytesleft = i;
-  iconv_res = iconv(iconv_format, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
-  if (iconv_res == (size_t) - 1) {
-    DEBUGA_SKYPE("ciao in=%s, inleft=%d, out=%s, outleft=%d, converted=%s, utf8_out=%s\n",
-              SKYPIAX_P_LOG, inbuf, (int)inbytesleft, outbuf, (int)outbytesleft, converted,
-              utf8_out);
-    DEBUGA_SKYPE("error: %s %d\n", SKYPIAX_P_LOG, strerror(errno), errno);
-    return -1;
-  }
-  DEBUGA_SKYPE
-    ("iconv_res=%d,  in=%s, inleft=%d, out=%s, outleft=%d, converted=%s, utf8_out=%s\n",
-     SKYPIAX_P_LOG, iconv_res, inbuf, (int)inbytesleft, outbuf, (int)outbytesleft, converted,
-     utf8_out);
-  iconv_close(iconv_format);
+	inbytesleft = i;
+	iconv_res = iconv(iconv_format, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+	if (iconv_res == (size_t) -1) {
+		DEBUGA_SKYPE("ciao in=%s, inleft=%d, out=%s, outleft=%d, converted=%s, utf8_out=%s\n",
+					 SKYPIAX_P_LOG, inbuf, (int) inbytesleft, outbuf, (int) outbytesleft, converted, utf8_out);
+		DEBUGA_SKYPE("error: %s %d\n", SKYPIAX_P_LOG, strerror(errno), errno);
+		return -1;
+	}
+	DEBUGA_SKYPE
+		("iconv_res=%d,  in=%s, inleft=%d, out=%s, outleft=%d, converted=%s, utf8_out=%s\n",
+		 SKYPIAX_P_LOG, iconv_res, inbuf, (int) inbytesleft, outbuf, (int) outbytesleft, converted, utf8_out);
+	iconv_close(iconv_format);
 
-  return 0;
+	return 0;
 }
 
-int utf_to_ucs2(private_t * tech_pvt, char *utf_in, size_t inbytesleft, char *ucs2_out,
-                size_t outbytesleft)
+int utf_to_ucs2(private_t * tech_pvt, char *utf_in, size_t inbytesleft, char *ucs2_out, size_t outbytesleft)
 {
-  /* cicopet */
-  iconv_t iconv_format;
-  int iconv_res;
-  char *outbuf;
-  char *inbuf;
-  char converted[16000];
-  int i;
-  char stringa[16];
-  char stringa2[16];
+	/* cicopet */
+	iconv_t iconv_format;
+	int iconv_res;
+	char *outbuf;
+	char *inbuf;
+	char converted[16000];
+	int i;
+	char stringa[16];
+	char stringa2[16];
 
-  memset(converted, '\0', sizeof(converted));
+	memset(converted, '\0', sizeof(converted));
 
-  outbuf = converted;
-  inbuf = utf_in;
+	outbuf = converted;
+	inbuf = utf_in;
 
-  iconv_format = iconv_open("UCS-2BE", "UTF8");
-  if (iconv_format == (iconv_t) - 1) {
-    ERRORA("error: %s\n", SKYPIAX_P_LOG, strerror(errno));
-    return -1;
-  }
-  outbytesleft = 16000;
+	iconv_format = iconv_open("UCS-2BE", "UTF8");
+	if (iconv_format == (iconv_t) - 1) {
+		ERRORA("error: %s\n", SKYPIAX_P_LOG, strerror(errno));
+		return -1;
+	}
+	outbytesleft = 16000;
 
-  DEBUGA_SKYPE("in=%s, inleft=%d, out=%s, outleft=%d, utf_in=%s, converted=%s\n",
-            SKYPIAX_P_LOG, inbuf, (int)inbytesleft, outbuf, (int)outbytesleft, utf_in, converted);
-  iconv_res = iconv(iconv_format, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
-  if (iconv_res == (size_t) - 1) {
-    ERRORA("error: %s %d\n", SKYPIAX_P_LOG, strerror(errno), errno);
-    return -1;
-  }
-  DEBUGA_SKYPE
-    ("iconv_res=%d,  in=%s, inleft=%d, out=%s, outleft=%d, utf_in=%s, converted=%s\n",
-     SKYPIAX_P_LOG, iconv_res, inbuf, (int)inbytesleft, outbuf, (int)outbytesleft, utf_in,
-     converted);
-  iconv_close(iconv_format);
+	DEBUGA_SKYPE("in=%s, inleft=%d, out=%s, outleft=%d, utf_in=%s, converted=%s\n",
+				 SKYPIAX_P_LOG, inbuf, (int) inbytesleft, outbuf, (int) outbytesleft, utf_in, converted);
+	iconv_res = iconv(iconv_format, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+	if (iconv_res == (size_t) -1) {
+		ERRORA("error: %s %d\n", SKYPIAX_P_LOG, strerror(errno), errno);
+		return -1;
+	}
+	DEBUGA_SKYPE
+		("iconv_res=%d,  in=%s, inleft=%d, out=%s, outleft=%d, utf_in=%s, converted=%s\n",
+		 SKYPIAX_P_LOG, iconv_res, inbuf, (int) inbytesleft, outbuf, (int) outbytesleft, utf_in, converted);
+	iconv_close(iconv_format);
 
-  for (i = 0; i < 16000 - outbytesleft; i++) {
-    memset(stringa, '\0', sizeof(stringa));
-    memset(stringa2, '\0', sizeof(stringa2));
-    sprintf(stringa, "%02X", converted[i]);
-    DEBUGA_SKYPE("character is |%02X|\n", SKYPIAX_P_LOG, converted[i]);
-    stringa2[0] = stringa[strlen(stringa) - 2];
-    stringa2[1] = stringa[strlen(stringa) - 1];
-    strncat(ucs2_out, stringa2, ((outbytesleft - strlen(ucs2_out)) - 1));   //add the received line to the buffer
-    DEBUGA_SKYPE("stringa=%s, stringa2=%s, ucs2_out=%s\n", SKYPIAX_P_LOG, stringa, stringa2,
-              ucs2_out);
-  }
-  return 0;
+	for (i = 0; i < 16000 - outbytesleft; i++) {
+		memset(stringa, '\0', sizeof(stringa));
+		memset(stringa2, '\0', sizeof(stringa2));
+		sprintf(stringa, "%02X", converted[i]);
+		DEBUGA_SKYPE("character is |%02X|\n", SKYPIAX_P_LOG, converted[i]);
+		stringa2[0] = stringa[strlen(stringa) - 2];
+		stringa2[1] = stringa[strlen(stringa) - 1];
+		strncat(ucs2_out, stringa2, ((outbytesleft - strlen(ucs2_out)) - 1));	//add the received line to the buffer
+		DEBUGA_SKYPE("stringa=%s, stringa2=%s, ucs2_out=%s\n", SKYPIAX_P_LOG, stringa, stringa2, ucs2_out);
+	}
+	return 0;
 }
 
 
@@ -3399,51 +3237,51 @@
  * Part of PBX interface */
 int celliax_answer(private_t * tech_pvt)
 {
-  int res;
+	int res;
 
-  if (option_debug) {
-    DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
-  }
-  /* do something to actually answer the call, if needed (eg. pick up the phone) */
-  if (tech_pvt->controldevprotocol != PROTOCOL_NO_SERIAL) {
-    if (celliax_serial_answer(tech_pvt)) {
-      ERRORA("celliax_answer FAILED\n", SKYPIAX_P_LOG);
-      if (option_debug) {
-        DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-      }
-      return -1;
-    }
-  }
-  tech_pvt->interface_state = SKYPIAX_STATE_UP;
-  tech_pvt->phone_callflow = CALLFLOW_CALL_ACTIVE;
+	if (option_debug) {
+		DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
+	}
+	/* do something to actually answer the call, if needed (eg. pick up the phone) */
+	if (tech_pvt->controldevprotocol != PROTOCOL_NO_SERIAL) {
+		if (celliax_serial_answer(tech_pvt)) {
+			ERRORA("celliax_answer FAILED\n", SKYPIAX_P_LOG);
+			if (option_debug) {
+				DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+			}
+			return -1;
+		}
+	}
+	tech_pvt->interface_state = SKYPIAX_STATE_UP;
+	tech_pvt->phone_callflow = CALLFLOW_CALL_ACTIVE;
 
-  while (tech_pvt->interface_state == SKYPIAX_STATE_RING) {
-    usleep(10000);              //10msec
-  }
-  if (tech_pvt->interface_state != SKYPIAX_STATE_UP) {
-    ERRORA("call answering failed\n", SKYPIAX_P_LOG);
-    res = -1;
-  } else {
-    if (option_debug)
-      DEBUGA_PBX("call answered\n", SKYPIAX_P_LOG);
-    res = 0;
+	while (tech_pvt->interface_state == SKYPIAX_STATE_RING) {
+		usleep(10000);			//10msec
+	}
+	if (tech_pvt->interface_state != SKYPIAX_STATE_UP) {
+		ERRORA("call answering failed\n", SKYPIAX_P_LOG);
+		res = -1;
+	} else {
+		if (option_debug)
+			DEBUGA_PBX("call answered\n", SKYPIAX_P_LOG);
+		res = 0;
 #ifdef CELLIAX_PORTAUDIO
-    speex_echo_state_reset(tech_pvt->stream->echo_state);
+		speex_echo_state_reset(tech_pvt->stream->echo_state);
 #endif // CELLIAX_PORTAUDIO
 
-									new_inbound_channel(tech_pvt);
-    if (tech_pvt->owner) {
-      DEBUGA_PBX("going to send SKYPIAX_STATE_UP\n", SKYPIAX_P_LOG);
-      ast_setstate(tech_pvt->owner, SKYPIAX_STATE_UP);
-      //ast_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_ANSWER);
-      //celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_ANSWER);
-      DEBUGA_PBX("just sent SKYPIAX_STATE_UP\n", SKYPIAX_P_LOG);
-    }
-  }
-  if (option_debug) {
-    DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-  }
-  return res;
+		new_inbound_channel(tech_pvt);
+		if (tech_pvt->owner) {
+			DEBUGA_PBX("going to send SKYPIAX_STATE_UP\n", SKYPIAX_P_LOG);
+			ast_setstate(tech_pvt->owner, SKYPIAX_STATE_UP);
+			//ast_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_ANSWER);
+			//celliax_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_ANSWER);
+			DEBUGA_PBX("just sent SKYPIAX_STATE_UP\n", SKYPIAX_P_LOG);
+		}
+	}
+	if (option_debug) {
+		DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+	}
+	return res;
 }
 
 /*! \brief  Hangup celliax call
@@ -3452,376 +3290,353 @@
 int celliax_hangup(private_t * tech_pvt)
 {
 
-  /* if there is not celliax pvt why we are here ? */
-  if (!tech_pvt) {
-    ERRORA("Asked to hangup channel not connected\n", SKYPIAX_P_LOG);
-    return 0;
-  }
+	/* if there is not celliax pvt why we are here ? */
+	if (!tech_pvt) {
+		ERRORA("Asked to hangup channel not connected\n", SKYPIAX_P_LOG);
+		return 0;
+	}
 
-    DEBUGA_SKYPE("ENTERING FUNC\n", SKYPIAX_P_LOG);
+	DEBUGA_SKYPE("ENTERING FUNC\n", SKYPIAX_P_LOG);
 
 #ifdef NOTDEF
-  /* shutdown the serial monitoring thread */
-  if (tech_pvt->controldev_thread && (tech_pvt->controldev_thread != SKYPIAX_PTHREADT_NULL)
-      && (tech_pvt->controldev_thread != SKYPIAX_PTHREADT_STOP)) {
-    if (pthread_cancel(tech_pvt->controldev_thread)) {
-      ERRORA("controldev_thread pthread_cancel failed, maybe he killed himself?\n",
-             SKYPIAX_P_LOG);
-    }
-    /* push it, maybe is stuck in a select or so */
-    if (pthread_kill(tech_pvt->controldev_thread, SIGURG)) {
-      DEBUGA_SKYPE("controldev_thread pthread_kill failed, no problem\n", SKYPIAX_P_LOG);
-    }
-#ifndef __CYGWIN__              /* under cygwin, this seems to be not reliable, get stuck at times */
-    /* wait for it to die */
-    if (pthread_join(tech_pvt->controldev_thread, NULL)) {
-      ERRORA("controldev_thread pthread_join failed, BAD\n", SKYPIAX_P_LOG);
-    }
+	/* shutdown the serial monitoring thread */
+	if (tech_pvt->controldev_thread && (tech_pvt->controldev_thread != SKYPIAX_PTHREADT_NULL)
+		&& (tech_pvt->controldev_thread != SKYPIAX_PTHREADT_STOP)) {
+		if (pthread_cancel(tech_pvt->controldev_thread)) {
+			ERRORA("controldev_thread pthread_cancel failed, maybe he killed himself?\n", SKYPIAX_P_LOG);
+		}
+		/* push it, maybe is stuck in a select or so */
+		if (pthread_kill(tech_pvt->controldev_thread, SIGURG)) {
+			DEBUGA_SKYPE("controldev_thread pthread_kill failed, no problem\n", SKYPIAX_P_LOG);
+		}
+#ifndef __CYGWIN__				/* under cygwin, this seems to be not reliable, get stuck at times */
+		/* wait for it to die */
+		if (pthread_join(tech_pvt->controldev_thread, NULL)) {
+			ERRORA("controldev_thread pthread_join failed, BAD\n", SKYPIAX_P_LOG);
+		}
 #else /* __CYGWIN__ */
 /* allow the serial thread to die */
-    usleep(300000);             //300msecs
+		usleep(300000);			//300msecs
 #endif /* __CYGWIN__ */
-  }
-  tech_pvt->controldev_thread = SKYPIAX_PTHREADT_NULL;
-#endif// NOTDEF
+	}
+	tech_pvt->controldev_thread = SKYPIAX_PTHREADT_NULL;
+#endif // NOTDEF
 
 
-  if (tech_pvt->controldevprotocol != PROTOCOL_NO_SERIAL) {
-    if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN) {
-      /* actually hangup through the serial port */
-      if (tech_pvt->controldevprotocol != PROTOCOL_NO_SERIAL) {
-        int res;
-        res = celliax_serial_hangup(tech_pvt);
-        if (res) {
-          ERRORA("celliax_serial_hangup error: %d\n", SKYPIAX_P_LOG, res);
-          if (option_debug) {
-            DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-          }
-          return -1;
-        }
-      }
+	if (tech_pvt->controldevprotocol != PROTOCOL_NO_SERIAL) {
+		if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN) {
+			/* actually hangup through the serial port */
+			if (tech_pvt->controldevprotocol != PROTOCOL_NO_SERIAL) {
+				int res;
+				res = celliax_serial_hangup(tech_pvt);
+				if (res) {
+					ERRORA("celliax_serial_hangup error: %d\n", SKYPIAX_P_LOG, res);
+					if (option_debug) {
+						DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+					}
+					return -1;
+				}
+			}
 
-      while (tech_pvt->interface_state != SKYPIAX_STATE_DOWN) {
-        usleep(10000);          //10msec
-      }
-      if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN) {
-        ERRORA("call hangup failed\n", SKYPIAX_P_LOG);
-        return -1;
-      } else {
-        DEBUGA_SKYPE("call hungup\n", SKYPIAX_P_LOG);
-      }
-    }
-  } else {
-    tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-    tech_pvt->phone_callflow = CALLFLOW_CALL_IDLE;
-  }
+			while (tech_pvt->interface_state != SKYPIAX_STATE_DOWN) {
+				usleep(10000);	//10msec
+			}
+			if (tech_pvt->interface_state != SKYPIAX_STATE_DOWN) {
+				ERRORA("call hangup failed\n", SKYPIAX_P_LOG);
+				return -1;
+			} else {
+				DEBUGA_SKYPE("call hungup\n", SKYPIAX_P_LOG);
+			}
+		}
+	} else {
+		tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+		tech_pvt->phone_callflow = CALLFLOW_CALL_IDLE;
+	}
 
-		switch_set_flag(tech_pvt, TFLAG_HANGUP);
+	switch_set_flag(tech_pvt, TFLAG_HANGUP);
 #ifdef NOTDEF
-  /* if there is a dsp struct alloced, free it */
-  if (tech_pvt->dsp) {
-    ast_dsp_free(tech_pvt->dsp);
-    tech_pvt->dsp = NULL;
-  }
+	/* if there is a dsp struct alloced, free it */
+	if (tech_pvt->dsp) {
+		ast_dsp_free(tech_pvt->dsp);
+		tech_pvt->dsp = NULL;
+	}
 #ifndef __CYGWIN__
 #ifdef CELLIAX_ALSA
 /* restart alsa */
-  snd_pcm_drop(tech_pvt->alsap);
-  snd_pcm_prepare(tech_pvt->alsap);
+	snd_pcm_drop(tech_pvt->alsap);
+	snd_pcm_prepare(tech_pvt->alsap);
 
-  snd_pcm_prepare(tech_pvt->alsac);
-  snd_pcm_start(tech_pvt->alsac);
+	snd_pcm_prepare(tech_pvt->alsac);
+	snd_pcm_start(tech_pvt->alsac);
 #endif /* CELLIAX_ALSA */
 
 #endif /* __CYGWIN__ */
 #ifdef CELLIAX_PORTAUDIO
-  speex_echo_state_reset(tech_pvt->stream->echo_state);
+	speex_echo_state_reset(tech_pvt->stream->echo_state);
 #endif // CELLIAX_PORTAUDIO
 
-  /* re-init the serial port, be paranoid */
-  if (tech_pvt->controldevprotocol != PROTOCOL_NO_SERIAL) {
-    tech_pvt->controldevfd = celliax_serial_init(p, tech_pvt->controldevice_speed);
-    if (tech_pvt->controldevfd < 1) {
-      ERRORA("bad, bad, bad\n", SKYPIAX_P_LOG);
-      if (option_debug) {
-        DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-      }
-      return -1;
-    }
-  }
+	/* re-init the serial port, be paranoid */
+	if (tech_pvt->controldevprotocol != PROTOCOL_NO_SERIAL) {
+		tech_pvt->controldevfd = celliax_serial_init(p, tech_pvt->controldevice_speed);
+		if (tech_pvt->controldevfd < 1) {
+			ERRORA("bad, bad, bad\n", SKYPIAX_P_LOG);
+			if (option_debug) {
+				DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+			}
+			return -1;
+		}
+	}
 #ifndef ASTERISK_VERSION_1_4
-  /* subtract one to the usage count of Celliax-type channels */
-  LOKKA(celliax_usecnt_lock);
-  celliax_usecnt--;
-  if (celliax_usecnt < 0)
-    ERRORA("Usecnt < 0???\n", SKYPIAX_P_LOG);
-  UNLOCKA(celliax_usecnt_lock);
-  ast_update_use_count();
+	/* subtract one to the usage count of Celliax-type channels */
+	LOKKA(celliax_usecnt_lock);
+	celliax_usecnt--;
+	if (celliax_usecnt < 0)
+		ERRORA("Usecnt < 0???\n", SKYPIAX_P_LOG);
+	UNLOCKA(celliax_usecnt_lock);
+	ast_update_use_count();
 #else /* ASTERISK_VERSION_1_4 */
 	ast_module_unref(ast_module_info->self);
 #endif /* ASTERISK_VERSION_1_4 */
 
-  /* our celliax pvt interface is no more part of a channel */
-  tech_pvt->owner = NULL;
-  /* our channel has no more this celliax pvt interface to manage */
-  c->tech_pvt = NULL;
-  /* set the channel state to DOWN, eg. available, not in active use */
-  if (ast_setstate(c, SKYPIAX_STATE_DOWN)) {
-    ERRORA("ast_setstate failed, BAD\n", SKYPIAX_P_LOG);
-    if (option_debug) {
-      DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-    }
-    return -1;
-  }
+	/* our celliax pvt interface is no more part of a channel */
+	tech_pvt->owner = NULL;
+	/* our channel has no more this celliax pvt interface to manage */
+	c->tech_pvt = NULL;
+	/* set the channel state to DOWN, eg. available, not in active use */
+	if (ast_setstate(c, SKYPIAX_STATE_DOWN)) {
+		ERRORA("ast_setstate failed, BAD\n", SKYPIAX_P_LOG);
+		if (option_debug) {
+			DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+		}
+		return -1;
+	}
 
-  if (option_debug)
-    DEBUGA_PBX("Hanged Up\n", SKYPIAX_P_LOG);
-  /* restart the monitor thread, so it can recheck which interfaces it have to watch during its loop (the interfaces that are not owned by channels) */
-  if (celliax_restart_monitor()) {
-    ERRORA("celliax_restart_monitor failed, BAD\n", SKYPIAX_P_LOG);
-    if (option_debug) {
-      DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-    }
-    return -1;
-  }
-
-#endif// NOTDEF
-  if (option_debug) {
-    DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-  }
-  return 0;
+	if (option_debug)
+		DEBUGA_PBX("Hanged Up\n", SKYPIAX_P_LOG);
+	/* restart the monitor thread, so it can recheck which interfaces it have to watch during its loop (the interfaces that are not owned by channels) */
+	if (celliax_restart_monitor()) {
+		ERRORA("celliax_restart_monitor failed, BAD\n", SKYPIAX_P_LOG);
+		if (option_debug) {
+			DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+		}
+		return -1;
+	}
+#endif // NOTDEF
+	if (option_debug) {
+		DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+	}
+	return 0;
 }
 
 
 #ifdef NOTDEF
 int celliax_serial_call_AT(private_t * tech_pvt, char *dstr)
 {
-  int res;
-  char at_command[256];
+	int res;
+	char at_command[256];
 
-  if (option_debug)
-    DEBUGA_PBX("Dialing %s\n", SKYPIAX_P_LOG, dstr);
-  memset(at_command, 0, sizeof(at_command));
-  tech_pvt->phone_callflow = CALLFLOW_CALL_DIALING;
-  tech_pvt->interface_state = SKYPIAX_STATE_DIALING;
-  ast_uri_decode(dstr);
-  size_t fixdstr = strspn(dstr, SKYPIAX_DIGIT_ANYDIG);
-  if (fixdstr == 0) {
-    ERRORA("dial command failed because of invalid dial number. dial string was: %s\n",
-           SKYPIAX_P_LOG, dstr);
-    return -1;
-  }
-  dstr[fixdstr] = '\0';
-  sprintf(at_command, "%s%s%s", tech_pvt->at_dial_pre_number, dstr, tech_pvt->at_dial_post_number);
-  res = celliax_serial_write_AT_expect(tech_pvt, at_command, tech_pvt->at_dial_expect);
-  if (res) {
-    ERRORA("dial command failed, dial string was: %s\n", SKYPIAX_P_LOG, at_command);
-    return -1;
-  }
-  // jet - early audio
-  if (tech_pvt->at_early_audio) {
-    ast_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_ANSWER);
-  }
+	if (option_debug)
+		DEBUGA_PBX("Dialing %s\n", SKYPIAX_P_LOG, dstr);
+	memset(at_command, 0, sizeof(at_command));
+	tech_pvt->phone_callflow = CALLFLOW_CALL_DIALING;
+	tech_pvt->interface_state = SKYPIAX_STATE_DIALING;
+	ast_uri_decode(dstr);
+	size_t fixdstr = strspn(dstr, SKYPIAX_DIGIT_ANYDIG);
+	if (fixdstr == 0) {
+		ERRORA("dial command failed because of invalid dial number. dial string was: %s\n", SKYPIAX_P_LOG, dstr);
+		return -1;
+	}
+	dstr[fixdstr] = '\0';
+	sprintf(at_command, "%s%s%s", tech_pvt->at_dial_pre_number, dstr, tech_pvt->at_dial_post_number);
+	res = celliax_serial_write_AT_expect(tech_pvt, at_command, tech_pvt->at_dial_expect);
+	if (res) {
+		ERRORA("dial command failed, dial string was: %s\n", SKYPIAX_P_LOG, at_command);
+		return -1;
+	}
+	// jet - early audio
+	if (tech_pvt->at_early_audio) {
+		ast_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_ANSWER);
+	}
 
-  return 0;
+	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;
+	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 (!tech_pvt) {
-    ast_cli(fd,
-            "No \"current\" console for celliax_at, please enter 'help celliax_console'\n");
-    return RESULT_SUCCESS;
-  }
-  if (tech_pvt->controldevprotocol != PROTOCOL_AT) {
-    ast_cli(fd,
-            "The \"current\" console is not connected to an 'AT modem' (cellphone)\n");
-    return RESULT_SUCCESS;
-  }
+	if (argc == 1)
+		return RESULT_SHOWUSAGE;
+	if (!tech_pvt) {
+		ast_cli(fd, "No \"current\" console for celliax_at, please enter 'help celliax_console'\n");
+		return RESULT_SUCCESS;
+	}
+	if (tech_pvt->controldevprotocol != PROTOCOL_AT) {
+		ast_cli(fd, "The \"current\" console is not connected to an 'AT modem' (cellphone)\n");
+		return RESULT_SUCCESS;
+	}
 
-  memset(at_cmd, 0, sizeof(at_cmd));
-  c = 0;
-  for (i = 1; i < argc; i++) {
-    for (a = 0; a < 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(tech_pvt, at_cmd);
-  return RESULT_SUCCESS;
+	memset(at_cmd, 0, sizeof(at_cmd));
+	c = 0;
+	for (i = 1; i < argc; i++) {
+		for (a = 0; a < 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(tech_pvt, at_cmd);
+	return RESULT_SUCCESS;
 }
 
 int celliax_serial_getstatus_AT(private_t * tech_pvt)
 {
-  int res;
+	int res;
 
-  if (tech_pvt->owner) {
-    if (tech_pvt->owner->state != SKYPIAX_STATE_UP && tech_pvt->owner->state != SKYPIAX_STATE_DOWN) {
-      DEBUGA_SKYPE("No getstatus, we're neither UP nor DOWN\n", SKYPIAX_P_LOG);
-      return 0;
-    }
-  }
+	if (tech_pvt->owner) {
+		if (tech_pvt->owner->state != SKYPIAX_STATE_UP && tech_pvt->owner->state != SKYPIAX_STATE_DOWN) {
+			DEBUGA_SKYPE("No getstatus, we're neither UP nor DOWN\n", SKYPIAX_P_LOG);
+			return 0;
+		}
+	}
 
-  PUSHA_UNLOCKA(tech_pvt->controldev_lock);
-  LOKKA(tech_pvt->controldev_lock);
-  res = celliax_serial_write_AT_ack(tech_pvt, "AT");
-  if (res) {
-    ERRORA("AT was not acknowledged, continuing but maybe there is a problem\n",
-           SKYPIAX_P_LOG);
-  }
-  usleep(1000);
+	PUSHA_UNLOCKA(tech_pvt->controldev_lock);
+	LOKKA(tech_pvt->controldev_lock);
+	res = celliax_serial_write_AT_ack(tech_pvt, "AT");
+	if (res) {
+		ERRORA("AT was not acknowledged, continuing but maybe there is a problem\n", SKYPIAX_P_LOG);
+	}
+	usleep(1000);
 
-  if (strlen(tech_pvt->at_query_battchg)) {
-    res =
-      celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_query_battchg, tech_pvt->at_query_battchg_expect);
-    if (res) {
-      WARNINGA("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG,
-               tech_pvt->at_query_battchg, tech_pvt->at_query_battchg_expect);
-    }
-    usleep(1000);
-  }
+	if (strlen(tech_pvt->at_query_battchg)) {
+		res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_query_battchg, tech_pvt->at_query_battchg_expect);
+		if (res) {
+			WARNINGA("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG, tech_pvt->at_query_battchg, tech_pvt->at_query_battchg_expect);
+		}
+		usleep(1000);
+	}
 
-  if (strlen(tech_pvt->at_query_signal)) {
-    res =
-      celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_query_signal, tech_pvt->at_query_signal_expect);
-    if (res) {
-      WARNINGA("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG,
-               tech_pvt->at_query_signal, tech_pvt->at_query_signal_expect);
-    }
-    usleep(1000);
-  }
-  //FIXME all the following commands in config!
+	if (strlen(tech_pvt->at_query_signal)) {
+		res = celliax_serial_write_AT_expect(tech_pvt, tech_pvt->at_query_signal, tech_pvt->at_query_signal_expect);
+		if (res) {
+			WARNINGA("%s does not get %s from the phone. Continuing.\n", SKYPIAX_P_LOG, tech_pvt->at_query_signal, tech_pvt->at_query_signal_expect);
+		}
+		usleep(1000);
+	}
+	//FIXME all the following commands in config!
 
-  if (tech_pvt->sms_cnmi_not_supported) {
-    res = celliax_serial_write_AT_ack(tech_pvt, "AT+MMGL=\"HEADER ONLY\"");
-    if (res) {
-      WARNINGA
-        ("%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",
-         SKYPIAX_P_LOG, "AT+MMGL=\"HEADER ONLY\"", "OK");
-    } else {
-      usleep(1000);
-      if (tech_pvt->unread_sms_msg_id) {
-        char at_command[256];
+	if (tech_pvt->sms_cnmi_not_supported) {
+		res = celliax_serial_write_AT_ack(tech_pvt, "AT+MMGL=\"HEADER ONLY\"");
+		if (res) {
+			WARNINGA
+				("%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",
+				 SKYPIAX_P_LOG, "AT+MMGL=\"HEADER ONLY\"", "OK");
+		} else {
+			usleep(1000);
+			if (tech_pvt->unread_sms_msg_id) {
+				char at_command[256];
 
-        if (tech_pvt->no_ucs2 == 0) {
-          res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"UCS2\"");
-          if (res) {
-            ERRORA
-              ("AT+CSCS=\"UCS2\" (set TE messages to ucs2)  do not got OK from the phone\n",
-               SKYPIAX_P_LOG);
-            memset(tech_pvt->sms_message, 0, sizeof(tech_pvt->sms_message));
-          }
-        }
+				if (tech_pvt->no_ucs2 == 0) {
+					res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"UCS2\"");
+					if (res) {
+						ERRORA("AT+CSCS=\"UCS2\" (set TE messages to ucs2)  do not got OK from the phone\n", SKYPIAX_P_LOG);
+						memset(tech_pvt->sms_message, 0, sizeof(tech_pvt->sms_message));
+					}
+				}
 
-        memset(at_command, 0, sizeof(at_command));
-        sprintf(at_command, "AT+CMGR=%d", tech_pvt->unread_sms_msg_id);
-        memset(tech_pvt->sms_message, 0, sizeof(tech_pvt->sms_message));
+				memset(at_command, 0, sizeof(at_command));
+				sprintf(at_command, "AT+CMGR=%d", tech_pvt->unread_sms_msg_id);
+				memset(tech_pvt->sms_message, 0, sizeof(tech_pvt->sms_message));
 
-        tech_pvt->reading_sms_msg = 1;
-        res = celliax_serial_write_AT_ack(tech_pvt, at_command);
-        tech_pvt->reading_sms_msg = 0;
-        if (res) {
-          ERRORA
-            ("AT+CMGR (read SMS) do not got OK from the phone, message sent was:|||%s|||\n",
-             SKYPIAX_P_LOG, at_command);
-        }
-        res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"GSM\"");
-        if (res) {
-          ERRORA
-            ("AT+CSCS=\"GSM\" (set TE messages to GSM) do not got OK from the phone\n",
-             SKYPIAX_P_LOG);
-        }
-        memset(at_command, 0, sizeof(at_command));
-        sprintf(at_command, "AT+CMGD=%d", tech_pvt->unread_sms_msg_id);    /* delete the message */
-        tech_pvt->unread_sms_msg_id = 0;
-        res = celliax_serial_write_AT_ack(tech_pvt, at_command);
-        if (res) {
-          ERRORA
-            ("AT+CMGD (Delete SMS) do not got OK from the phone, message sent was:|||%s|||\n",
-             SKYPIAX_P_LOG, at_command);
-        }
+				tech_pvt->reading_sms_msg = 1;
+				res = celliax_serial_write_AT_ack(tech_pvt, at_command);
+				tech_pvt->reading_sms_msg = 0;
+				if (res) {
+					ERRORA("AT+CMGR (read SMS) do not got OK from the phone, message sent was:|||%s|||\n", SKYPIAX_P_LOG, at_command);
+				}
+				res = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"GSM\"");
+				if (res) {
+					ERRORA("AT+CSCS=\"GSM\" (set TE messages to GSM) do not got OK from the phone\n", SKYPIAX_P_LOG);
+				}
+				memset(at_command, 0, sizeof(at_command));
+				sprintf(at_command, "AT+CMGD=%d", tech_pvt->unread_sms_msg_id);	/* delete the message */
+				tech_pvt->unread_sms_msg_id = 0;
+				res = celliax_serial_write_AT_ack(tech_pvt, at_command);
+				if (res) {
+					ERRORA("AT+CMGD (Delete SMS) do not got OK from the phone, message sent was:|||%s|||\n", SKYPIAX_P_LOG, at_command);
+				}
 
-        if (strlen(tech_pvt->sms_message)) {
+				if (strlen(tech_pvt->sms_message)) {
 
-          manager_event(EVENT_FLAG_SYSTEM, "CELLIAXincomingsms",
-                        "Interface: %s\r\nSMS_Message: %s\r\n", tech_pvt->name, tech_pvt->sms_message);
+					manager_event(EVENT_FLAG_SYSTEM, "CELLIAXincomingsms", "Interface: %s\r\nSMS_Message: %s\r\n", tech_pvt->name, tech_pvt->sms_message);
 
-          if (strlen(tech_pvt->sms_receiving_program)) {
-            int fd1[2];
-            pid_t pid1;
-            char *arg1[] = { tech_pvt->sms_receiving_program, (char *) NULL };
-            int i;
+					if (strlen(tech_pvt->sms_receiving_program)) {
+						int fd1[2];
+						pid_t pid1;
+						char *arg1[] = { tech_pvt->sms_receiving_program, (char *) NULL };
+						int i;
 
-            NOTICA("incoming SMS message:>>>%s<<<\n", SKYPIAX_P_LOG, tech_pvt->sms_message);
-            pipe(fd1);
-            pid1 = fork();
+						NOTICA("incoming SMS message:>>>%s<<<\n", SKYPIAX_P_LOG, tech_pvt->sms_message);
+						pipe(fd1);
+						pid1 = fork();
 
-            if (pid1 == 0) {    //child
-              int err;
+						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
-                  ("'sms_receiving_program' is set in config file to '%s', and it gave us back this error: %d, (%s). SMS received was:---%s---\n",
-                   SKYPIAX_P_LOG, tech_pvt->sms_receiving_program, err, strerror(errno),
-                   tech_pvt->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 < strlen(tech_pvt->sms_message); i++) {
-              write(fd1[1], &tech_pvt->sms_message[i], 1);
-            }
-            close(fd1[1]);      // close pipe input, let our program know we've finished
-          } else {
-            ERRORA
-              ("got SMS incoming message, but 'sms_receiving_program' is not set in config file. SMS received was:---%s---\n",
-               SKYPIAX_P_LOG, tech_pvt->sms_message);
-          }
-        }
-#if 1                           //is this one needed? maybe it can interrupt an incoming call that is just to announce itself
-        if (tech_pvt->phone_callflow == CALLFLOW_CALL_IDLE
-            && tech_pvt->interface_state == SKYPIAX_STATE_DOWN && tech_pvt->owner == NULL) {
-          /* we're not in a call, neither calling */
-          res = celliax_serial_write_AT_ack(tech_pvt, "AT+CKPD=\"EEE\"");
-          if (res) {
-            ERRORA
-              ("AT+CKPD=\"EEE\" (cellphone screen back to user) do not got OK from the phone\n",
-               SKYPIAX_P_LOG);
-          }
-        }
+							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
+									("'sms_receiving_program' is set in config file to '%s', and it gave us back this error: %d, (%s). SMS received was:---%s---\n",
+									 SKYPIAX_P_LOG, tech_pvt->sms_receiving_program, err, strerror(errno), tech_pvt->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 < strlen(tech_pvt->sms_message); i++) {
+							write(fd1[1], &tech_pvt->sms_message[i], 1);
+						}
+						close(fd1[1]);	// close pipe input, let our program know we've finished
+					} else {
+						ERRORA
+							("got SMS incoming message, but 'sms_receiving_program' is not set in config file. SMS received was:---%s---\n",
+							 SKYPIAX_P_LOG, tech_pvt->sms_message);
+					}
+				}
+#if 1							//is this one needed? maybe it can interrupt an incoming call that is just to announce itself
+				if (tech_pvt->phone_callflow == CALLFLOW_CALL_IDLE && tech_pvt->interface_state == SKYPIAX_STATE_DOWN && tech_pvt->owner == NULL) {
+					/* we're not in a call, neither calling */
+					res = celliax_serial_write_AT_ack(tech_pvt, "AT+CKPD=\"EEE\"");
+					if (res) {
+						ERRORA("AT+CKPD=\"EEE\" (cellphone screen back to user) do not got OK from the phone\n", SKYPIAX_P_LOG);
+					}
+				}
 #endif
-      }
-    }
-  }
+			}
+		}
+	}
 
-  UNLOCKA(tech_pvt->controldev_lock);
-  POPPA_UNLOCKA(tech_pvt->controldev_lock);
-  return 0;
+	UNLOCKA(tech_pvt->controldev_lock);
+	POPPA_UNLOCKA(tech_pvt->controldev_lock);
+	return 0;
 }
 
 
 
 
-#endif// NOTDEF
+#endif // NOTDEF
 
 
 #define SKYPIAX_ALSA
@@ -3843,28 +3658,28 @@
  */
 int alsa_init(private_t * tech_pvt)
 {
-  tech_pvt->alsac = alsa_open_dev(tech_pvt, SND_PCM_STREAM_CAPTURE);
-  if (!tech_pvt->alsac) {
-    ERRORA("Failed opening ALSA capture device: %s\n", SKYPIAX_P_LOG, tech_pvt->alsacname);
-    if (alsa_shutdown(tech_pvt)) {
-      ERRORA("alsa_shutdown failed\n", SKYPIAX_P_LOG);
-      return -1;
-    }
-    return -1;
-  }
-  tech_pvt->alsap = alsa_open_dev(tech_pvt, SND_PCM_STREAM_PLAYBACK);
-  if (!tech_pvt->alsap) {
-    ERRORA("Failed opening ALSA playback device: %s\n", SKYPIAX_P_LOG, tech_pvt->alsapname);
-    if (alsa_shutdown(tech_pvt)) {
-      ERRORA("alsa_shutdown failed\n", SKYPIAX_P_LOG);
-      return -1;
-    }
-    return -1;
-  }
+	tech_pvt->alsac = alsa_open_dev(tech_pvt, SND_PCM_STREAM_CAPTURE);
+	if (!tech_pvt->alsac) {
+		ERRORA("Failed opening ALSA capture device: %s\n", SKYPIAX_P_LOG, tech_pvt->alsacname);
+		if (alsa_shutdown(tech_pvt)) {
+			ERRORA("alsa_shutdown failed\n", SKYPIAX_P_LOG);
+			return -1;
+		}
+		return -1;
+	}
+	tech_pvt->alsap = alsa_open_dev(tech_pvt, SND_PCM_STREAM_PLAYBACK);
+	if (!tech_pvt->alsap) {
+		ERRORA("Failed opening ALSA playback device: %s\n", SKYPIAX_P_LOG, tech_pvt->alsapname);
+		if (alsa_shutdown(tech_pvt)) {
+			ERRORA("alsa_shutdown failed\n", SKYPIAX_P_LOG);
+			return -1;
+		}
+		return -1;
+	}
 
-  /* make valgrind very happy */
-  snd_config_update_free_global();
-  return 0;
+	/* make valgrind very happy */
+	snd_config_update_free_global();
+	return 0;
 }
 
 /*!
@@ -3879,38 +3694,34 @@
 int alsa_shutdown(private_t * tech_pvt)
 {
 
-  int err;
+	int err;
 
-  if (tech_pvt->alsap) {
-    err = snd_pcm_drop(tech_pvt->alsap);
-    if (err < 0) {
-      ERRORA("device [%s], snd_pcm_drop failed with error '%s'\n", SKYPIAX_P_LOG,
-             tech_pvt->alsapname, snd_strerror(err));
-      return -1;
-    }
-    err = snd_pcm_close(tech_pvt->alsap);
-    if (err < 0) {
-      ERRORA("device [%s], snd_pcm_close failed with error '%s'\n", SKYPIAX_P_LOG,
-             tech_pvt->alsapname, snd_strerror(err));
-      return -1;
-    }
-  }
-  if (tech_pvt->alsac) {
-    err = snd_pcm_drop(tech_pvt->alsac);
-    if (err < 0) {
-      ERRORA("device [%s], snd_pcm_drop failed with error '%s'\n", SKYPIAX_P_LOG,
-             tech_pvt->alsacname, snd_strerror(err));
-      return -1;
-    }
-    err = snd_pcm_close(tech_pvt->alsac);
-    if (err < 0) {
-      ERRORA("device [%s], snd_pcm_close failed with error '%s'\n", SKYPIAX_P_LOG,
-             tech_pvt->alsacname, snd_strerror(err));
-      return -1;
-    }
-  }
+	if (tech_pvt->alsap) {
+		err = snd_pcm_drop(tech_pvt->alsap);
+		if (err < 0) {
+			ERRORA("device [%s], snd_pcm_drop failed with error '%s'\n", SKYPIAX_P_LOG, tech_pvt->alsapname, snd_strerror(err));
+			return -1;
+		}
+		err = snd_pcm_close(tech_pvt->alsap);
+		if (err < 0) {
+			ERRORA("device [%s], snd_pcm_close failed with error '%s'\n", SKYPIAX_P_LOG, tech_pvt->alsapname, snd_strerror(err));
+			return -1;
+		}
+	}
+	if (tech_pvt->alsac) {
+		err = snd_pcm_drop(tech_pvt->alsac);
+		if (err < 0) {
+			ERRORA("device [%s], snd_pcm_drop failed with error '%s'\n", SKYPIAX_P_LOG, tech_pvt->alsacname, snd_strerror(err));
+			return -1;
+		}
+		err = snd_pcm_close(tech_pvt->alsac);
+		if (err < 0) {
+			ERRORA("device [%s], snd_pcm_close failed with error '%s'\n", SKYPIAX_P_LOG, tech_pvt->alsacname, snd_strerror(err));
+			return -1;
+		}
+	}
 
-  return 0;
+	return 0;
 }
 
 /*!
@@ -3925,328 +3736,320 @@
 snd_pcm_t *alsa_open_dev(private_t * tech_pvt, 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;
+	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 = tech_pvt->alsa_period_size;
+	period_size = tech_pvt->alsa_period_size;
 
-  snd_pcm_hw_params_alloca(&params);
-  snd_pcm_sw_params_alloca(&swparams);
+	snd_pcm_hw_params_alloca(&params);
+	snd_pcm_sw_params_alloca(&swparams);
 
-  if (stream == SND_PCM_STREAM_CAPTURE) {
-    err = snd_pcm_open(&handle, tech_pvt->alsacname, stream, 0 | SND_PCM_NONBLOCK);
-  } else {
-    err = snd_pcm_open(&handle, tech_pvt->alsapname, stream, 0 | SND_PCM_NONBLOCK);
-  }
-  if (err < 0) {
-    ERRORA
-      ("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"
-       " is running?\n", SKYPIAX_P_LOG, snd_strerror(err),
-       stream == SND_PCM_STREAM_CAPTURE ? tech_pvt->alsacname : tech_pvt->alsapname);
-    return NULL;
-  }
+	if (stream == SND_PCM_STREAM_CAPTURE) {
+		err = snd_pcm_open(&handle, tech_pvt->alsacname, stream, 0 | SND_PCM_NONBLOCK);
+	} else {
+		err = snd_pcm_open(&handle, tech_pvt->alsapname, stream, 0 | SND_PCM_NONBLOCK);
+	}
+	if (err < 0) {
+		ERRORA
+			("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"
+			 " is running?\n", SKYPIAX_P_LOG, snd_strerror(err), stream == SND_PCM_STREAM_CAPTURE ? tech_pvt->alsacname : tech_pvt->alsapname);
+		return NULL;
+	}
 
-  snd_pcm_info_alloca(&info);
+	snd_pcm_info_alloca(&info);
 
-  if ((err = snd_pcm_info(handle, info)) < 0) {
-    ERRORA("info error: %s", SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
+	if ((err = snd_pcm_info(handle, info)) < 0) {
+		ERRORA("info error: %s", SKYPIAX_P_LOG, snd_strerror(err));
+		return NULL;
+	}
 
-  err = snd_pcm_nonblock(handle, 1);
-  if (err < 0) {
-    ERRORA("nonblock setting error: %s", SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
+	err = snd_pcm_nonblock(handle, 1);
+	if (err < 0) {
+		ERRORA("nonblock setting error: %s", SKYPIAX_P_LOG, snd_strerror(err));
+		return NULL;
+	}
 
-  err = snd_pcm_hw_params_any(handle, params);
-  if (err < 0) {
-    ERRORA("Broken configuration for this PCM, no configurations available: %s\n",
-           SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
+	err = snd_pcm_hw_params_any(handle, params);
+	if (err < 0) {
+		ERRORA("Broken configuration for this PCM, no configurations available: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+		return NULL;
+	}
 
-  err = snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);
-  if (err < 0) {
-    ERRORA("Access type not available: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-  err = snd_pcm_hw_params_set_format(handle, params, celliax_format);
-  if (err < 0) {
-    ERRORA("Sample format non available: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-  err = snd_pcm_hw_params_set_channels(handle, params, 1);
-  if (err < 0) {
-    DEBUGA_SKYPE("Channels count set failed: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-  }
+	err = snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);
+	if (err < 0) {
+		ERRORA("Access type not available: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+		return NULL;
+	}
+	err = snd_pcm_hw_params_set_format(handle, params, celliax_format);
+	if (err < 0) {
+		ERRORA("Sample format non available: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+		return NULL;
+	}
+	err = snd_pcm_hw_params_set_channels(handle, params, 1);
+	if (err < 0) {
+		DEBUGA_SKYPE("Channels count set failed: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+	}
 #if 1
-  unsigned int chan_num;
-  err = snd_pcm_hw_params_get_channels(params, &chan_num);
-  if (err < 0) {
-    ERRORA("Channels count non available: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-  if (chan_num < 1 || chan_num > 2) {
-    ERRORA("Channels count MUST BE 1 or 2, it is: %d\n", SKYPIAX_P_LOG, chan_num);
-    ERRORA("Channels count MUST BE 1 or 2, it is: %d on %s %s\n", SKYPIAX_P_LOG, chan_num,
-           tech_pvt->alsapname, tech_pvt->alsacname);
-    return NULL;
-  } else {
-    if (chan_num == 1) {
-      if (stream == SND_PCM_STREAM_CAPTURE)
-        tech_pvt->alsa_capture_is_mono = 1;
-      else
-        tech_pvt->alsa_play_is_mono = 1;
-    } else {
-      if (stream == SND_PCM_STREAM_CAPTURE)
-        tech_pvt->alsa_capture_is_mono = 0;
-      else
-        tech_pvt->alsa_play_is_mono = 0;
-    }
-  }
+	unsigned int chan_num;
+	err = snd_pcm_hw_params_get_channels(params, &chan_num);
+	if (err < 0) {
+		ERRORA("Channels count non available: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+		return NULL;
+	}
+	if (chan_num < 1 || chan_num > 2) {
+		ERRORA("Channels count MUST BE 1 or 2, it is: %d\n", SKYPIAX_P_LOG, chan_num);
+		ERRORA("Channels count MUST BE 1 or 2, it is: %d on %s %s\n", SKYPIAX_P_LOG, chan_num, tech_pvt->alsapname, tech_pvt->alsacname);
+		return NULL;
+	} else {
+		if (chan_num == 1) {
+			if (stream == SND_PCM_STREAM_CAPTURE)
+				tech_pvt->alsa_capture_is_mono = 1;
+			else
+				tech_pvt->alsa_play_is_mono = 1;
+		} else {
+			if (stream == SND_PCM_STREAM_CAPTURE)
+				tech_pvt->alsa_capture_is_mono = 0;
+			else
+				tech_pvt->alsa_play_is_mono = 0;
+		}
+	}
 #else
-  tech_pvt->alsa_capture_is_mono = 1;
-  tech_pvt->alsa_play_is_mono = 1;
+	tech_pvt->alsa_capture_is_mono = 1;
+	tech_pvt->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;
+	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 && buffer_frames == 0) {
-    err = snd_pcm_hw_params_get_buffer_time_max(params, &buffer_time, 0);
-    assert(err >= 0);
-    if (buffer_time > 500000)
-      buffer_time = 500000;
-  }
-  if (period_time == 0 && period_frames == 0) {
-    if (buffer_time > 0)
-      period_time = buffer_time / 4;
-    else
-      period_frames = buffer_frames / 4;
-  }
-  if (period_time > 0)
-    err = snd_pcm_hw_params_set_period_time_near(handle, params, &period_time, 0);
-  else
-    err = snd_pcm_hw_params_set_period_size_near(handle, params, &period_frames, 0);
-  assert(err >= 0);
-  if (buffer_time > 0) {
-    err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, 0);
-  } else {
-    err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &buffer_frames);
-  }
+	if (buffer_time == 0 && buffer_frames == 0) {
+		err = snd_pcm_hw_params_get_buffer_time_max(params, &buffer_time, 0);
+		assert(err >= 0);
+		if (buffer_time > 500000)
+			buffer_time = 500000;
+	}
+	if (period_time == 0 && period_frames == 0) {
+		if (buffer_time > 0)
+			period_time = buffer_time / 4;
+		else
+			period_frames = buffer_frames / 4;
+	}
+	if (period_time > 0)
+		err = snd_pcm_hw_params_set_period_time_near(handle, params, &period_time, 0);
+	else
+		err = snd_pcm_hw_params_set_period_size_near(handle, params, &period_frames, 0);
+	assert(err >= 0);
+	if (buffer_time > 0) {
+		err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, 0);
+	} else {
+		err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &buffer_frames);
+	}
 #endif
 
 #if 1
-  rate = tech_pvt->celliax_sound_rate;
-  err = snd_pcm_hw_params_set_rate_near(handle, params, &rate, 0);
-  if ((float) tech_pvt->celliax_sound_rate * 1.05 < rate
-      || (float) tech_pvt->celliax_sound_rate * 0.95 > rate) {
-    WARNINGA("Rate is not accurate (requested = %iHz, got = %iHz)\n", SKYPIAX_P_LOG,
-             tech_pvt->celliax_sound_rate, rate);
-  }
+	rate = tech_pvt->celliax_sound_rate;
+	err = snd_pcm_hw_params_set_rate_near(handle, params, &rate, 0);
+	if ((float) tech_pvt->celliax_sound_rate * 1.05 < rate || (float) tech_pvt->celliax_sound_rate * 0.95 > rate) {
+		WARNINGA("Rate is not accurate (requested = %iHz, got = %iHz)\n", SKYPIAX_P_LOG, tech_pvt->celliax_sound_rate, rate);
+	}
 
-  if (err < 0) {
-    ERRORA("Error setting rate: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-  tech_pvt->celliax_sound_rate = rate;
+	if (err < 0) {
+		ERRORA("Error setting rate: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+		return NULL;
+	}
+	tech_pvt->celliax_sound_rate = rate;
 
-  err = snd_pcm_hw_params_set_period_size_near(handle, params, &period_size, 0);
+	err = snd_pcm_hw_params_set_period_size_near(handle, params, &period_size, 0);
 
-  if (err < 0) {
-    ERRORA("Error setting period_size: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
+	if (err < 0) {
+		ERRORA("Error setting period_size: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+		return NULL;
+	}
 
-  tech_pvt->alsa_period_size = period_size;
+	tech_pvt->alsa_period_size = period_size;
 
-  tech_pvt->alsa_buffer_size = tech_pvt->alsa_period_size * tech_pvt->alsa_periods_in_buffer;
+	tech_pvt->alsa_buffer_size = tech_pvt->alsa_period_size * tech_pvt->alsa_periods_in_buffer;
 
-  err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &tech_pvt->alsa_buffer_size);
+	err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &tech_pvt->alsa_buffer_size);
 
-  if (err < 0) {
-    ERRORA("Error setting buffer_size: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
+	if (err < 0) {
+		ERRORA("Error setting buffer_size: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+		return NULL;
+	}
 #endif
 
-  err = snd_pcm_hw_params(handle, params);
-  if (err < 0) {
-    ERRORA("Unable to install hw params: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
+	err = snd_pcm_hw_params(handle, params);
+	if (err < 0) {
+		ERRORA("Unable to install hw params: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+		return NULL;
+	}
 
-  snd_pcm_hw_params_get_period_size(params, &chunk_size, 0);
-  snd_pcm_hw_params_get_buffer_size(params, &buffer_size);
-  if (chunk_size == buffer_size) {
-    ERRORA("Can't use period equal to buffer size (%lu == %lu)\n", SKYPIAX_P_LOG,
-           chunk_size, buffer_size);
-    return NULL;
-  }
+	snd_pcm_hw_params_get_period_size(params, &chunk_size, 0);
+	snd_pcm_hw_params_get_buffer_size(params, &buffer_size);
+	if (chunk_size == buffer_size) {
+		ERRORA("Can't use period equal to buffer size (%lu == %lu)\n", SKYPIAX_P_LOG, chunk_size, buffer_size);
+		return NULL;
+	}
 
-  snd_pcm_sw_params_current(handle, swparams);
+	snd_pcm_sw_params_current(handle, swparams);
 
 #if 0
-  err = snd_pcm_sw_params_get_xfer_align(swparams, &xfer_align);
-  if (err < 0) {
-    ERRORA("Unable to obtain xfer align: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-  }
-  NOTICA("xfer_align: %d\n", 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 = tech_pvt->alsa_period_size;
-  NOTICA("xfer_align: %d\n", SKYPIAX_P_LOG, xfer_align);
+	err = snd_pcm_sw_params_get_xfer_align(swparams, &xfer_align);
+	if (err < 0) {
+		ERRORA("Unable to obtain xfer align: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+	}
+	NOTICA("xfer_align: %d\n", 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 = tech_pvt->alsa_period_size;
+	NOTICA("xfer_align: %d\n", SKYPIAX_P_LOG, xfer_align);
 
-  err = snd_pcm_sw_params_set_xfer_align(handle, swparams, xfer_align);
-  if (err < 0) {
-    ERRORA("Error setting xfer_align: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-  }
-  NOTICA("xfer_align: %d\n", SKYPIAX_P_LOG, xfer_align);
+	err = snd_pcm_sw_params_set_xfer_align(handle, swparams, xfer_align);
+	if (err < 0) {
+		ERRORA("Error setting xfer_align: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+	}
+	NOTICA("xfer_align: %d\n", SKYPIAX_P_LOG, xfer_align);
 
-  err = snd_pcm_sw_params_get_xfer_align(swparams, &xfer_align);
-  if (err < 0) {
-    ERRORA("Unable to obtain xfer align: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-  }
-  NOTICA("xfer_align: %d\n", SKYPIAX_P_LOG, xfer_align);
+	err = snd_pcm_sw_params_get_xfer_align(swparams, &xfer_align);
+	if (err < 0) {
+		ERRORA("Unable to obtain xfer align: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+	}
+	NOTICA("xfer_align: %d\n", SKYPIAX_P_LOG, xfer_align);
 #endif
 
-  /*
-     if (sleep_min)
-     xfer_align = 1;
-     err = snd_pcm_sw_params_set_sleep_min(handle, swparams,
-     0);
+	/*
+	   if (sleep_min)
+	   xfer_align = 1;
+	   err = snd_pcm_sw_params_set_sleep_min(handle, swparams,
+	   0);
 
-     if (err < 0) {
-     ERRORA("Error setting slep_min: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-     }
-   */
-  n = chunk_size;
-  err = snd_pcm_sw_params_set_avail_min(handle, swparams, n);
-  if (err < 0) {
-    ERRORA("Error setting avail_min: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-  }
+	   if (err < 0) {
+	   ERRORA("Error setting slep_min: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+	   }
+	 */
+	n = chunk_size;
+	err = snd_pcm_sw_params_set_avail_min(handle, swparams, n);
+	if (err < 0) {
+		ERRORA("Error setting avail_min: %s\n", 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;
+	/* 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 <= 0) {
-    start_threshold = n + (double) rate *start_delay / 1000000;
-  } else {
-    start_threshold = (double) rate *start_delay / 1000000;
-  }
-  if (start_threshold < 1)
-    start_threshold = 1;
-  if (start_threshold > n)
-    start_threshold = n;
-  err = snd_pcm_sw_params_set_start_threshold(handle, swparams, start_threshold);
-  if (err < 0) {
-    ERRORA("Error setting start_threshold: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-  }
+	if (stream == SND_PCM_STREAM_CAPTURE) {
+		start_delay = 1;
+	}
+	if (start_delay <= 0) {
+		start_threshold = n + (double) rate *start_delay / 1000000;
+	} else {
+		start_threshold = (double) rate *start_delay / 1000000;
+	}
+	if (start_threshold < 1)
+		start_threshold = 1;
+	if (start_threshold > n)
+		start_threshold = n;
+	err = snd_pcm_sw_params_set_start_threshold(handle, swparams, start_threshold);
+	if (err < 0) {
+		ERRORA("Error setting start_threshold: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+	}
 
-  if (stop_delay <= 0)
-    stop_threshold = buffer_size + (double) rate *stop_delay / 1000000;
-  else
-    stop_threshold = (double) rate *stop_delay / 1000000;
+	if (stop_delay <= 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;
-  }
+	if (stream == SND_PCM_STREAM_CAPTURE) {
+		stop_threshold = -1;
+	}
 
-  err = snd_pcm_sw_params_set_stop_threshold(handle, swparams, stop_threshold);
+	err = snd_pcm_sw_params_set_stop_threshold(handle, swparams, stop_threshold);
 
-  if (err < 0) {
-    ERRORA("Error setting stop_threshold: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-  }
+	if (err < 0) {
+		ERRORA("Error setting stop_threshold: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+	}
 #if 0
-  err = snd_pcm_sw_params_set_xfer_align(handle, swparams, xfer_align);
+	err = snd_pcm_sw_params_set_xfer_align(handle, swparams, xfer_align);
 
-  if (err < 0) {
-    ERRORA("Error setting xfer_align: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-  }
+	if (err < 0) {
+		ERRORA("Error setting xfer_align: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+	}
 #endif
 
-  if (snd_pcm_sw_params(handle, swparams) < 0) {
-    ERRORA("Error installing software parameters: %s\n", SKYPIAX_P_LOG,
-           snd_strerror(err));
-  }
+	if (snd_pcm_sw_params(handle, swparams) < 0) {
+		ERRORA("Error installing software parameters: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+	}
 
-  err = snd_pcm_poll_descriptors_count(handle);
-  if (err <= 0) {
-    ERRORA("Unable to get a poll descriptors count, error is %s\n", SKYPIAX_P_LOG,
-           snd_strerror(err));
-    return NULL;
-  }
+	err = snd_pcm_poll_descriptors_count(handle);
+	if (err <= 0) {
+		ERRORA("Unable to get a poll descriptors count, error is %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+		return NULL;
+	}
 
-  if (err != 1) {               //number of poll descriptors
-    DEBUGA_SKYPE("Can't handle more than one device\n", SKYPIAX_P_LOG);
-    return NULL;
-  }
+	if (err != 1) {				//number of poll descriptors
+		DEBUGA_SKYPE("Can't handle more than one device\n", SKYPIAX_P_LOG);
+		return NULL;
+	}
 
-  err = snd_pcm_poll_descriptors(handle, &tech_pvt->pfd, err);
-  if (err != 1) {
-    ERRORA("snd_pcm_poll_descriptors failed, %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-    return NULL;
-  }
-  DEBUGA_SKYPE("Acquired fd %d from the poll descriptor\n", SKYPIAX_P_LOG, tech_pvt->pfd.fd);
+	err = snd_pcm_poll_descriptors(handle, &tech_pvt->pfd, err);
+	if (err != 1) {
+		ERRORA("snd_pcm_poll_descriptors failed, %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+		return NULL;
+	}
+	DEBUGA_SKYPE("Acquired fd %d from the poll descriptor\n", SKYPIAX_P_LOG, tech_pvt->pfd.fd);
 
-  if (stream == SND_PCM_STREAM_CAPTURE) {
-    tech_pvt->celliax_sound_capt_fd = tech_pvt->pfd.fd;
-  }
+	if (stream == SND_PCM_STREAM_CAPTURE) {
+		tech_pvt->celliax_sound_capt_fd = tech_pvt->pfd.fd;
+	}
 
-  state = snd_pcm_state(handle);
+	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("snd_pcm_prepare failed, %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-        return NULL;
-      }
-      DEBUGA_SKYPE("prepared!\n", SKYPIAX_P_LOG);
-    }
-    if (stream == SND_PCM_STREAM_CAPTURE) {
-      err = snd_pcm_start(handle);
-      if (err) {
-        ERRORA("snd_pcm_start failed, %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-        return NULL;
-      }
-      DEBUGA_SKYPE("started!\n", SKYPIAX_P_LOG);
-    }
-  }
-  if (option_debug > 1) {
-    snd_output_t *output = NULL;
-    err = snd_output_stdio_attach(&output, stdout, 0);
-    if (err < 0) {
-      ERRORA("snd_output_stdio_attach failed: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
-    }
-    snd_pcm_dump(handle, output);
-  }
-  if (option_debug > 1)
-    DEBUGA_SKYPE("ALSA handle = %ld\n", SKYPIAX_P_LOG, (long int) handle);
-  return handle;
+	if (state != SND_PCM_STATE_RUNNING) {
+		if (state != SND_PCM_STATE_PREPARED) {
+			err = snd_pcm_prepare(handle);
+			if (err) {
+				ERRORA("snd_pcm_prepare failed, %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+				return NULL;
+			}
+			DEBUGA_SKYPE("prepared!\n", SKYPIAX_P_LOG);
+		}
+		if (stream == SND_PCM_STREAM_CAPTURE) {
+			err = snd_pcm_start(handle);
+			if (err) {
+				ERRORA("snd_pcm_start failed, %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+				return NULL;
+			}
+			DEBUGA_SKYPE("started!\n", SKYPIAX_P_LOG);
+		}
+	}
+	if (option_debug > 1) {
+		snd_output_t *output = NULL;
+		err = snd_output_stdio_attach(&output, stdout, 0);
+		if (err < 0) {
+			ERRORA("snd_output_stdio_attach failed: %s\n", SKYPIAX_P_LOG, snd_strerror(err));
+		}
+		snd_pcm_dump(handle, output);
+	}
+	if (option_debug > 1)
+		DEBUGA_SKYPE("ALSA handle = %ld\n", SKYPIAX_P_LOG, (long int) handle);
+	return handle;
 
 }
 
@@ -4255,343 +4058,339 @@
 
 struct ast_frame *alsa_read(private_t * tech_pvt)
 {
-  static struct ast_frame f;
-  static short __buf[SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2];
-  static short __buf2[(SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2) * 2];
-  short *buf;
-  short *buf2;
-  static int readpos = 0;
-  static int left = SKYPIAX_FRAME_SIZE;
-  snd_pcm_state_t state;
-  int r = 0;
-  int off = 0;
-  int error = 0;
-  //time_t now_timestamp;
+	static struct ast_frame f;
+	static short __buf[SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2];
+	static short __buf2[(SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2) * 2];
+	short *buf;
+	short *buf2;
+	static int readpos = 0;
+	static int left = SKYPIAX_FRAME_SIZE;
+	snd_pcm_state_t state;
+	int r = 0;
+	int off = 0;
+	int error = 0;
+	//time_t now_timestamp;
 
-  //memset(&f, 0, sizeof(struct ast_frame)); //giova
+	//memset(&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;
+	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(tech_pvt->alsac);
-  if (state != SND_PCM_STATE_RUNNING) {
-    DEBUGA_SKYPE("ALSA read state is not SND_PCM_STATE_RUNNING\n", SKYPIAX_P_LOG);
+	state = snd_pcm_state(tech_pvt->alsac);
+	if (state != SND_PCM_STATE_RUNNING) {
+		DEBUGA_SKYPE("ALSA read state is not SND_PCM_STATE_RUNNING\n", SKYPIAX_P_LOG);
 
-    if (state != SND_PCM_STATE_PREPARED) {
-      error = snd_pcm_prepare(tech_pvt->alsac);
-      if (error) {
-        ERRORA("snd_pcm_prepare failed, %s\n", SKYPIAX_P_LOG, snd_strerror(error));
-        return &f;
-      }
-      DEBUGA_SKYPE("prepared!\n", SKYPIAX_P_LOG);
-    }
-    usleep(1000);
-    error = snd_pcm_start(tech_pvt->alsac);
-    if (error) {
-      ERRORA("snd_pcm_start failed, %s\n", SKYPIAX_P_LOG, snd_strerror(error));
-      return &f;
-    }
-    DEBUGA_SKYPE("started!\n", SKYPIAX_P_LOG);
-    usleep(1000);
-  }
+		if (state != SND_PCM_STATE_PREPARED) {
+			error = snd_pcm_prepare(tech_pvt->alsac);
+			if (error) {
+				ERRORA("snd_pcm_prepare failed, %s\n", SKYPIAX_P_LOG, snd_strerror(error));
+				return &f;
+			}
+			DEBUGA_SKYPE("prepared!\n", SKYPIAX_P_LOG);
+		}
+		usleep(1000);
+		error = snd_pcm_start(tech_pvt->alsac);
+		if (error) {
+			ERRORA("snd_pcm_start failed, %s\n", SKYPIAX_P_LOG, snd_strerror(error));
+			return &f;
+		}
+		DEBUGA_SKYPE("started!\n", SKYPIAX_P_LOG);
+		usleep(1000);
+	}
 
-  buf = __buf + AST_FRIENDLY_OFFSET / 2;
-  buf2 = __buf2 + ((AST_FRIENDLY_OFFSET / 2) * 2);
+	buf = __buf + AST_FRIENDLY_OFFSET / 2;
+	buf2 = __buf2 + ((AST_FRIENDLY_OFFSET / 2) * 2);
 
-  if (tech_pvt->alsa_capture_is_mono) {
-    r = snd_pcm_readi(tech_pvt->alsac, buf + readpos, left);
-  } else {
-    r = snd_pcm_readi(tech_pvt->alsac, buf2 + (readpos * 2), left);
+	if (tech_pvt->alsa_capture_is_mono) {
+		r = snd_pcm_readi(tech_pvt->alsac, buf + readpos, left);
+	} else {
+		r = snd_pcm_readi(tech_pvt->alsac, buf2 + (readpos * 2), left);
 
-    int a = 0;
-    int i = 0;
-    for (i = 0; i < (SKYPIAX_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++;
-    }
-  }
+		int a = 0;
+		int i = 0;
+		for (i = 0; i < (SKYPIAX_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("XRUN read\n\n\n\n\n", SKYPIAX_P_LOG);
-    return &f;
-  } else if (r == -ESTRPIPE) {
-    ERRORA("-ESTRPIPE\n", SKYPIAX_P_LOG);
-    return &f;
+	if (r == -EPIPE) {
+		ERRORA("XRUN read\n\n\n\n\n", SKYPIAX_P_LOG);
+		return &f;
+	} else if (r == -ESTRPIPE) {
+		ERRORA("-ESTRPIPE\n", SKYPIAX_P_LOG);
+		return &f;
 
-  } else if (r == -EAGAIN) {
-    DEBUGA_SKYPE("ALSA read -EAGAIN, the soundcard is not ready to be read by celliax\n",
-                 SKYPIAX_P_LOG);
-    while (r == -EAGAIN) {
-      usleep(1000);
+	} else if (r == -EAGAIN) {
+		DEBUGA_SKYPE("ALSA read -EAGAIN, the soundcard is not ready to be read by celliax\n", SKYPIAX_P_LOG);
+		while (r == -EAGAIN) {
+			usleep(1000);
 
-      if (tech_pvt->alsa_capture_is_mono) {
-        r = snd_pcm_readi(tech_pvt->alsac, buf + readpos, left);
-      } else {
-        r = snd_pcm_readi(tech_pvt->alsac, buf2 + (readpos * 2), left);
+			if (tech_pvt->alsa_capture_is_mono) {
+				r = snd_pcm_readi(tech_pvt->alsac, buf + readpos, left);
+			} else {
+				r = snd_pcm_readi(tech_pvt->alsac, buf2 + (readpos * 2), left);
 
-        int a = 0;
-        int i = 0;
-        for (i = 0; i < (SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2) * 2;) {
-          __buf[a] = (__buf2[i] + __buf2[i + 1]) / 2;
-          a++;
-          i++;
-          i++;
-        }
-      }
+				int a = 0;
+				int i = 0;
+				for (i = 0; i < (SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2) * 2;) {
+					__buf[a] = (__buf2[i] + __buf2[i + 1]) / 2;
+					a++;
+					i++;
+					i++;
+				}
+			}
 
-    }
-  } else if (r < 0) {
-    WARNINGA("ALSA Read error: %s\n", SKYPIAX_P_LOG, snd_strerror(r));
-  } else if (r >= 0) {
-    //DEBUGA_SKYPE("read: r=%d, readpos=%d, left=%d, off=%d\n", SKYPIAX_P_LOG, r, readpos, left, off);
-    off -= r;                   //what is the meaning of this? a leftover, probably
-  }
-  /* Update positions */
-  readpos += r;
-  left -= r;
+		}
+	} else if (r < 0) {
+		WARNINGA("ALSA Read error: %s\n", SKYPIAX_P_LOG, snd_strerror(r));
+	} else if (r >= 0) {
+		//DEBUGA_SKYPE("read: r=%d, readpos=%d, left=%d, off=%d\n", 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 >= SKYPIAX_FRAME_SIZE) {
-    /* A real frame */
-    readpos = 0;
-    left = SKYPIAX_FRAME_SIZE;
+	if (readpos >= SKYPIAX_FRAME_SIZE) {
+		/* A real frame */
+		readpos = 0;
+		left = SKYPIAX_FRAME_SIZE;
 
-    f.frametype = AST_FRAME_VOICE;
-    f.subclass = AST_FORMAT_SLINEAR;
-    f.samples = SKYPIAX_FRAME_SIZE;
-    f.datalen = SKYPIAX_FRAME_SIZE * 2;
-    f.data = buf;
-    f.offset = AST_FRIENDLY_OFFSET;
-    f.src = celliax_type;
-    f.mallocd = 0;
+		f.frametype = AST_FRAME_VOICE;
+		f.subclass = AST_FORMAT_SLINEAR;
+		f.samples = SKYPIAX_FRAME_SIZE;
+		f.datalen = SKYPIAX_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, SKYPIAX_FRAME_SIZE * 2);
+		alsa_monitor_read((char *) buf, SKYPIAX_FRAME_SIZE * 2);
 #endif
 
-  }
-  return &f;
+	}
+	return &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;
+	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->datalen > sizeof(sizbuf) - sizpos) {
-    ERRORA("Frame too large\n", SKYPIAX_P_LOG);
-    res = -1;
-  } else {
-    memcpy(sizbuf + sizpos, f->data, f->datalen);
-    len += f->datalen;
-    pos = 0;
+	/* We have to digest the frame in 160-byte portions */
+	if (f->datalen > sizeof(sizbuf) - sizpos) {
+		ERRORA("Frame too large\n", SKYPIAX_P_LOG);
+		res = -1;
+	} else {
+		memcpy(sizbuf + sizpos, f->data, f->datalen);
+		len += f->datalen;
+		pos = 0;
 #ifdef ALSA_MONITOR
-    alsa_monitor_write(sizbuf, len);
+		alsa_monitor_write(sizbuf, len);
 #endif
-    state = snd_pcm_state(tech_pvt->alsap);
-    if (state == SND_PCM_STATE_XRUN) {
-      int i;
+		state = snd_pcm_state(tech_pvt->alsap);
+		if (state == SND_PCM_STATE_XRUN) {
+			int i;
 
-      DEBUGA_SKYPE
-        ("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",
-         SKYPIAX_P_LOG, tech_pvt->alsa_periods_in_buffer);
-      res = snd_pcm_prepare(tech_pvt->alsap);
-      if (res) {
-        ERRORA("audio play prepare failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-      } else {
-        res = snd_pcm_format_set_silence(celliax_format, silencebuf, len / 2);
-        if (res < 0) {
-          DEBUGA_SKYPE("Silence error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-          res = -1;
-        }
-        for (i = 0; i < (tech_pvt->alsa_periods_in_buffer - 1); i++) {
-          res = snd_pcm_writei(tech_pvt->alsap, silencebuf, len / 2);
-          if (res != len / 2) {
-            DEBUGA_SKYPE("Write returned a different quantity: %d\n", SKYPIAX_P_LOG, res);
-            res = -1;
-          } else if (res < 0) {
-            DEBUGA_SKYPE("Write error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-            res = -1;
-          }
-        }
-      }
+			DEBUGA_SKYPE
+				("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",
+				 SKYPIAX_P_LOG, tech_pvt->alsa_periods_in_buffer);
+			res = snd_pcm_prepare(tech_pvt->alsap);
+			if (res) {
+				ERRORA("audio play prepare failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+			} else {
+				res = snd_pcm_format_set_silence(celliax_format, silencebuf, len / 2);
+				if (res < 0) {
+					DEBUGA_SKYPE("Silence error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+					res = -1;
+				}
+				for (i = 0; i < (tech_pvt->alsa_periods_in_buffer - 1); i++) {
+					res = snd_pcm_writei(tech_pvt->alsap, silencebuf, len / 2);
+					if (res != len / 2) {
+						DEBUGA_SKYPE("Write returned a different quantity: %d\n", SKYPIAX_P_LOG, res);
+						res = -1;
+					} else if (res < 0) {
+						DEBUGA_SKYPE("Write error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+						res = -1;
+					}
+				}
+			}
 
-    }
+		}
 
-    res = snd_pcm_delay(tech_pvt->alsap, &delayp1);
-    if (res < 0) {
-      DEBUGA_SKYPE("Error %d on snd_pcm_delay: \"%s\"\n", SKYPIAX_P_LOG, res,
-                   snd_strerror(res));
-      res = snd_pcm_prepare(tech_pvt->alsap);
-      if (res) {
-        DEBUGA_SKYPE("snd_pcm_prepare failed: '%s'\n", SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      res = snd_pcm_delay(tech_pvt->alsap, &delayp1);
-    }
+		res = snd_pcm_delay(tech_pvt->alsap, &delayp1);
+		if (res < 0) {
+			DEBUGA_SKYPE("Error %d on snd_pcm_delay: \"%s\"\n", SKYPIAX_P_LOG, res, snd_strerror(res));
+			res = snd_pcm_prepare(tech_pvt->alsap);
+			if (res) {
+				DEBUGA_SKYPE("snd_pcm_prepare failed: '%s'\n", SKYPIAX_P_LOG, snd_strerror(res));
+			}
+			res = snd_pcm_delay(tech_pvt->alsap, &delayp1);
+		}
 
-    delayp2 = snd_pcm_avail_update(tech_pvt->alsap);
-    if (delayp2 < 0) {
-      DEBUGA_SKYPE("Error %d on snd_pcm_avail_update: \"%s\"\n", SKYPIAX_P_LOG,
-                   (int) delayp2, snd_strerror(delayp2));
+		delayp2 = snd_pcm_avail_update(tech_pvt->alsap);
+		if (delayp2 < 0) {
+			DEBUGA_SKYPE("Error %d on snd_pcm_avail_update: \"%s\"\n", SKYPIAX_P_LOG, (int) delayp2, snd_strerror(delayp2));
 
-      res = snd_pcm_prepare(tech_pvt->alsap);
-      if (res) {
-        DEBUGA_SKYPE("snd_pcm_prepare failed: '%s'\n", SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      delayp2 = snd_pcm_avail_update(tech_pvt->alsap);
-    }
+			res = snd_pcm_prepare(tech_pvt->alsap);
+			if (res) {
+				DEBUGA_SKYPE("snd_pcm_prepare failed: '%s'\n", SKYPIAX_P_LOG, snd_strerror(res));
+			}
+			delayp2 = snd_pcm_avail_update(tech_pvt->alsap);
+		}
 
-    if (                        /* delayp1 != 0 && delayp1 != 160 */
-         delayp1 < 160 || delayp2 > tech_pvt->alsa_buffer_size) {
+		if (					/* delayp1 != 0 && delayp1 != 160 */
+			   delayp1 < 160 || delayp2 > tech_pvt->alsa_buffer_size) {
 
-      res = snd_pcm_prepare(tech_pvt->alsap);
-      if (res) {
-        DEBUGA_SKYPE
-          ("snd_pcm_prepare failed while trying to prevent an ALSA write XRUN: %s, delayp1=%d, delayp2=%d\n",
-           SKYPIAX_P_LOG, snd_strerror(res), (int) delayp1, (int) delayp2);
-      } else {
+			res = snd_pcm_prepare(tech_pvt->alsap);
+			if (res) {
+				DEBUGA_SKYPE
+					("snd_pcm_prepare failed while trying to prevent an ALSA write XRUN: %s, delayp1=%d, delayp2=%d\n",
+					 SKYPIAX_P_LOG, snd_strerror(res), (int) delayp1, (int) delayp2);
+			} else {
 
-        int i;
-        for (i = 0; i < (tech_pvt->alsa_periods_in_buffer - 1); i++) {
-          res = snd_pcm_format_set_silence(celliax_format, silencebuf, len / 2);
-          if (res < 0) {
-            DEBUGA_SKYPE("Silence error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-            res = -1;
-          }
-          res = snd_pcm_writei(tech_pvt->alsap, silencebuf, len / 2);
-          if (res < 0) {
-            DEBUGA_SKYPE("Write error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-            res = -1;
-          } else if (res != len / 2) {
-            DEBUGA_SKYPE("Write returned a different quantity: %d\n", SKYPIAX_P_LOG, res);
-            res = -1;
-          }
-        }
+				int i;
+				for (i = 0; i < (tech_pvt->alsa_periods_in_buffer - 1); i++) {
+					res = snd_pcm_format_set_silence(celliax_format, silencebuf, len / 2);
+					if (res < 0) {
+						DEBUGA_SKYPE("Silence error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+						res = -1;
+					}
+					res = snd_pcm_writei(tech_pvt->alsap, silencebuf, len / 2);
+					if (res < 0) {
+						DEBUGA_SKYPE("Write error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+						res = -1;
+					} else if (res != len / 2) {
+						DEBUGA_SKYPE("Write returned a different quantity: %d\n", SKYPIAX_P_LOG, res);
+						res = -1;
+					}
+				}
 
-        DEBUGA_SKYPE
-          ("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",
-           SKYPIAX_P_LOG, tech_pvt->alsa_periods_in_buffer, (int) delayp1, (int) delayp2);
-      }
+				DEBUGA_SKYPE
+					("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",
+					 SKYPIAX_P_LOG, tech_pvt->alsa_periods_in_buffer, (int) delayp1, (int) delayp2);
+			}
 
-    }
+		}
 
-    memset(sizbuf2, 0, sizeof(sizbuf2));
-    if (tech_pvt->alsa_play_is_mono) {
-    ERRORA("data=%p, datalen=%d, sizbuf=%p, len/2=%d\n", SKYPIAX_P_LOG, (void *)data, datalen, (void *)sizbuf, len/2);
-      res = snd_pcm_writei(tech_pvt->alsap, sizbuf, len / 2);
-    } else {
-      int a = 0;
-      int i = 0;
-      for (i = 0; i < 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(tech_pvt->alsap, sizbuf2, len);
-    }
-    if (res == -EPIPE) {
-      DEBUGA_SKYPE
-        ("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",
-         SKYPIAX_P_LOG, tech_pvt->alsa_periods_in_buffer, (int) delayp1, (int) delayp2);
-      res = snd_pcm_prepare(tech_pvt->alsap);
-      if (res) {
-        ERRORA("audio play prepare failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-      } else {
+		memset(sizbuf2, 0, sizeof(sizbuf2));
+		if (tech_pvt->alsa_play_is_mono) {
+			ERRORA("data=%p, datalen=%d, sizbuf=%p, len/2=%d\n", SKYPIAX_P_LOG, (void *) data, datalen, (void *) sizbuf, len / 2);
+			res = snd_pcm_writei(tech_pvt->alsap, sizbuf, len / 2);
+		} else {
+			int a = 0;
+			int i = 0;
+			for (i = 0; i < 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(tech_pvt->alsap, sizbuf2, len);
+		}
+		if (res == -EPIPE) {
+			DEBUGA_SKYPE
+				("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",
+				 SKYPIAX_P_LOG, tech_pvt->alsa_periods_in_buffer, (int) delayp1, (int) delayp2);
+			res = snd_pcm_prepare(tech_pvt->alsap);
+			if (res) {
+				ERRORA("audio play prepare failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+			} else {
 
-        if (tech_pvt->alsa_play_is_mono) {
-          res = snd_pcm_writei(tech_pvt->alsap, sizbuf, len / 2);
-        } else {
-          int a = 0;
-          int i = 0;
-          for (i = 0; i < 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(tech_pvt->alsap, sizbuf2, len);
-        }
+				if (tech_pvt->alsa_play_is_mono) {
+					res = snd_pcm_writei(tech_pvt->alsap, sizbuf, len / 2);
+				} else {
+					int a = 0;
+					int i = 0;
+					for (i = 0; i < 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(tech_pvt->alsap, sizbuf2, len);
+				}
 
-      }
+			}
 
-    } else {
-      if (res == -ESTRPIPE) {
-        ERRORA("You've got some big problems\n", SKYPIAX_P_LOG);
-      } else if (res == -EAGAIN) {
-        res = 0;
-      } else if (res < 0) {
-        ERRORA("Error %d on audio write: \"%s\"\n", SKYPIAX_P_LOG, res,
-               snd_strerror(res));
-      }
-    }
-  }
+		} else {
+			if (res == -ESTRPIPE) {
+				ERRORA("You've got some big problems\n", SKYPIAX_P_LOG);
+			} else if (res == -EAGAIN) {
+				res = 0;
+			} else if (res < 0) {
+				ERRORA("Error %d on audio write: \"%s\"\n", SKYPIAX_P_LOG, res, snd_strerror(res));
+			}
+		}
+	}
 
-  if (tech_pvt->audio_play_reset_period) {
-    time(&now_timestamp);
-    if ((now_timestamp - tech_pvt->audio_play_reset_timestamp) > tech_pvt->audio_play_reset_period) {
-      if (option_debug)
-        DEBUGA_SKYPE("reset audio play\n", SKYPIAX_P_LOG);
-      res = snd_pcm_wait(tech_pvt->alsap, 1000);
-      if (res < 0) {
-        ERRORA("audio play wait failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      res = snd_pcm_drop(tech_pvt->alsap);
-      if (res) {
-        ERRORA("audio play drop failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      res = snd_pcm_prepare(tech_pvt->alsap);
-      if (res) {
-        ERRORA("audio play prepare failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      res = snd_pcm_wait(tech_pvt->alsap, 1000);
-      if (res < 0) {
-        ERRORA("audio play wait failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      time(&tech_pvt->audio_play_reset_timestamp);
-    }
-  }
-  res = 0;
-  if (res > 0)
-    res = 0;
-  return res;
+	if (tech_pvt->audio_play_reset_period) {
+		time(&now_timestamp);
+		if ((now_timestamp - tech_pvt->audio_play_reset_timestamp) > tech_pvt->audio_play_reset_period) {
+			if (option_debug)
+				DEBUGA_SKYPE("reset audio play\n", SKYPIAX_P_LOG);
+			res = snd_pcm_wait(tech_pvt->alsap, 1000);
+			if (res < 0) {
+				ERRORA("audio play wait failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+			}
+			res = snd_pcm_drop(tech_pvt->alsap);
+			if (res) {
+				ERRORA("audio play drop failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+			}
+			res = snd_pcm_prepare(tech_pvt->alsap);
+			if (res) {
+				ERRORA("audio play prepare failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+			}
+			res = snd_pcm_wait(tech_pvt->alsap, 1000);
+			if (res < 0) {
+				ERRORA("audio play wait failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+			}
+			time(&tech_pvt->audio_play_reset_timestamp);
+		}
+	}
+	res = 0;
+	if (res > 0)
+		res = 0;
+	return res;
 }
 
 #endif //NOTDEF
@@ -4610,11 +4409,11 @@
 	//celliax_signaling_write(tech_pvt, "SET AEC OFF");
 	//celliax_sleep(10000);
 
-celliax_serial_call(tech_pvt, rdest);
+	celliax_serial_call(tech_pvt, rdest);
 	//sprintf(msg_to_skype, "CALL %s", rdest);
 	//if (celliax_signaling_write(tech_pvt, msg_to_skype) < 0) {
-		//ERRORA("failed to communicate with Skype client, now exit\n", SKYPIAX_P_LOG);
-		//return -1;
+	//ERRORA("failed to communicate with Skype client, now exit\n", SKYPIAX_P_LOG);
+	//return -1;
 	//}
 	return 0;
 }
@@ -4625,305 +4424,302 @@
 
 	DEBUGA_SKYPE("DIGIT received: %c\n", SKYPIAX_P_LOG, digit);
 	//celliax_signaling_write(tech_pvt, msg_to_skype);
-  if (tech_pvt->controldevprotocol == PROTOCOL_AT && tech_pvt->at_send_dtmf[0]) {
-    int res = 0;
-    char at_command[256];
+	if (tech_pvt->controldevprotocol == PROTOCOL_AT && tech_pvt->at_send_dtmf[0]) {
+		int res = 0;
+		char at_command[256];
 
-    memset(at_command, '\0', 256);
-    sprintf(at_command, "%s=\"%c\"", tech_pvt->at_send_dtmf, digit);
-    res = celliax_serial_write_AT_ack(tech_pvt, at_command);
-    if (res) {
-      ERRORA("senddigit command failed, command used: '%s=\"%c\"', giving up\n",
-             SKYPIAX_P_LOG, tech_pvt->at_send_dtmf, digit);
-    }
-  }
+		memset(at_command, '\0', 256);
+		sprintf(at_command, "%s=\"%c\"", tech_pvt->at_send_dtmf, digit);
+		res = celliax_serial_write_AT_ack(tech_pvt, at_command);
+		if (res) {
+			ERRORA("senddigit command failed, command used: '%s=\"%c\"', giving up\n", SKYPIAX_P_LOG, tech_pvt->at_send_dtmf, digit);
+		}
+	}
 
 	return 0;
 }
+
 /*! \brief Write audio frames to interface */
-int alsa_write(private_t * tech_pvt, short * data, int datalen)
+int alsa_write(private_t * tech_pvt, short *data, int datalen)
 {
-  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;
+	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;
 
-    //ERRORA("data=%p, datalen=%d\n", SKYPIAX_P_LOG, (void *)data, datalen);
-  /* We have to digest the frame in 160-byte portions */
-  if (datalen > sizeof(sizbuf) - sizpos) {
-    ERRORA("Frame too large\n", SKYPIAX_P_LOG);
-    res = -1;
-  } else {
-    memcpy(sizbuf + sizpos, data, datalen);
-    len += datalen;
-    pos = 0;
+	//ERRORA("data=%p, datalen=%d\n", SKYPIAX_P_LOG, (void *)data, datalen);
+	/* We have to digest the frame in 160-byte portions */
+	if (datalen > sizeof(sizbuf) - sizpos) {
+		ERRORA("Frame too large\n", SKYPIAX_P_LOG);
+		res = -1;
+	} else {
+		memcpy(sizbuf + sizpos, data, datalen);
+		len += datalen;
+		pos = 0;
 #ifdef ALSA_MONITOR
-    alsa_monitor_write(sizbuf, len);
+		alsa_monitor_write(sizbuf, len);
 #endif
-    state = snd_pcm_state(tech_pvt->alsap);
-    if (state == SND_PCM_STATE_XRUN) {
-      int i;
+		state = snd_pcm_state(tech_pvt->alsap);
+		if (state == SND_PCM_STATE_XRUN) {
+			int i;
 
-      DEBUGA_SKYPE
-        ("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",
-         SKYPIAX_P_LOG, tech_pvt->alsa_periods_in_buffer);
-      res = snd_pcm_prepare(tech_pvt->alsap);
-      if (res) {
-        ERRORA("audio play prepare failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-      } else {
-        res = snd_pcm_format_set_silence(celliax_format, silencebuf, len / 2);
-        if (res < 0) {
-          DEBUGA_SKYPE("Silence error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-          res = -1;
-        }
-        for (i = 0; i < (tech_pvt->alsa_periods_in_buffer - 1); i++) {
-          res = snd_pcm_writei(tech_pvt->alsap, silencebuf, len / 2);
-          if (res != len / 2) {
-            DEBUGA_SKYPE("Write returned a different quantity: %d\n", SKYPIAX_P_LOG, res);
-            res = -1;
-          } else if (res < 0) {
-            DEBUGA_SKYPE("Write error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-            res = -1;
-          }
-        }
-      }
+			DEBUGA_SKYPE
+				("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",
+				 SKYPIAX_P_LOG, tech_pvt->alsa_periods_in_buffer);
+			res = snd_pcm_prepare(tech_pvt->alsap);
+			if (res) {
+				ERRORA("audio play prepare failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+			} else {
+				res = snd_pcm_format_set_silence(celliax_format, silencebuf, len / 2);
+				if (res < 0) {
+					DEBUGA_SKYPE("Silence error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+					res = -1;
+				}
+				for (i = 0; i < (tech_pvt->alsa_periods_in_buffer - 1); i++) {
+					res = snd_pcm_writei(tech_pvt->alsap, silencebuf, len / 2);
+					if (res != len / 2) {
+						DEBUGA_SKYPE("Write returned a different quantity: %d\n", SKYPIAX_P_LOG, res);
+						res = -1;
+					} else if (res < 0) {
+						DEBUGA_SKYPE("Write error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+						res = -1;
+					}
+				}
+			}
 
-    }
+		}
 
-    res = snd_pcm_delay(tech_pvt->alsap, &delayp1);
-    if (res < 0) {
-      DEBUGA_SKYPE("Error %d on snd_pcm_delay: \"%s\"\n", SKYPIAX_P_LOG, res,
-                   snd_strerror(res));
-      res = snd_pcm_prepare(tech_pvt->alsap);
-      if (res) {
-        DEBUGA_SKYPE("snd_pcm_prepare failed: '%s'\n", SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      res = snd_pcm_delay(tech_pvt->alsap, &delayp1);
-    }
+		res = snd_pcm_delay(tech_pvt->alsap, &delayp1);
+		if (res < 0) {
+			DEBUGA_SKYPE("Error %d on snd_pcm_delay: \"%s\"\n", SKYPIAX_P_LOG, res, snd_strerror(res));
+			res = snd_pcm_prepare(tech_pvt->alsap);
+			if (res) {
+				DEBUGA_SKYPE("snd_pcm_prepare failed: '%s'\n", SKYPIAX_P_LOG, snd_strerror(res));
+			}
+			res = snd_pcm_delay(tech_pvt->alsap, &delayp1);
+		}
 
-    delayp2 = snd_pcm_avail_update(tech_pvt->alsap);
-    if (delayp2 < 0) {
-      DEBUGA_SKYPE("Error %d on snd_pcm_avail_update: \"%s\"\n", SKYPIAX_P_LOG,
-                   (int) delayp2, snd_strerror(delayp2));
+		delayp2 = snd_pcm_avail_update(tech_pvt->alsap);
+		if (delayp2 < 0) {
+			DEBUGA_SKYPE("Error %d on snd_pcm_avail_update: \"%s\"\n", SKYPIAX_P_LOG, (int) delayp2, snd_strerror(delayp2));
 
-      res = snd_pcm_prepare(tech_pvt->alsap);
-      if (res) {
-        DEBUGA_SKYPE("snd_pcm_prepare failed: '%s'\n", SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      delayp2 = snd_pcm_avail_update(tech_pvt->alsap);
-    }
+			res = snd_pcm_prepare(tech_pvt->alsap);
+			if (res) {
+				DEBUGA_SKYPE("snd_pcm_prepare failed: '%s'\n", SKYPIAX_P_LOG, snd_strerror(res));
+			}
+			delayp2 = snd_pcm_avail_update(tech_pvt->alsap);
+		}
 
-    if (                        /* delayp1 != 0 && delayp1 != 160 */
-         delayp1 < 160 || delayp2 > tech_pvt->alsa_buffer_size) {
+		if (					/* delayp1 != 0 && delayp1 != 160 */
+			   delayp1 < 160 || delayp2 > tech_pvt->alsa_buffer_size) {
 
-      res = snd_pcm_prepare(tech_pvt->alsap);
-      if (res) {
-        DEBUGA_SKYPE
-          ("snd_pcm_prepare failed while trying to prevent an ALSA write XRUN: %s, delayp1=%d, delayp2=%d\n",
-           SKYPIAX_P_LOG, snd_strerror(res), (int) delayp1, (int) delayp2);
-      } else {
+			res = snd_pcm_prepare(tech_pvt->alsap);
+			if (res) {
+				DEBUGA_SKYPE
+					("snd_pcm_prepare failed while trying to prevent an ALSA write XRUN: %s, delayp1=%d, delayp2=%d\n",
+					 SKYPIAX_P_LOG, snd_strerror(res), (int) delayp1, (int) delayp2);
+			} else {
 
-        int i;
-        for (i = 0; i < (tech_pvt->alsa_periods_in_buffer - 1); i++) {
-          res = snd_pcm_format_set_silence(celliax_format, silencebuf, len / 2);
-          if (res < 0) {
-            DEBUGA_SKYPE("Silence error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-            res = -1;
-          }
-          res = snd_pcm_writei(tech_pvt->alsap, silencebuf, len / 2);
-          if (res < 0) {
-            DEBUGA_SKYPE("Write error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-            res = -1;
-          } else if (res != len / 2) {
-            DEBUGA_SKYPE("Write returned a different quantity: %d\n", SKYPIAX_P_LOG, res);
-            res = -1;
-          }
-        }
+				int i;
+				for (i = 0; i < (tech_pvt->alsa_periods_in_buffer - 1); i++) {
+					res = snd_pcm_format_set_silence(celliax_format, silencebuf, len / 2);
+					if (res < 0) {
+						DEBUGA_SKYPE("Silence error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+						res = -1;
+					}
+					res = snd_pcm_writei(tech_pvt->alsap, silencebuf, len / 2);
+					if (res < 0) {
+						DEBUGA_SKYPE("Write error %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+						res = -1;
+					} else if (res != len / 2) {
+						DEBUGA_SKYPE("Write returned a different quantity: %d\n", SKYPIAX_P_LOG, res);
+						res = -1;
+					}
+				}
 
-        DEBUGA_SKYPE
-          ("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",
-           SKYPIAX_P_LOG, tech_pvt->alsa_periods_in_buffer, (int) delayp1, (int) delayp2);
-      }
+				DEBUGA_SKYPE
+					("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",
+					 SKYPIAX_P_LOG, tech_pvt->alsa_periods_in_buffer, (int) delayp1, (int) delayp2);
+			}
 
-    }
+		}
 
-    memset(sizbuf2, 0, sizeof(sizbuf2));
-    if (tech_pvt->alsa_play_is_mono) {
-      res = snd_pcm_writei(tech_pvt->alsap, sizbuf, len / 2);
-    } else {
-      int a = 0;
-      int i = 0;
-      for (i = 0; i < 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(tech_pvt->alsap, sizbuf2, len);
-    }
-    if (res == -EPIPE) {
-      DEBUGA_SKYPE
-        ("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",
-         SKYPIAX_P_LOG, tech_pvt->alsa_periods_in_buffer, (int) delayp1, (int) delayp2);
-      res = snd_pcm_prepare(tech_pvt->alsap);
-      if (res) {
-        ERRORA("audio play prepare failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-      } else {
+		memset(sizbuf2, 0, sizeof(sizbuf2));
+		if (tech_pvt->alsa_play_is_mono) {
+			res = snd_pcm_writei(tech_pvt->alsap, sizbuf, len / 2);
+		} else {
+			int a = 0;
+			int i = 0;
+			for (i = 0; i < 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(tech_pvt->alsap, sizbuf2, len);
+		}
+		if (res == -EPIPE) {
+			DEBUGA_SKYPE
+				("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",
+				 SKYPIAX_P_LOG, tech_pvt->alsa_periods_in_buffer, (int) delayp1, (int) delayp2);
+			res = snd_pcm_prepare(tech_pvt->alsap);
+			if (res) {
+				ERRORA("audio play prepare failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+			} else {
 
-        if (tech_pvt->alsa_play_is_mono) {
-          res = snd_pcm_writei(tech_pvt->alsap, sizbuf, len / 2);
-        } else {
-          int a = 0;
-          int i = 0;
-          for (i = 0; i < 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(tech_pvt->alsap, sizbuf2, len);
-        }
+				if (tech_pvt->alsa_play_is_mono) {
+					res = snd_pcm_writei(tech_pvt->alsap, sizbuf, len / 2);
+				} else {
+					int a = 0;
+					int i = 0;
+					for (i = 0; i < 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(tech_pvt->alsap, sizbuf2, len);
+				}
 
-      }
+			}
 
-    } else {
-      if (res == -ESTRPIPE) {
-        ERRORA("You've got some big problems\n", SKYPIAX_P_LOG);
-      } else if (res == -EAGAIN) {
-        res = 0;
-      } else if (res < 0) {
-        ERRORA("Error %d on audio write: \"%s\"\n", SKYPIAX_P_LOG, res,
-               snd_strerror(res));
-      }
-    }
-  }
+		} else {
+			if (res == -ESTRPIPE) {
+				ERRORA("You've got some big problems\n", SKYPIAX_P_LOG);
+			} else if (res == -EAGAIN) {
+				res = 0;
+			} else if (res < 0) {
+				ERRORA("Error %d on audio write: \"%s\"\n", SKYPIAX_P_LOG, res, snd_strerror(res));
+			}
+		}
+	}
 
-  if (tech_pvt->audio_play_reset_period) {
-    time(&now_timestamp);
-    if ((now_timestamp - tech_pvt->audio_play_reset_timestamp) > tech_pvt->audio_play_reset_period) {
-      if (option_debug)
-        DEBUGA_SKYPE("reset audio play\n", SKYPIAX_P_LOG);
-      res = snd_pcm_wait(tech_pvt->alsap, 1000);
-      if (res < 0) {
-        ERRORA("audio play wait failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      res = snd_pcm_drop(tech_pvt->alsap);
-      if (res) {
-        ERRORA("audio play drop failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      res = snd_pcm_prepare(tech_pvt->alsap);
-      if (res) {
-        ERRORA("audio play prepare failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      res = snd_pcm_wait(tech_pvt->alsap, 1000);
-      if (res < 0) {
-        ERRORA("audio play wait failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
-      }
-      time(&tech_pvt->audio_play_reset_timestamp);
-    }
-  }
-  //res = 0;
-  //if (res > 0)
-    //res = 0;
-  return res;
+	if (tech_pvt->audio_play_reset_period) {
+		time(&now_timestamp);
+		if ((now_timestamp - tech_pvt->audio_play_reset_timestamp) > tech_pvt->audio_play_reset_period) {
+			if (option_debug)
+				DEBUGA_SKYPE("reset audio play\n", SKYPIAX_P_LOG);
+			res = snd_pcm_wait(tech_pvt->alsap, 1000);
+			if (res < 0) {
+				ERRORA("audio play wait failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+			}
+			res = snd_pcm_drop(tech_pvt->alsap);
+			if (res) {
+				ERRORA("audio play drop failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+			}
+			res = snd_pcm_prepare(tech_pvt->alsap);
+			if (res) {
+				ERRORA("audio play prepare failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+			}
+			res = snd_pcm_wait(tech_pvt->alsap, 1000);
+			if (res < 0) {
+				ERRORA("audio play wait failed: %s\n", SKYPIAX_P_LOG, snd_strerror(res));
+			}
+			time(&tech_pvt->audio_play_reset_timestamp);
+		}
+	}
+	//res = 0;
+	//if (res > 0)
+	//res = 0;
+	return res;
 }
 
 #define AST_FRIENDLY_OFFSET 0
-int alsa_read(private_t * tech_pvt, short * data, int datalen)
+int alsa_read(private_t * tech_pvt, short *data, int datalen)
 {
-  //static struct ast_frame f;
-  static short __buf[SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2];
-  static short __buf2[(SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2) * 2];
-  short *buf;
-  short *buf2;
-  static int readpos = 0;
-  //static int left = SKYPIAX_FRAME_SIZE;
-  static int left;
-  snd_pcm_state_t state;
-  int r = 0;
-  int off = 0;
-  int error = 0;
-  //time_t now_timestamp;
+	//static struct ast_frame f;
+	static short __buf[SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2];
+	static short __buf2[(SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2) * 2];
+	short *buf;
+	short *buf2;
+	static int readpos = 0;
+	//static int left = SKYPIAX_FRAME_SIZE;
+	static int left;
+	snd_pcm_state_t state;
+	int r = 0;
+	int off = 0;
+	int error = 0;
+	//time_t now_timestamp;
 
-    //DEBUGA_SKYPE("buf=%p, datalen=%d, left=%d\n", SKYPIAX_P_LOG, (void *)buf, datalen, left);
-  //memset(&f, 0, sizeof(struct ast_frame)); //giova
+	//DEBUGA_SKYPE("buf=%p, datalen=%d, left=%d\n", SKYPIAX_P_LOG, (void *)buf, datalen, left);
+	//memset(&f, 0, sizeof(struct ast_frame)); //giova
 
 #ifdef NOTDEF
-  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;
-#endif// NOTDEF
+	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;
+#endif // NOTDEF
 
 
 
 
-left = datalen;
+	left = datalen;
 
-  struct timeval to;
-  fd_set rfds;
-int result;
+	struct timeval to;
+	fd_set rfds;
+	int result;
 
 
-    FD_ZERO(&rfds);
-    FD_SET(tech_pvt->celliax_sound_capt_fd, &rfds);
+	FD_ZERO(&rfds);
+	FD_SET(tech_pvt->celliax_sound_capt_fd, &rfds);
 
-    /* Wait for something to happen */
-    to.tv_sec = 0;
-    to.tv_usec = 500000;        /* we select with this timeout because under cygwin we avoid the signal usage, so there is no way to end the thread if it is stuck waiting for select */
-    result = select(tech_pvt->celliax_sound_capt_fd + 1, &rfds, NULL, NULL, &to);
+	/* Wait for something to happen */
+	to.tv_sec = 0;
+	to.tv_usec = 500000;		/* we select with this timeout because under cygwin we avoid the signal usage, so there is no way to end the thread if it is stuck waiting for select */
+	result = select(tech_pvt->celliax_sound_capt_fd + 1, &rfds, NULL, NULL, &to);
 
 
 
-    /* If there are errors...  */
-    if (result < 0) {
-      if (errno == EINTR) {     /* EINTR is just the select
-                                   being interrupted by a SIGURG, or so */
-        ERRORA("select returned %d: %s\n", SKYPIAX_P_LOG, result, strerror(errno));
-        usleep(1000);
-        //continue;
-      } else {
-        ERRORA("select returned %d: %s\n", SKYPIAX_P_LOG, result, strerror(errno));
+	/* If there are errors...  */
+	if (result < 0) {
+		if (errno == EINTR) {	/* EINTR is just the select
+								   being interrupted by a SIGURG, or so */
+			ERRORA("select returned %d: %s\n", SKYPIAX_P_LOG, result, strerror(errno));
+			usleep(1000);
+			//continue;
+		} else {
+			ERRORA("select returned %d: %s\n", SKYPIAX_P_LOG, result, strerror(errno));
 //FIXME what to do here? is the interface that failed signaled? which interface we have to disable?
-        //return NULL;
-      }
-    }
-    /* If there are no file descriptors changed, just continue  */
+			//return NULL;
+		}
+	}
+	/* If there are no file descriptors changed, just continue  */
 
-    if (result == 0) {
-      usleep(10000);              //let's breath
-        ERRORA("select returned %d: %s\n", SKYPIAX_P_LOG, result, strerror(errno));
-    }
+	if (result == 0) {
+		usleep(10000);			//let's breath
+		ERRORA("select returned %d: %s\n", SKYPIAX_P_LOG, result, strerror(errno));
+	}
 
 
 
@@ -4943,111 +4739,108 @@
 
 
 
-  state = snd_pcm_state(tech_pvt->alsac);
-  if (state != SND_PCM_STATE_RUNNING) {
-    DEBUGA_SKYPE("ALSA read state is not SND_PCM_STATE_RUNNING\n", SKYPIAX_P_LOG);
+	state = snd_pcm_state(tech_pvt->alsac);
+	if (state != SND_PCM_STATE_RUNNING) {
+		DEBUGA_SKYPE("ALSA read state is not SND_PCM_STATE_RUNNING\n", SKYPIAX_P_LOG);
 
-    if (state != SND_PCM_STATE_PREPARED) {
-      error = snd_pcm_prepare(tech_pvt->alsac);
-      if (error) {
-        ERRORA("snd_pcm_prepare failed, %s\n", SKYPIAX_P_LOG, snd_strerror(error));
-        return r;
-      }
-      DEBUGA_SKYPE("prepared!\n", SKYPIAX_P_LOG);
-    }
-    usleep(1000);
-    error = snd_pcm_start(tech_pvt->alsac);
-    if (error) {
-      ERRORA("snd_pcm_start failed, %s\n", SKYPIAX_P_LOG, snd_strerror(error));
-      return r;
-    }
-    DEBUGA_SKYPE("started!\n", SKYPIAX_P_LOG);
-    usleep(1000);
-  }
+		if (state != SND_PCM_STATE_PREPARED) {
+			error = snd_pcm_prepare(tech_pvt->alsac);
+			if (error) {
+				ERRORA("snd_pcm_prepare failed, %s\n", SKYPIAX_P_LOG, snd_strerror(error));
+				return r;
+			}
+			DEBUGA_SKYPE("prepared!\n", SKYPIAX_P_LOG);
+		}
+		usleep(1000);
+		error = snd_pcm_start(tech_pvt->alsac);
+		if (error) {
+			ERRORA("snd_pcm_start failed, %s\n", SKYPIAX_P_LOG, snd_strerror(error));
+			return r;
+		}
+		DEBUGA_SKYPE("started!\n", SKYPIAX_P_LOG);
+		usleep(1000);
+	}
 
-  buf = __buf + AST_FRIENDLY_OFFSET / 2;
-  buf2 = __buf2 + ((AST_FRIENDLY_OFFSET / 2) * 2);
+	buf = __buf + AST_FRIENDLY_OFFSET / 2;
+	buf2 = __buf2 + ((AST_FRIENDLY_OFFSET / 2) * 2);
 
-  if (tech_pvt->alsa_capture_is_mono) {
-    //DEBUGA_SKYPE("buf=%p, buf+readpos=%p, datalen=%d, left=%d\n", SKYPIAX_P_LOG, (void *)buf, (void *)(buf + readpos), datalen, left);
-    r = snd_pcm_readi(tech_pvt->alsac, buf + readpos, left);
-  } else {
-    r = snd_pcm_readi(tech_pvt->alsac, buf2 + (readpos * 2), left);
+	if (tech_pvt->alsa_capture_is_mono) {
+		//DEBUGA_SKYPE("buf=%p, buf+readpos=%p, datalen=%d, left=%d\n", SKYPIAX_P_LOG, (void *)buf, (void *)(buf + readpos), datalen, left);
+		r = snd_pcm_readi(tech_pvt->alsac, buf + readpos, left);
+	} else {
+		r = snd_pcm_readi(tech_pvt->alsac, buf2 + (readpos * 2), left);
 
-    int a = 0;
-    int i = 0;
-    for (i = 0; i < (SKYPIAX_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++;
-    }
-  }
+		int a = 0;
+		int i = 0;
+		for (i = 0; i < (SKYPIAX_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("XRUN read\n\n\n\n\n", SKYPIAX_P_LOG);
-    return r;
-  } else if (r == -ESTRPIPE) {
-    ERRORA("-ESTRPIPE\n", SKYPIAX_P_LOG);
-    return r;
+	if (r == -EPIPE) {
+		ERRORA("XRUN read\n\n\n\n\n", SKYPIAX_P_LOG);
+		return r;
+	} else if (r == -ESTRPIPE) {
+		ERRORA("-ESTRPIPE\n", SKYPIAX_P_LOG);
+		return r;
 
-  } else if (r == -EAGAIN) {
-    DEBUGA_SKYPE("ALSA read -EAGAIN, the soundcard is not ready to be read by celliax\n",
-                 SKYPIAX_P_LOG);
-    while (r == -EAGAIN) {
-      usleep(1000);
+	} else if (r == -EAGAIN) {
+		DEBUGA_SKYPE("ALSA read -EAGAIN, the soundcard is not ready to be read by celliax\n", SKYPIAX_P_LOG);
+		while (r == -EAGAIN) {
+			usleep(1000);
 
-      if (tech_pvt->alsa_capture_is_mono) {
-        r = snd_pcm_readi(tech_pvt->alsac, buf + readpos, left);
-      } else {
-        r = snd_pcm_readi(tech_pvt->alsac, buf2 + (readpos * 2), left);
+			if (tech_pvt->alsa_capture_is_mono) {
+				r = snd_pcm_readi(tech_pvt->alsac, buf + readpos, left);
+			} else {
+				r = snd_pcm_readi(tech_pvt->alsac, buf2 + (readpos * 2), left);
 
-        int a = 0;
-        int i = 0;
-        for (i = 0; i < (SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2) * 2;) {
-          __buf[a] = (__buf2[i] + __buf2[i + 1]) / 2;
-          a++;
-          i++;
-          i++;
-        }
-      }
+				int a = 0;
+				int i = 0;
+				for (i = 0; i < (SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2) * 2;) {
+					__buf[a] = (__buf2[i] + __buf2[i + 1]) / 2;
+					a++;
+					i++;
+					i++;
+				}
+			}
 
-    }
-  } else if (r < 0) {
-    WARNINGA("ALSA Read error: %s\n", SKYPIAX_P_LOG, snd_strerror(r));
-  } else if (r >= 0) {
-    //DEBUGA_SKYPE("read: r=%d, readpos=%d, left=%d, off=%d\n", SKYPIAX_P_LOG, r, readpos, left, off);
-    off -= r;                   //what is the meaning of this? a leftover, probably
-  }
-  /* Update positions */
-  readpos += r;
-  left -= r;
+		}
+	} else if (r < 0) {
+		WARNINGA("ALSA Read error: %s\n", SKYPIAX_P_LOG, snd_strerror(r));
+	} else if (r >= 0) {
+		//DEBUGA_SKYPE("read: r=%d, readpos=%d, left=%d, off=%d\n", 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 >= SKYPIAX_FRAME_SIZE) {
-    /* A real frame */
-    readpos = 0;
-    left = SKYPIAX_FRAME_SIZE;
-int i;
-for(i=0; i<r; i++)
-data[i] = buf[i];
+	if (readpos >= SKYPIAX_FRAME_SIZE) {
+		/* A real frame */
+		readpos = 0;
+		left = SKYPIAX_FRAME_SIZE;
+		int i;
+		for (i = 0; i < r; i++)
+			data[i] = buf[i];
 
 #ifdef NOTDEF
-    f.frametype = AST_FRAME_VOICE;
-    f.subclass = AST_FORMAT_SLINEAR;
-    f.samples = SKYPIAX_FRAME_SIZE;
-    f.datalen = SKYPIAX_FRAME_SIZE * 2;
-    f.data = buf;
-    f.offset = AST_FRIENDLY_OFFSET;
-    f.src = celliax_type;
-    f.mallocd = 0;
+		f.frametype = AST_FRAME_VOICE;
+		f.subclass = AST_FORMAT_SLINEAR;
+		f.samples = SKYPIAX_FRAME_SIZE;
+		f.datalen = SKYPIAX_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, SKYPIAX_FRAME_SIZE * 2);
+		alsa_monitor_read((char *) buf, SKYPIAX_FRAME_SIZE * 2);
 #endif
 #endif //NOTDEF
 
-  }
-  return r;
+	}
+	return r;
 }
-
-

Modified: freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c (14675 => 14676)


--- freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c	2009-08-29 13:15:21 UTC (rev 14675)
+++ freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c	2009-08-29 13:24:59 UTC (rev 14676)
@@ -253,28 +253,26 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-int res;
-				  res = alsa_init(tech_pvt);
-				  if (res == -1) {
-					  ERRORA("Failed initializing sound device\n", SKYPIAX_P_LOG);
-					  /* we failed, free the PVT */
-					  //if (tmp)
-						  //free(tmp);
-					  //return NULL;
-				  }
+	int res;
+	res = alsa_init(tech_pvt);
+	if (res == -1) {
+		ERRORA("Failed initializing sound device\n", SKYPIAX_P_LOG);
+		/* we failed, free the PVT */
+		//if (tmp)
+		//free(tmp);
+		//return NULL;
+	}
+	//teletone_dtmf_detect_init(&tech_pvt->dtmf_detect, tech_pvt->read_codec.implementation->actual_samples_per_second);
+	teletone_dtmf_detect_init(&tech_pvt->dtmf_detect, 8000);
 
-
-
-        //teletone_dtmf_detect_init(&tech_pvt->dtmf_detect, tech_pvt->read_codec.implementation->actual_samples_per_second);
-        teletone_dtmf_detect_init(&tech_pvt->dtmf_detect, 8000);
-
-	if (switch_core_timer_init(&tech_pvt->timer, "soft", 20, tech_pvt->read_codec.implementation->samples_per_packet, celliax_module_pool) != SWITCH_STATUS_SUCCESS) {
+	if (switch_core_timer_init(&tech_pvt->timer, "soft", 20, tech_pvt->read_codec.implementation->samples_per_packet, celliax_module_pool) !=
+		SWITCH_STATUS_SUCCESS) {
 		ERRORA("setup timer failed\n", SKYPIAX_P_LOG);
 		return SWITCH_STATUS_FALSE;
 	}
 
 
-switch_clear_flag(tech_pvt, TFLAG_HANGUP);	
+	switch_clear_flag(tech_pvt, TFLAG_HANGUP);
 	DEBUGA_SKYPE("celliax_codec SUCCESS\n", SKYPIAX_P_LOG);
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -479,9 +477,9 @@
 			switch_core_codec_destroy(&tech_pvt->write_codec);
 		}
 
-			switch_core_timer_destroy(&tech_pvt->timer);
+		switch_core_timer_destroy(&tech_pvt->timer);
 
-alsa_shutdown(tech_pvt);
+		alsa_shutdown(tech_pvt);
 
 		*tech_pvt->session_uuid_str = '\0';
 		tech_pvt->interface_state = SKYPIAX_STATE_IDLE;
@@ -635,7 +633,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
+static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t * dtmf)
 {
 	private_t *tech_pvt = switch_core_session_get_private(session);
 	switch_assert(tech_pvt != NULL);
@@ -670,67 +668,62 @@
 	tech_pvt->read_frame.flags = SFF_NONE;
 	*frame = NULL;
 
-		if (switch_test_flag(tech_pvt, TFLAG_HANGUP)) {
+	if (switch_test_flag(tech_pvt, TFLAG_HANGUP)) {
 		return SWITCH_STATUS_FALSE;
-		}
+	}
 
 
 
-int samples;
+	int samples;
 
-		//if ((samples = snd_pcm_readi(tech_pvt->alsac, tech_pvt->read_frame.data, tech_pvt->read_codec.implementation->samples_per_packet)) > 0) 
-		if ((samples = alsa_read(tech_pvt, tech_pvt->read_frame.data, tech_pvt->read_codec.implementation->samples_per_packet )) > 0) 
+	//if ((samples = snd_pcm_readi(tech_pvt->alsac, tech_pvt->read_frame.data, tech_pvt->read_codec.implementation->samples_per_packet)) > 0) 
+	if ((samples = alsa_read(tech_pvt, tech_pvt->read_frame.data, tech_pvt->read_codec.implementation->samples_per_packet)) > 0) {
+		tech_pvt->read_frame.datalen = samples * 2;
+		tech_pvt->read_frame.samples = samples;
 
+		switch_core_timer_check(&tech_pvt->timer, SWITCH_TRUE);
+		tech_pvt->read_frame.timestamp = tech_pvt->timer.samplecount;
+		*frame = &tech_pvt->read_frame;
 
-{
-			tech_pvt->read_frame.datalen = samples * 2;
-			tech_pvt->read_frame.samples = samples;
+		//status = SWITCH_STATUS_SUCCESS;
+		switch_set_flag(tech_pvt, TFLAG_VOICE);
+	}
 
-			switch_core_timer_check(&tech_pvt->timer, SWITCH_TRUE);
-			tech_pvt->read_frame.timestamp = tech_pvt->timer.samplecount;
-			*frame = &tech_pvt->read_frame;
-
-			//status = SWITCH_STATUS_SUCCESS;
-			switch_set_flag(tech_pvt, TFLAG_VOICE);
-		}
-
-if(samples != 160)
+	if (samples != 160)
 		ERRORA("samples=%d\n", SKYPIAX_P_LOG, samples);
 
-		//WARNINGA("samples=%d\n", SKYPIAX_P_LOG, samples);
+	//WARNINGA("samples=%d\n", SKYPIAX_P_LOG, samples);
 
 //usleep(17000);
 //usleep(17000);
 
 
 
-        char digit_str[256];
+	char digit_str[256];
 
 
-            memset(digit_str, 0, sizeof(digit_str));
-                teletone_dtmf_detect(&tech_pvt->dtmf_detect, tech_pvt->read_frame.data, tech_pvt->read_frame.samples);
-                teletone_dtmf_get(&tech_pvt->dtmf_detect, digit_str, sizeof(digit_str));
+	memset(digit_str, 0, sizeof(digit_str));
+	teletone_dtmf_detect(&tech_pvt->dtmf_detect, tech_pvt->read_frame.data, tech_pvt->read_frame.samples);
+	teletone_dtmf_get(&tech_pvt->dtmf_detect, digit_str, sizeof(digit_str));
 
-                if (digit_str[0]) {
-                switch_time_t new_dtmf_timestamp = switch_time_now();
-                if((new_dtmf_timestamp - tech_pvt->old_dtmf_timestamp) > 350000) { //FIXME: make it configurable
-                        char *p = digit_str;
-                            switch_channel_t *channel = switch_core_session_get_channel(session);
+	if (digit_str[0]) {
+		switch_time_t new_dtmf_timestamp = switch_time_now();
+		if ((new_dtmf_timestamp - tech_pvt->old_dtmf_timestamp) > 350000) {	//FIXME: make it configurable
+			char *p = digit_str;
+			switch_channel_t *channel = switch_core_session_get_channel(session);
 
-                        while(p && *p) {
-                            switch_dtmf_t dtmf;
-                            dtmf.digit = *p;
-                            dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
-                            switch_channel_queue_dtmf(channel, &dtmf);
-                            p++;
-                        }
-                        NOTICA("DTMF DETECTED: [%s] new_dtmf_timestamp: %u, delta_t: %u\n", SKYPIAX_P_LOG, digit_str, (unsigned int)new_dtmf_timestamp, (unsigned int)(new_dtmf_timestamp - tech_pvt->old_dtmf_timestamp));
-                    tech_pvt->old_dtmf_timestamp = new_dtmf_timestamp;
-                    }
-            }
-
-
-
+			while (p && *p) {
+				switch_dtmf_t dtmf;
+				dtmf.digit = *p;
+				dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
+				switch_channel_queue_dtmf(channel, &dtmf);
+				p++;
+			}
+			NOTICA("DTMF DETECTED: [%s] new_dtmf_timestamp: %u, delta_t: %u\n", SKYPIAX_P_LOG, digit_str, (unsigned int) new_dtmf_timestamp,
+				   (unsigned int) (new_dtmf_timestamp - tech_pvt->old_dtmf_timestamp));
+			tech_pvt->old_dtmf_timestamp = new_dtmf_timestamp;
+		}
+	}
 #ifdef NOTDEF
 
 	if (!celliax_audio_read(tech_pvt)) {
@@ -766,7 +759,7 @@
 				switch_swap_linear((*frame)->data, (int) (*frame)->datalen / 2);
 			}
 #endif
-		//WARNINGA("HERE\n", SKYPIAX_P_LOG);
+			//WARNINGA("HERE\n", SKYPIAX_P_LOG);
 			return SWITCH_STATUS_SUCCESS;
 		}
 
@@ -815,23 +808,22 @@
 
 	sent = frame->datalen;
 
-		//ERRORA("PLAY \n", SKYPIAX_P_LOG);
-	            //snd_pcm_writei(tech_pvt->alsap, (short *) frame->data, (int) (frame->datalen / 2));
+	//ERRORA("PLAY \n", SKYPIAX_P_LOG);
+	//snd_pcm_writei(tech_pvt->alsap, (short *) frame->data, (int) (frame->datalen / 2));
 
- sent = alsa_write(tech_pvt, frame->data, (int) (frame->datalen));
+	sent = alsa_write(tech_pvt, frame->data, (int) (frame->datalen));
 
-#ifdef NOTDEF //FIXME
+#ifdef NOTDEF					//FIXME
 #ifdef WIN32
 	switch_file_write(tech_pvt->audioskypepipe[1], frame->data, &sent);
 #else /* WIN32 */
 	sent = write(tech_pvt->audioskypepipe[1], frame->data, sent);
 #endif /* WIN32 */
 #endif //NOTDEF
-	if (sent && sent != frame->datalen/2 && sent != -1) {
+	if (sent && sent != frame->datalen / 2 && sent != -1) {
 		DEBUGA_SKYPE("sent %d\n", SKYPIAX_P_LOG, sent);
 	}
-
-		//NOTICA("sent=%d\n", SKYPIAX_P_LOG, sent);
+	//NOTICA("sent=%d\n", SKYPIAX_P_LOG, sent);
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -1056,7 +1048,7 @@
  *
  */
 #ifdef NOTDEF
-static void *SWITCH_THREAD_FUNC celliax_signaling_thread_func(switch_thread_t * thread, void *obj)
+static void *SWITCH_THREAD_FUNC celliax_signaling_thread_func(switch_thread_t *thread, void *obj)
 {
 	private_t *tech_pvt = obj;
 	int res;
@@ -1116,7 +1108,7 @@
 	}
 	return NULL;
 }
-#endif// NOTDEF
+#endif // NOTDEF
 
 /* BEGIN: Changes heres */
 static switch_status_t load_config(int reload_type)
@@ -1302,8 +1294,7 @@
 			if (name) {
 				DEBUGA_SKYPE("name=%s\n", SKYPIAX_P_LOG, name);
 			}
-
-#ifdef NOTDEF 
+#ifdef NOTDEF
 #ifndef WIN32
 			if (!XInitThreads()) {
 				ERRORA("Not initialized XInitThreads!\n", SKYPIAX_P_LOG);
@@ -1313,7 +1304,7 @@
 			switch_sleep(100);
 #endif /* WIN32 */
 
-#endif// NOTDEF 
+#endif // NOTDEF
 			if (interface_id && interface_id < SKYPIAX_MAX_INTERFACES) {
 				private_t newconf;
 				switch_threadattr_t *celliax_api_thread_attr = NULL;
@@ -1351,109 +1342,109 @@
 				globals.SKYPIAX_INTERFACES[interface_id].controldevprotocol = controldevprotocol;
 
 
-	switch_mutex_init(&globals.SKYPIAX_INTERFACES[interface_id].controldev_lock, SWITCH_MUTEX_NESTED, celliax_module_pool);
+				switch_mutex_init(&globals.SKYPIAX_INTERFACES[interface_id].controldev_lock, SWITCH_MUTEX_NESTED, celliax_module_pool);
 /*********************/
 #ifdef NOTDEF
-  .interface_state = SKYPIAX_STATE_DOWN;
-  .phone_callflow = CALLFLOW_CALL_IDLE;
-  .dsp_silence_threshold = 512;
-  .context = "default";
-  .language = "en";
-  .exten = "s";
-  .controldevice_name = "none";
-  .controldevfd = 0;
-  .next = NULL;
-  .owner = NULL;
-  .dsp = NULL;
-  .fbus2_outgoing_list = NULL;
-  .seqnumfbus = FBUS2_SEQNUM_MAX;
-  .controldev_thread = AST_PTHREADT_NULL;
-  .arraycounter = 0;
+				.interface_state = SKYPIAX_STATE_DOWN;
+				.phone_callflow = CALLFLOW_CALL_IDLE;
+				.dsp_silence_threshold = 512;
+				.context = "default";
+				.language = "en";
+				.exten = "s";
+				.controldevice_name = "none";
+				.controldevfd = 0;
+				.next = NULL;
+				.owner = NULL;
+				.dsp = NULL;
+				.fbus2_outgoing_list = NULL;
+				.seqnumfbus = FBUS2_SEQNUM_MAX;
+				.controldev_thread = AST_PTHREADT_NULL;
+				.arraycounter = 0;
 #ifndef GIOVA48
-  .celliax_sound_rate = 8000;
+				.celliax_sound_rate = 8000;
 #else // GIOVA48
-  .celliax_sound_rate = 48000;
+				.celliax_sound_rate = 48000;
 #endif // GIOVA48
-  .celliax_sound_capt_fd = -1;
-  .need_acoustic_ring = 0;
-  .celliax_serial_synced_timestamp = 0;
-  .celliax_serial_sync_period = 300;
-  .audio_play_reset_timestamp = 0;
-  .audio_capture_reset_timestamp = 0;
-  .controldevice_speed = B38400;
-  .capture_boost = 0;
-  .playback_boost = 0;
-  .stripmsd = 0;
-  .controldev_dead = 0;
-  .dtmf_inited = 0;
-#endif// NOTDEF
-  //at_dial_pre_number = "AT+CKPD=\"";
-switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_dial_pre_number, "ATD");
-  //.at_dial_post_number = "S\"";
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_dial_post_number , ";");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_dial_expect , "OK");
-  globals.SKYPIAX_INTERFACES[interface_id].at_early_audio = 0;
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_hangup , "ATH");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_hangup_expect , "OK");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_answer , "ATA");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_answer_expect , "OK");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_send_dtmf , "AT+VTS");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_1 , "");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_1_expect , "");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_2 , "");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_2_expect , "");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_3 , "");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_3_expect , "");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_4 , "");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_4_expect , "");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_5 , "");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_5_expect , "");
-  globals.SKYPIAX_INTERFACES[interface_id].at_after_preinit_pause = 500000;
-  globals.SKYPIAX_INTERFACES[interface_id].at_initial_pause = 500000;
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_1 , "at+cmic=0,9");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_1_expect , "OK");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_2 , "AT+CKPD=\"EEE\"");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_2_expect , "OK");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_3 , "AT+CSSN=1,0");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_3_expect , "OK");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_4 , "at+sidet=0");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_4_expect , "OK");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_5 , "at+clvl=99");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_5_expect , "OK");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_query_battchg , "AT+CBC");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_query_battchg_expect , "OK");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_query_signal , "AT+CSQ");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_query_signal_expect , "OK");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_call_idle , "+MCST: 1");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_call_incoming , "+MCST: 2");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_call_active , "+CSSI: 7");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_call_failed , "+MCST: 65");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_call_calling , "+CSSI: 1");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_noservice_string , "CIEV: 2;0");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_nosignal_string , "CIEV: 5;0");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_lowsignal_string , "CIEV: 5;1");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_lowbattchg_string , "CIEV: 0;1");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_nobattchg_string , "CIEV: 0;0");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_callactive_string , "CIEV: 3;1");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_nocallactive_string , "CIEV: 3;0");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_nocallsetup_string , "CIEV: 6;0");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_callsetupincoming_string , "CIEV: 6;1");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_callsetupoutgoing_string , "CIEV: 6;2");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_callsetupremoteringing_string , "CIEV: 6;3");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].sms_receiving_program , "/usr/local/bin/ciapalo");
-  globals.SKYPIAX_INTERFACES[interface_id].at_has_clcc = 0;
-  globals.SKYPIAX_INTERFACES[interface_id].at_has_ecam = 0;
+				.celliax_sound_capt_fd = -1;
+				.need_acoustic_ring = 0;
+				.celliax_serial_synced_timestamp = 0;
+				.celliax_serial_sync_period = 300;
+				.audio_play_reset_timestamp = 0;
+				.audio_capture_reset_timestamp = 0;
+				.controldevice_speed = B38400;
+				.capture_boost = 0;
+				.playback_boost = 0;
+				.stripmsd = 0;
+				.controldev_dead = 0;
+				.dtmf_inited = 0;
+#endif // NOTDEF
+				//at_dial_pre_number = "AT+CKPD=\"";
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_dial_pre_number, "ATD");
+				//.at_dial_post_number = "S\"";
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_dial_post_number, ";");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_dial_expect, "OK");
+				globals.SKYPIAX_INTERFACES[interface_id].at_early_audio = 0;
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_hangup, "ATH");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_hangup_expect, "OK");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_answer, "ATA");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_answer_expect, "OK");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_send_dtmf, "AT+VTS");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_1, "");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_1_expect, "");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_2, "");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_2_expect, "");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_3, "");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_3_expect, "");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_4, "");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_4_expect, "");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_5, "");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_preinit_5_expect, "");
+				globals.SKYPIAX_INTERFACES[interface_id].at_after_preinit_pause = 500000;
+				globals.SKYPIAX_INTERFACES[interface_id].at_initial_pause = 500000;
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_1, "at+cmic=0,9");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_1_expect, "OK");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_2, "AT+CKPD=\"EEE\"");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_2_expect, "OK");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_3, "AT+CSSN=1,0");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_3_expect, "OK");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_4, "at+sidet=0");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_4_expect, "OK");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_5, "at+clvl=99");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_postinit_5_expect, "OK");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_query_battchg, "AT+CBC");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_query_battchg_expect, "OK");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_query_signal, "AT+CSQ");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_query_signal_expect, "OK");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_call_idle, "+MCST: 1");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_call_incoming, "+MCST: 2");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_call_active, "+CSSI: 7");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_call_failed, "+MCST: 65");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_call_calling, "+CSSI: 1");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_noservice_string, "CIEV: 2;0");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_nosignal_string, "CIEV: 5;0");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_lowsignal_string, "CIEV: 5;1");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_lowbattchg_string, "CIEV: 0;1");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_nobattchg_string, "CIEV: 0;0");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_callactive_string, "CIEV: 3;1");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_nocallactive_string, "CIEV: 3;0");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_nocallsetup_string, "CIEV: 6;0");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_callsetupincoming_string, "CIEV: 6;1");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_callsetupoutgoing_string, "CIEV: 6;2");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].at_indicator_callsetupremoteringing_string, "CIEV: 6;3");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].sms_receiving_program, "/usr/local/bin/ciapalo");
+				globals.SKYPIAX_INTERFACES[interface_id].at_has_clcc = 0;
+				globals.SKYPIAX_INTERFACES[interface_id].at_has_ecam = 0;
 
-  globals.SKYPIAX_INTERFACES[interface_id].alsa_period_size = 160;
-  globals.SKYPIAX_INTERFACES[interface_id].alsa_periods_in_buffer = 4;
-  globals.SKYPIAX_INTERFACES[interface_id].celliax_sound_rate = 8000;
+				globals.SKYPIAX_INTERFACES[interface_id].alsa_period_size = 160;
+				globals.SKYPIAX_INTERFACES[interface_id].alsa_periods_in_buffer = 4;
+				globals.SKYPIAX_INTERFACES[interface_id].celliax_sound_rate = 8000;
 
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].alsacname , "plughw:1");
-  switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].alsapname , "plughw:1");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].alsacname, "plughw:1");
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].alsapname, "plughw:1");
 
 
-  globals.SKYPIAX_INTERFACES[interface_id].alsa_play_is_mono = 1;
-  globals.SKYPIAX_INTERFACES[interface_id].alsa_capture_is_mono = 1;
+				globals.SKYPIAX_INTERFACES[interface_id].alsa_play_is_mono = 1;
+				globals.SKYPIAX_INTERFACES[interface_id].alsa_capture_is_mono = 1;
 
 
 
@@ -1486,54 +1477,57 @@
 					 SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].context);
 				WARNINGA("STARTING interface_id=%d\n", SKYPIAX_P_LOG, interface_id);
 
-				int res=0;
+				int res = 0;
 
-  /* init the serial port */
-  if (globals.SKYPIAX_INTERFACES[interface_id].controldevprotocol != PROTOCOL_NO_SERIAL) {
-    globals.SKYPIAX_INTERFACES[interface_id].controldevfd = celliax_serial_init(&globals.SKYPIAX_INTERFACES[interface_id], globals.SKYPIAX_INTERFACES[interface_id].controldevice_speed);
-    if (globals.SKYPIAX_INTERFACES[interface_id].controldevfd < 1) {
-      ERRORA("celliax_serial_init failed\n", SKYPIAX_P_LOG);
-      //celliax_sound_shutdown(tmp);
-      //if (tmp)
-        //free(tmp);
-      //return NULL;
-    }
-  }
+				/* init the serial port */
+				if (globals.SKYPIAX_INTERFACES[interface_id].controldevprotocol != PROTOCOL_NO_SERIAL) {
+					globals.SKYPIAX_INTERFACES[interface_id].controldevfd =
+						celliax_serial_init(&globals.SKYPIAX_INTERFACES[interface_id], globals.SKYPIAX_INTERFACES[interface_id].controldevice_speed);
+					if (globals.SKYPIAX_INTERFACES[interface_id].controldevfd < 1) {
+						ERRORA("celliax_serial_init failed\n", SKYPIAX_P_LOG);
+						//celliax_sound_shutdown(tmp);
+						//if (tmp)
+						//free(tmp);
+						//return NULL;
+					}
+				}
 
-  /* config the phone/modem on the serial port */
-  if (globals.SKYPIAX_INTERFACES[interface_id].controldevprotocol != PROTOCOL_NO_SERIAL) {
-    //int res;
-    res = celliax_serial_config(&globals.SKYPIAX_INTERFACES[interface_id]);
-    if (res) {
-      ERRORA("celliax_serial_config failed\n", SKYPIAX_P_LOG);
-      //celliax_sound_shutdown(tmp);
-      //if (tmp)
-        //free(tmp);
-      //return NULL;
-    }
-  }
+				/* config the phone/modem on the serial port */
+				if (globals.SKYPIAX_INTERFACES[interface_id].controldevprotocol != PROTOCOL_NO_SERIAL) {
+					//int res;
+					res = celliax_serial_config(&globals.SKYPIAX_INTERFACES[interface_id]);
+					if (res) {
+						ERRORA("celliax_serial_config failed\n", SKYPIAX_P_LOG);
+						//celliax_sound_shutdown(tmp);
+						//if (tmp)
+						//free(tmp);
+						//return NULL;
+					}
+				}
 
 
 				switch_sleep(100000);
 				switch_threadattr_create(&celliax_api_thread_attr, celliax_module_pool);
 				switch_threadattr_stacksize_set(celliax_api_thread_attr, SWITCH_THREAD_STACKSIZE);
-				switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].celliax_api_thread, celliax_api_thread_attr, celliax_do_skypeapi_thread, &globals.SKYPIAX_INTERFACES[interface_id], celliax_module_pool);
+				switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].celliax_api_thread, celliax_api_thread_attr, celliax_do_skypeapi_thread,
+									 &globals.SKYPIAX_INTERFACES[interface_id], celliax_module_pool);
 
 				switch_sleep(100000);
 
-#ifdef NOTDEF 
-				  res = alsa_init(&globals.SKYPIAX_INTERFACES[interface_id]);
-				  if (res == -1) {
-					  ERRORA("Failed initializing sound device\n", SKYPIAX_P_LOG);
-					  /* we failed, free the PVT */
-					  //if (tmp)
-						  //free(tmp);
-					  //return NULL;
-				  }
+#ifdef NOTDEF
+				res = alsa_init(&globals.SKYPIAX_INTERFACES[interface_id]);
+				if (res == -1) {
+					ERRORA("Failed initializing sound device\n", SKYPIAX_P_LOG);
+					/* we failed, free the PVT */
+					//if (tmp)
+					//free(tmp);
+					//return NULL;
+				}
 
 				switch_threadattr_create(&celliax_signaling_thread_attr, celliax_module_pool);
 				switch_threadattr_stacksize_set(celliax_signaling_thread_attr, SWITCH_THREAD_STACKSIZE);
-				switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].celliax_signaling_thread, celliax_signaling_thread_attr, celliax_signaling_thread_func, &globals.SKYPIAX_INTERFACES[interface_id], celliax_module_pool);
+				switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].celliax_signaling_thread, celliax_signaling_thread_attr,
+									 celliax_signaling_thread_func, &globals.SKYPIAX_INTERFACES[interface_id], celliax_module_pool);
 
 				switch_sleep(100000);
 
@@ -1582,7 +1576,7 @@
 					switch_xml_free(xml);
 					return SWITCH_STATUS_FALSE;
 				}
-#endif// NOTDEF 
+#endif // NOTDEF
 
 			} else {
 				ERRORA("interface id %d is higher than SKYPIAX_MAX_INTERFACES (%d)\n", SKYPIAX_P_LOG, interface_id, SKYPIAX_MAX_INTERFACES);
@@ -1667,7 +1661,6 @@
 				howmany = write(tech_pvt->SkypiaxHandles.fdesc[1], "sciutati", howmany);
 #endif /* WIN32 */
 			}
-
 #ifdef NOTDEF
 			if (globals.SKYPIAX_INTERFACES[interface_id].celliax_api_thread) {
 #ifdef WIN32
@@ -1690,7 +1683,7 @@
 				XSync(tech_pvt->SkypiaxHandles.disp, False);
 #endif
 			}
-#endif// NOTDEF
+#endif // NOTDEF
 			x = 10;
 			while (x) {			//FIXME 0.5 seconds?
 				x--;
@@ -1730,18 +1723,18 @@
 }
 
 #ifdef NOTDEF
-void *SWITCH_THREAD_FUNC celliax_do_tcp_srv_thread(switch_thread_t * thread, void *obj)
+void *SWITCH_THREAD_FUNC celliax_do_tcp_srv_thread(switch_thread_t *thread, void *obj)
 {
 	return celliax_do_tcp_srv_thread_func(obj);
 }
 
-void *SWITCH_THREAD_FUNC celliax_do_tcp_cli_thread(switch_thread_t * thread, void *obj)
+void *SWITCH_THREAD_FUNC celliax_do_tcp_cli_thread(switch_thread_t *thread, void *obj)
 {
 	return celliax_do_tcp_cli_thread_func(obj);
 }
-#endif// NOTDEF
+#endif // NOTDEF
 
-void *SWITCH_THREAD_FUNC celliax_do_skypeapi_thread(switch_thread_t * thread, void *obj)
+void *SWITCH_THREAD_FUNC celliax_do_skypeapi_thread(switch_thread_t *thread, void *obj)
 {
 	return celliax_do_skypeapi_thread_func(obj);
 }
@@ -1810,7 +1803,7 @@
 
 	return 0;
 }
-#endif// NOTDEF
+#endif // NOTDEF
 
 int new_inbound_channel(private_t * tech_pvt)
 {
@@ -1941,8 +1934,8 @@
 	}
 	if (channel) {
 		switch_channel_mark_answered(channel);
-tech_pvt->phone_callflow = SKYPIAX_STATE_UP;
-tech_pvt->interface_state = SKYPIAX_STATE_UP;
+		tech_pvt->phone_callflow = SKYPIAX_STATE_UP;
+		tech_pvt->interface_state = SKYPIAX_STATE_UP;
 		//DEBUGA_SKYPE("skype_call: %s, answered\n", SKYPIAX_P_LOG, id);
 	} else {
 		ERRORA("No channel???\n", SKYPIAX_P_LOG);
@@ -2062,8 +2055,7 @@
 				if (strlen(globals.SKYPIAX_INTERFACES[i].name)
 					&& (strncmp(globals.SKYPIAX_INTERFACES[i].name, argv[1], strlen(argv[1])) == 0)) {
 					globals.sk_console = &globals.SKYPIAX_INTERFACES[i];
-					stream->write_function(stream,
-										   "sk console is now: globals.SKYPIAX_INTERFACES[%d].name=|||%s|||\n", i, globals.SKYPIAX_INTERFACES[i].name);
+					stream->write_function(stream, "sk console is now: globals.SKYPIAX_INTERFACES[%d].name=|||%s|||\n", i, globals.SKYPIAX_INTERFACES[i].name);
 					stream->write_function(stream, "sk console is: |||%s|||\n", globals.sk_console->name);
 					found = 1;
 					break;
@@ -2190,8 +2182,7 @@
 				found = 1;
 				DEBUGA_SKYPE
 					("FOUND  (name=%s, giovatech->interface_state=%d != SKYPIAX_STATE_DOWN) && (giovatech->skype_user=%s == tech_pvt->skype_user=%s) && (giovatech->callid_number=%s == value=%s)\n",
-					 SKYPIAX_P_LOG, giovatech->name, giovatech->interface_state,
-					 giovatech->skype_user, tech_pvt->skype_user, giovatech->callid_number, value)
+					 SKYPIAX_P_LOG, giovatech->name, giovatech->interface_state, giovatech->skype_user, tech_pvt->skype_user, giovatech->callid_number, value)
 					if (tech_pvt->interface_state == SKYPIAX_STATE_PRERING) {
 					tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
 				} else if (tech_pvt->interface_state != 0 && tech_pvt->interface_state != SKYPIAX_STATE_DOWN) {
@@ -2245,7 +2236,7 @@
 	switch_mutex_unlock(globals.mutex);
 	return 0;
 }
-#endif// NOTDEF
+#endif // NOTDEF
 int celliax_transfer(private_t * tech_pvt, char *id, char *value)
 {
 	char msg_to_skype[1024];
@@ -2267,8 +2258,7 @@
 				found = 1;
 				DEBUGA_SKYPE
 					("FOUND  (name=%s, giovatech->interface_state=%d != SKYPIAX_STATE_DOWN) && (giovatech->skype_user=%s == tech_pvt->skype_user=%s) && (giovatech->callid_number=%s == value=%s)\n",
-					 SKYPIAX_P_LOG, giovatech->name, giovatech->interface_state,
-					 giovatech->skype_user, tech_pvt->skype_user, giovatech->callid_number, value)
+					 SKYPIAX_P_LOG, giovatech->name, giovatech->interface_state, giovatech->skype_user, tech_pvt->skype_user, giovatech->callid_number, value)
 					break;
 			}
 		}
@@ -2376,28 +2366,26 @@
 			int res;
 			//celliax_sleep(1000000); //1 sec
 			//DEBUGA_SKYPE("ciao!\n", SKYPIAX_P_LOG);
-			res=celliax_serial_read(tech_pvt);
-            if (res == -1) {    //manage the graceful interface shutdown
-              tech_pvt->controldev_dead = 1;
-              close(tech_pvt->controldevfd);
-              ERRORA("celliax_serial_monitor failed, declaring %s dead\n", SKYPIAX_P_LOG,
-                     tech_pvt->controldevice_name);
-            } else if (tech_pvt->controldevprotocol != PROTOCOL_NO_SERIAL
-                       && tech_pvt->interface_state == SKYPIAX_STATE_RING) {
-                WARNINGA("INCOMING RING, let's take the incoming call\n", SKYPIAX_P_LOG);
+			res = celliax_serial_read(tech_pvt);
+			if (res == -1) {	//manage the graceful interface shutdown
+				tech_pvt->controldev_dead = 1;
+				close(tech_pvt->controldevfd);
+				ERRORA("celliax_serial_monitor failed, declaring %s dead\n", SKYPIAX_P_LOG, tech_pvt->controldevice_name);
+			} else if (tech_pvt->controldevprotocol != PROTOCOL_NO_SERIAL && tech_pvt->interface_state == SKYPIAX_STATE_RING) {
+				WARNINGA("INCOMING RING, let's take the incoming call\n", SKYPIAX_P_LOG);
 				celliax_answer(tech_pvt);
 				//new_inbound_channel(tech_pvt);
-              //FIXME if (!celliax_new(p, AST_STATE_RING, tech_pvt->context)) {
-                //FIXME ERRORA("celliax_new failed! BAD BAD BAD\n", CELLIAX_P_LOG);
-              //FIXME }
-            } else if (tech_pvt->interface_state == CALLFLOW_CALL_REMOTEANSWER) {
-                WARNINGA("REMOTE PARTY ANSWERED\n", SKYPIAX_P_LOG);
-outbound_channel_answered(tech_pvt);
+				//FIXME if (!celliax_new(p, AST_STATE_RING, tech_pvt->context)) {
+				//FIXME ERRORA("celliax_new failed! BAD BAD BAD\n", CELLIAX_P_LOG);
+				//FIXME }
+			} else if (tech_pvt->interface_state == CALLFLOW_CALL_REMOTEANSWER) {
+				WARNINGA("REMOTE PARTY ANSWERED\n", SKYPIAX_P_LOG);
+				outbound_channel_answered(tech_pvt);
 				//new_inbound_channel(tech_pvt);
-              //FIXME if (!celliax_new(p, AST_STATE_RING, tech_pvt->context)) {
-                //FIXME ERRORA("celliax_new failed! BAD BAD BAD\n", CELLIAX_P_LOG);
-              //FIXME }
-            }
+				//FIXME if (!celliax_new(p, AST_STATE_RING, tech_pvt->context)) {
+				//FIXME ERRORA("celliax_new failed! BAD BAD BAD\n", CELLIAX_P_LOG);
+				//FIXME }
+			}
 		}
 	} else {
 		ERRORA("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypiax\n", SKYPIAX_P_LOG);