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(¶ms);
- snd_pcm_sw_params_alloca(&swparams);
+ snd_pcm_hw_params_alloca(¶ms);
+ 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;
}
-
-