FS-5292 gsmopen: patch from garmt

This commit is contained in:
Giovanni Maruzzelli 2013-06-20 14:21:49 +02:00
parent 607ef575bc
commit 12c96d9009
2 changed files with 218 additions and 117 deletions

View File

@ -113,13 +113,36 @@ int gettimeofday(struct timeval *tv, struct sk_timezone *tz)
int gsmopen_serial_init(private_t *tech_pvt, int controldevice_speed)
{
if (!tech_pvt)
return -1;
tech_pvt->serialPort_serial_control = new ctb::SerialPort();
if (tech_pvt->serialPort_serial_control->Open(tech_pvt->controldevice_name, 115200, "8N1", ctb::SerialPort::NoFlowControl) >= 0) {
/* windows: com ports above com9 need a special trick, which also works for com ports below com10 ... */
char devname[512] = "";
strcpy(devname, tech_pvt->controldevice_name);
#ifdef WIN32
strcpy(devname,"\\\\.\\");
strcat(devname, tech_pvt->controldevice_name);
#endif
if (tech_pvt->serialPort_serial_control->Open(devname, 115200, "8N1", ctb::SerialPort::NoFlowControl) >= 0) {
DEBUGA_GSMOPEN("port %s, SUCCESS open\n", GSMOPEN_P_LOG, tech_pvt->controldevice_name);
} else {
#ifdef WIN32
LPVOID msg;
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &msg,
0,
NULL);
ERRORA("port open failed for %s - %s", GSMOPEN_P_LOG, devname, (LPCTSTR) msg);
LocalFree(msg);
#else
ERRORA("port %s, NOT open\n", GSMOPEN_P_LOG, tech_pvt->controldevice_name);
#endif
return -1;
}
@ -128,7 +151,7 @@ int gsmopen_serial_init(private_t *tech_pvt, int controldevice_speed)
int gsmopen_serial_read(private_t *tech_pvt)
{
if (tech_pvt->controldevprotocol == PROTOCOL_AT)
if (tech_pvt && tech_pvt->controldevprotocol == PROTOCOL_AT)
return gsmopen_serial_read_AT(tech_pvt, 0, 100000, 0, NULL, 1); // a 10th of a second timeout
#ifdef GSMOPEN_FBUS2
if (tech_pvt->controldevprotocol == PROTOCOL_FBUS2)
@ -179,9 +202,12 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
char at_command[5];
int i;
if (!tech_pvt)
return 0;
/* initial_pause? */
if (tech_pvt->at_initial_pause) {
DEBUGA_GSMOPEN("sleeping for %d usec\n", GSMOPEN_P_LOG, tech_pvt->at_initial_pause);
DEBUGA_GSMOPEN("sleeping for %u usec\n", GSMOPEN_P_LOG, tech_pvt->at_initial_pause);
gsmopen_sleep(tech_pvt->at_initial_pause);
}
@ -206,7 +232,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
if (strlen(tech_pvt->at_preinit_1)) {
res = gsmopen_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_1, tech_pvt->at_preinit_1_expect);
if (res) {
DEBUGA_GSMOPEN("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_preinit_1, tech_pvt->at_preinit_1_expect);
DEBUGA_GSMOPEN("%s didn't get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_preinit_1, tech_pvt->at_preinit_1_expect);
}
} else {
break;
@ -215,7 +241,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
if (strlen(tech_pvt->at_preinit_2)) {
res = gsmopen_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_2, tech_pvt->at_preinit_2_expect);
if (res) {
DEBUGA_GSMOPEN("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_preinit_2, tech_pvt->at_preinit_2_expect);
DEBUGA_GSMOPEN("%s didn't get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_preinit_2, tech_pvt->at_preinit_2_expect);
}
} else {
break;
@ -224,7 +250,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
if (strlen(tech_pvt->at_preinit_3)) {
res = gsmopen_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_3, tech_pvt->at_preinit_3_expect);
if (res) {
DEBUGA_GSMOPEN("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_preinit_3, tech_pvt->at_preinit_3_expect);
DEBUGA_GSMOPEN("%s didn't get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_preinit_3, tech_pvt->at_preinit_3_expect);
}
} else {
break;
@ -233,7 +259,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
if (strlen(tech_pvt->at_preinit_4)) {
res = gsmopen_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_4, tech_pvt->at_preinit_4_expect);
if (res) {
DEBUGA_GSMOPEN("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_preinit_4, tech_pvt->at_preinit_4_expect);
DEBUGA_GSMOPEN("%s didn't get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_preinit_4, tech_pvt->at_preinit_4_expect);
}
} else {
break;
@ -242,7 +268,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
if (strlen(tech_pvt->at_preinit_5)) {
res = gsmopen_serial_write_AT_expect(tech_pvt, tech_pvt->at_preinit_5, tech_pvt->at_preinit_5_expect);
if (res) {
DEBUGA_GSMOPEN("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_preinit_5, tech_pvt->at_preinit_5_expect);
DEBUGA_GSMOPEN("%s didn't get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_preinit_5, tech_pvt->at_preinit_5_expect);
}
} else {
break;
@ -253,7 +279,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
/* after_preinit_pause? */
if (tech_pvt->at_after_preinit_pause) {
DEBUGA_GSMOPEN("sleeping for %d usec\n", GSMOPEN_P_LOG, tech_pvt->at_after_preinit_pause);
DEBUGA_GSMOPEN("sleeping for %u usec\n", GSMOPEN_P_LOG, tech_pvt->at_after_preinit_pause);
gsmopen_sleep(tech_pvt->at_after_preinit_pause);
}
@ -267,7 +293,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
/* for motorola, bring it back to "normal" mode if it happens to be in another mode */
res = gsmopen_serial_write_AT_ack(tech_pvt, "AT+mode=0");
if (res) {
DEBUGA_GSMOPEN("AT+mode=0 does not get OK from the phone. If it is NOT Motorola," " no problem.\n", GSMOPEN_P_LOG);
DEBUGA_GSMOPEN("AT+mode=0 didn't get OK from the phone. If it is NOT Motorola," " no problem.\n", GSMOPEN_P_LOG);
}
gsmopen_sleep(50000);
/* for motorola end */
@ -411,7 +437,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
res = gsmopen_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", GSMOPEN_P_LOG);
WARNINGA("AT+CSMP didn't get OK from the phone, continuing\n", GSMOPEN_P_LOG);
}
/* what is the Charset of SMSs? */
@ -423,18 +449,18 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
tech_pvt->no_ucs2 = 0;
res = gsmopen_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", GSMOPEN_P_LOG);
WARNINGA("AT+CSCS=\"UCS2\" (set TE messages to ucs2) didn't get OK from the phone, let's try with 'GSM'\n", GSMOPEN_P_LOG);
tech_pvt->no_ucs2 = 1;
}
if (tech_pvt->no_ucs2) {
res = gsmopen_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", GSMOPEN_P_LOG);
WARNINGA("AT+CSCS=\"GSM\" (set TE messages to GSM) didn't get OK from the phone\n", GSMOPEN_P_LOG);
}
//res = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CSMP=17,167,0,16"); //"flash", class 0 sms 7 bit
res = gsmopen_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", GSMOPEN_P_LOG);
WARNINGA("AT+CSMP didn't get OK from the phone, continuing\n", GSMOPEN_P_LOG);
}
}
@ -448,12 +474,12 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
if (tech_pvt->no_ucs2) {
res = gsmopen_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", GSMOPEN_P_LOG);
WARNINGA("AT+CSCS=\"GSM\" (set TE messages to GSM) didn't get OK from the phone\n", GSMOPEN_P_LOG);
}
//res = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CSMP=17,167,0,16"); //"flash", class 0 sms 7 bit
res = gsmopen_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", GSMOPEN_P_LOG);
WARNINGA("AT+CSMP didn't get OK from the phone, continuing\n", GSMOPEN_P_LOG);
}
}
#endif // NOTDEF //GSMLIB? XXX
@ -464,7 +490,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
//res = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CSMP=17,167,0,20"); //"flash", class 0 sms 16 bit unicode
res = gsmopen_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", GSMOPEN_P_LOG);
WARNINGA("AT+CSMP didn't get OK from the phone, continuing\n", GSMOPEN_P_LOG);
}
}
#endif // NOTDEF
@ -520,7 +546,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
(to know when call is disconnected (they
don't give you "no carrier") */
if (res) {
DEBUGA_GSMOPEN("AT+MCST=1 does not get OK from the phone. If it is NOT Motorola," " no problem.\n", GSMOPEN_P_LOG);
DEBUGA_GSMOPEN("AT+MCST=1 didn't get OK from the phone. If it is NOT Motorola," " no problem.\n", GSMOPEN_P_LOG);
}
/* for motorola end */
@ -530,7 +556,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
if (strlen(tech_pvt->at_postinit_1)) {
res = gsmopen_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_1, tech_pvt->at_postinit_1_expect);
if (res) {
DEBUGA_GSMOPEN("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_postinit_1, tech_pvt->at_postinit_1_expect);
DEBUGA_GSMOPEN("%s didn't get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_postinit_1, tech_pvt->at_postinit_1_expect);
}
} else {
break;
@ -539,7 +565,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
if (strlen(tech_pvt->at_postinit_2)) {
res = gsmopen_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_2, tech_pvt->at_postinit_2_expect);
if (res) {
DEBUGA_GSMOPEN("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_postinit_2, tech_pvt->at_postinit_2_expect);
DEBUGA_GSMOPEN("%s didn't get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_postinit_2, tech_pvt->at_postinit_2_expect);
}
} else {
break;
@ -548,7 +574,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
if (strlen(tech_pvt->at_postinit_3)) {
res = gsmopen_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_3, tech_pvt->at_postinit_3_expect);
if (res) {
DEBUGA_GSMOPEN("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_postinit_3, tech_pvt->at_postinit_3_expect);
DEBUGA_GSMOPEN("%s didn't get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_postinit_3, tech_pvt->at_postinit_3_expect);
}
} else {
break;
@ -557,7 +583,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
if (strlen(tech_pvt->at_postinit_4)) {
res = gsmopen_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_4, tech_pvt->at_postinit_4_expect);
if (res) {
DEBUGA_GSMOPEN("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_postinit_4, tech_pvt->at_postinit_4_expect);
DEBUGA_GSMOPEN("%s didn't get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_postinit_4, tech_pvt->at_postinit_4_expect);
}
} else {
break;
@ -566,7 +592,7 @@ int gsmopen_serial_config_AT(private_t *tech_pvt)
if (strlen(tech_pvt->at_postinit_5)) {
res = gsmopen_serial_write_AT_expect(tech_pvt, tech_pvt->at_postinit_5, tech_pvt->at_postinit_5_expect);
if (res) {
DEBUGA_GSMOPEN("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_postinit_5, tech_pvt->at_postinit_5_expect);
DEBUGA_GSMOPEN("%s didn't get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, tech_pvt->at_postinit_5, tech_pvt->at_postinit_5_expect);
}
} else {
break;
@ -588,7 +614,6 @@ int gsmopen_serial_sync_AT(private_t *tech_pvt)
int gsmopen_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 = 1;
int res;
struct timeval timeout;
char tmp_answer[AT_BUFSIZ];
char tmp_answer2[AT_BUFSIZ];
@ -608,7 +633,7 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
if (timeout_in_msec != 100)
DEBUGA_GSMOPEN("TIMEOUT=%d\n", GSMOPEN_P_LOG, timeout_in_msec);
if (!running || !tech_pvt->running) {
if (!running || !tech_pvt || !tech_pvt->running) {
return -1;
}
@ -728,7 +753,7 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
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 */
/* let's list the complete lines read so far, without re-listing the lines that have already been listed */
for (i = la_read; i < la_counter; i++) {
DEBUGA_GSMOPEN("Read line %d: |%s| la_counter=%d\n", GSMOPEN_P_LOG, i, tech_pvt->line_array.result[i], la_counter);
}
@ -754,7 +779,7 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
DEBUGA_GSMOPEN("|%s| got second RING\n", GSMOPEN_P_LOG, tech_pvt->line_array.result[i]);
tech_pvt->interface_state = GSMOPEN_STATE_RING;
} else {
/* we're at the first ring, so there is no CALLID yet thus clean the previous one
/* 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));
@ -762,7 +787,7 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
if (tech_pvt->at_has_clcc != 0) {
/* we're at the first ring, try to get CALLID (with +CLCC) */
DEBUGA_GSMOPEN("|%s| got first RING, sending AT+CLCC?\n", GSMOPEN_P_LOG, tech_pvt->line_array.result[i]);
res = gsmopen_serial_write_AT_noack(tech_pvt, "AT+CLCC?");
int res = gsmopen_serial_write_AT_noack(tech_pvt, "AT+CLCC?");
if (res) {
ERRORA("AT+CLCC? (call list) was not correctly sent to the phone\n", GSMOPEN_P_LOG);
}
@ -783,7 +808,7 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
memset(tech_pvt->callid_name, 0, sizeof(tech_pvt->callid_name));
memset(tech_pvt->callid_number, 0, sizeof(tech_pvt->callid_number));
for (a = 0; a < strlen(tech_pvt->line_array.result[i]); a++) {
for (a = 0; a < (int) strlen(tech_pvt->line_array.result[i]); a++) {
if (tech_pvt->line_array.result[i][a] == ',') {
commacount++;
@ -818,7 +843,7 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
memset(tech_pvt->callid_name, 0, sizeof(tech_pvt->callid_name));
memset(tech_pvt->callid_number, 0, sizeof(tech_pvt->callid_number));
for (a = 7; a < strlen(tech_pvt->line_array.result[i]); a++) {
for (a = 7; a < (int) strlen(tech_pvt->line_array.result[i]); a++) {
if (tech_pvt->line_array.result[i][a] == ',') {
commacount++;
}
@ -872,7 +897,7 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
tech_pvt->phone_callflow = CALLFLOW_CALL_LINEBUSY;
if (option_debug > 1)
DEBUGA_GSMOPEN("|%s| CALLFLOW_CALL_LINEBUSY\n", GSMOPEN_P_LOG, tech_pvt->line_array.result[i]);
//if (tech_pvt->interface_state != GSMOPEN_STATE_DOWN && tech_pvt->owner && tech_pvt->phone_callflow != CALLFLOW_CALL_DOWN)
//if (tech_pvt->interface_state != GSMOPEN_STATE_DOWN && tech_pvt->owner && tech_pvt->phone_callflow != CALLFLOW_CALL_DOWN)
if (tech_pvt->interface_state != GSMOPEN_STATE_DOWN && tech_pvt->phone_callflow != CALLFLOW_CALL_DOWN) {
//ast_setstate(tech_pvt->owner, GSMOPEN_STATE_BUSY);
//gsmopen_queue_control(tech_pvt->owner, GSMOPEN_CONTROL_BUSY);
@ -983,10 +1008,10 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
} else {
if (signal_quality < 9 || signal_quality == 99) {
ERRORA
("|%s| CELLPHONE GETS ALMOST NO SIGNAL, consider to move it or additional antenna\n",
("|%s| CELLPHONE GETS ALMOST NO SIGNAL, consider to move it or use additional antenna\n",
GSMOPEN_P_LOG, tech_pvt->line_array.result[i]);
tech_pvt->got_signal = 0;
alarm_event(tech_pvt, ALARM_NETWORK_NO_SIGNAL, "CELLPHONE GETS ALMOST NO SIGNAL, consider to move it or additional antenna");
alarm_event(tech_pvt, ALARM_NETWORK_NO_SIGNAL, "CELLPHONE GETS ALMOST NO SIGNAL, consider to move it or use additional antenna");
} else if (signal_quality < 11) {
WARNINGA("|%s| CELLPHONE GETS SIGNAL LOW\n", GSMOPEN_P_LOG, tech_pvt->line_array.result[i]);
tech_pvt->got_signal = 1;
@ -1011,13 +1036,13 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
} else {
if (stat == 0) {
ERRORA
("|%s| CELLPHONE is not registered to network, consider to move it or additional antenna\n",
("|%s| CELLPHONE is not registered to network, consider to move it or use additional antenna\n",
GSMOPEN_P_LOG, tech_pvt->line_array.result[i]);
tech_pvt->not_registered = 1;
tech_pvt->home_network_registered = 0;
tech_pvt->roaming_registered = 0;
alarm_event(tech_pvt, ALARM_NO_NETWORK_REGISTRATION,
"CELLPHONE is not registered to network, consider to move it or additional antenna");
"CELLPHONE is not registered to network, consider to move it or use additional antenna");
} else if (stat == 1) {
DEBUGA_GSMOPEN("|%s| CELLPHONE is registered to the HOME network\n", GSMOPEN_P_LOG, tech_pvt->line_array.result[i]);
tech_pvt->not_registered = 0;
@ -1199,9 +1224,9 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
char at_command[256];
if (tech_pvt->no_ucs2 == 0) {
res = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"UCS2\"");
int res = gsmopen_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", GSMOPEN_P_LOG);
ERRORA("AT+CSCS=\"UCS2\" (set TE messages to ucs2) didn't get OK from the phone, continuing\n", GSMOPEN_P_LOG);
//memset(tech_pvt->sms_message, 0, sizeof(tech_pvt->sms_message));
}
}
@ -1211,15 +1236,15 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
memset(tech_pvt->sms_message, 0, sizeof(tech_pvt->sms_message));
tech_pvt->reading_sms_msg = 1;
res = gsmopen_serial_write_AT_ack(tech_pvt, at_command);
int res = gsmopen_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", GSMOPEN_P_LOG, at_command);
ERRORA("AT+CMGR (read SMS) didn't get OK from the phone, message sent was:|||%s|||\n", GSMOPEN_P_LOG, at_command);
}
/*
res = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"CIAPALO1\"");
if (res) {
ERRORA("AT+CSCS=\"CIAPALO1\" (set TE messages to GSM) do not got OK from the phone\n", GSMOPEN_P_LOG);
ERRORA("AT+CSCS=\"CIAPALO1\" (set TE messages to GSM) didn't get OK from the phone\n", GSMOPEN_P_LOG);
}
*/
memset(at_command, 0, sizeof(at_command));
@ -1227,7 +1252,7 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
tech_pvt->unread_sms_msg_id = 0;
res = gsmopen_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", GSMOPEN_P_LOG, at_command);
ERRORA("AT+CMGD (Delete SMS) didn't get OK from the phone, message sent was:|||%s|||\n", GSMOPEN_P_LOG, at_command);
}
res = sms_incoming(tech_pvt);
@ -1236,7 +1261,7 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
/* we're not in a call, neither calling */
res = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CKPD=\"EEE\"");
if (res) {
DEBUGA_GSMOPEN("AT+CKPD=\"EEE\" (cellphone screen back to user) do not got OK from the phone\n", GSMOPEN_P_LOG);
DEBUGA_GSMOPEN("AT+CKPD=\"EEE\" (cellphone screen back to user) didn't get OK from the phone\n", GSMOPEN_P_LOG);
}
}
} //unread_msg_id
@ -1625,7 +1650,7 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
memset(content, '\0', sizeof(content));
for (c = 0; c < strlen(tech_pvt->line_array.result[i]); c++) {
for (c = 0; c < (int) 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;
@ -1722,10 +1747,10 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
ucs2_to_utf8(tech_pvt, (char *) bufToHex((unsigned char *) sms->userData().data(), sms->userData().length()).c_str(),
content2, sizeof(content2));
} else {
ERRORA("dataCodingScheme not supported=%d\n", GSMOPEN_P_LOG, sms->dataCodingScheme().getAlphabet());
ERRORA("dataCodingScheme not supported=%u\n", GSMOPEN_P_LOG, sms->dataCodingScheme().getAlphabet());
}
DEBUGA_GSMOPEN("dataCodingScheme=%d\n", GSMOPEN_P_LOG, sms->dataCodingScheme().getAlphabet());
DEBUGA_GSMOPEN("dataCodingScheme=%u\n", GSMOPEN_P_LOG, sms->dataCodingScheme().getAlphabet());
DEBUGA_GSMOPEN("dataCodingScheme=%s\n", GSMOPEN_P_LOG, sms->dataCodingScheme().toString().c_str());
DEBUGA_GSMOPEN("address=%s\n", GSMOPEN_P_LOG, sms->address().toString().c_str());
DEBUGA_GSMOPEN("serviceCentreAddress=%s\n", GSMOPEN_P_LOG, sms->serviceCentreAddress().toString().c_str());
@ -1812,7 +1837,7 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us
DEBUGA_GSMOPEN
("CALLFLOW_CALL_INCOMING call_incoming_time.tv_sec=%ld, call_incoming_timeout.tv_sec=%ld\n",
GSMOPEN_P_LOG, tech_pvt->call_incoming_time.tv_sec, call_incoming_timeout.tv_sec);
res = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CPBS=RC");
int res = gsmopen_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", GSMOPEN_P_LOG);
}
@ -1865,6 +1890,9 @@ int gsmopen_serial_write_AT(private_t *tech_pvt, const char *data)
int count;
char *Data = (char *) data;
if (!tech_pvt)
return -1;
howmany = strlen(Data);
for (i = 0; i < howmany; i++) {
@ -1977,6 +2005,9 @@ int gsmopen_serial_write_AT_nocr(private_t *tech_pvt, const char *data)
int count;
char *Data = (char *) data;
if (!tech_pvt)
return -1;
howmany = strlen(Data);
for (i = 0; i < howmany; i++) {
@ -2039,7 +2070,7 @@ int gsmopen_serial_write_AT_noack(private_t *tech_pvt, const char *data)
PUSHA_UNLOCKA(tech_pvt->controldev_lock);
LOKKA(tech_pvt->controldev_lock);
if (gsmopen_serial_write_AT(tech_pvt, data) != strlen(data)) {
if (gsmopen_serial_write_AT(tech_pvt, data) != (int) strlen(data)) {
ERRORA("Error sending data... (%s)\n", GSMOPEN_P_LOG, strerror(errno));
UNLOCKA(tech_pvt->controldev_lock);
@ -2075,16 +2106,19 @@ int gsmopen_serial_write_AT_ack(private_t *tech_pvt, const char *data)
{
int at_result = AT_ERROR;
if (!tech_pvt)
return -1;
PUSHA_UNLOCKA(tech_pvt->controldev_lock);
LOKKA(tech_pvt->controldev_lock);
if (option_debug > 1)
DEBUGA_GSMOPEN("sending: %s\n", GSMOPEN_P_LOG, data);
if (gsmopen_serial_write_AT(tech_pvt, data) != strlen(data)) {
if (gsmopen_serial_write_AT(tech_pvt, data) != (int) strlen(data)) {
ERRORA("Error sending data... (%s) \n", GSMOPEN_P_LOG, strerror(errno));
UNLOCKA(tech_pvt->controldev_lock);
ERRORA
("wrote -1 bytes!!! Nenormalno! Marking this gsmopen_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",
("wrote -1 bytes!!! Nenormalno! Marking this gsmopen_serial_device %s as dead, and if it is owned by a channel, hanging up. Maybe the phone is stuck, switched off, powered down or battery exhausted\n",
GSMOPEN_P_LOG, tech_pvt->controldevice_name);
tech_pvt->controldev_dead = 1;
//cicopet close(tech_pvt->controldevfd);
@ -2117,16 +2151,19 @@ int gsmopen_serial_write_AT_ack_nocr_longtime(private_t *tech_pvt, const char *d
{
int at_result = AT_ERROR;
if (!tech_pvt)
return -1;
PUSHA_UNLOCKA(tech_pvt->controldev_lock);
LOKKA(tech_pvt->controldev_lock);
if (option_debug > 1)
DEBUGA_GSMOPEN("sending: %s\n", GSMOPEN_P_LOG, data);
if (gsmopen_serial_write_AT_nocr(tech_pvt, data) != strlen(data)) {
if (gsmopen_serial_write_AT_nocr(tech_pvt, data) != (int) strlen(data)) {
ERRORA("Error sending data... (%s) \n", GSMOPEN_P_LOG, strerror(errno));
UNLOCKA(tech_pvt->controldev_lock);
ERRORA
("wrote -1 bytes!!! Nenormalno! Marking this gsmopen_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",
("wrote -1 bytes!!! Nenormalno! Marking this gsmopen_serial_device %s as dead, and if it is owned by a channel, hanging up. Maybe the phone is stuck, switched off, powered down or battery exhausted\n",
GSMOPEN_P_LOG, tech_pvt->controldevice_name);
tech_pvt->controldev_dead = 1;
//cicopet close(tech_pvt->controldevfd);
@ -2159,16 +2196,19 @@ int gsmopen_serial_write_AT_expect1(private_t *tech_pvt, const char *data, const
{
int at_result = AT_ERROR;
if (!tech_pvt)
return -1;
PUSHA_UNLOCKA(tech_pvt->controldev_lock);
LOKKA(tech_pvt->controldev_lock);
if (option_debug > 1)
DEBUGA_GSMOPEN("sending: %s, expecting: %s\n", GSMOPEN_P_LOG, data, expected_string);
if (gsmopen_serial_write_AT(tech_pvt, data) != strlen(data)) {
if (gsmopen_serial_write_AT(tech_pvt, data) != (int) strlen(data)) {
ERRORA("Error sending data... (%s) \n", GSMOPEN_P_LOG, strerror(errno));
UNLOCKA(tech_pvt->controldev_lock);
ERRORA
("wrote -1 bytes!!! Nenormalno! Marking this gsmopen_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",
("wrote -1 bytes!!! Nenormalno! Marking this gsmopen_serial_device %s as dead, and if it is owned by a channel, hanging up. Maybe the phone is stuck, switched off, powered down or battery exhausted\n",
GSMOPEN_P_LOG, tech_pvt->controldevice_name);
tech_pvt->controldev_dead = 1;
//cicopet close(tech_pvt->controldevfd);
@ -2201,6 +2241,10 @@ int gsmopen_serial_AT_expect(private_t *tech_pvt, const char *expected_string, i
{
int at_result = AT_ERROR;
if (!tech_pvt)
return -1;
PUSHA_UNLOCKA(tech_pvt->controldev_lock);
LOKKA(tech_pvt->controldev_lock);
if (option_debug > 1)
@ -2234,6 +2278,9 @@ int gsmopen_serial_answer_AT(private_t *tech_pvt)
{
int res;
if (!tech_pvt)
return -1;
res = gsmopen_serial_write_AT_expect(tech_pvt, tech_pvt->at_answer, tech_pvt->at_answer_expect);
if (res) {
DEBUGA_GSMOPEN
@ -2272,6 +2319,9 @@ int gsmopen_serial_hangup_AT(private_t *tech_pvt)
{
int res;
if (!tech_pvt)
return -1;
if (tech_pvt->interface_state != GSMOPEN_STATE_DOWN) {
res = gsmopen_serial_write_AT_expect(tech_pvt, tech_pvt->at_hangup, tech_pvt->at_hangup_expect);
if (res) {
@ -2327,9 +2377,9 @@ int gsmopen_serial_call_AT(private_t *tech_pvt, char *dstr)
/*
size_t fixdstr = strspn(dstr, AST_DIGIT_ANYDIG);
if (fixdstr == 0) {
ERRORA("dial command failed because of invalid dial number. dial string was: %s\n",
GSMOPEN_P_LOG, dstr);
return -1;
ERRORA("dial command failed because of invalid dial number. dial string was: %s\n",
GSMOPEN_P_LOG, dstr);
return -1;
}
*/
//dstr[fixdstr] = '\0';
@ -2367,7 +2417,7 @@ int ucs2_to_utf8(private_t *tech_pvt, char *ucs2_in, char *utf8_out, size_t outb
DEBUGA_GSMOPEN("ucs2_in=|%s|, utf8_out=|%s|\n", GSMOPEN_P_LOG, ucs2_in, utf8_out);
/* cicopet */
for (c = 0; c < strlen(ucs2_in); c++) {
for (c = 0; c < (int) strlen(ucs2_in); c++) {
sprintf(stringa, "0x%c%c", ucs2_in[c], ucs2_in[c + 1]);
c++;
hexnum = strtod(stringa, NULL);
@ -2548,7 +2598,7 @@ int utf8_to_ucs2(private_t *tech_pvt, char *utf8_in, size_t inbytesleft, char *u
GSMOPEN_P_LOG, iconv_res, inbuf, (int) inbytesleft, outbuf, (int) outbytesleft, utf8_in, converted);
iconv_close(iconv_format);
for (i = 0; i < 16000 - outbytesleft; i++) {
for (i = 0; i < 16000 - (int) outbytesleft; i++) {
memset(stringa, '\0', sizeof(stringa));
memset(stringa2, '\0', sizeof(stringa2));
sprintf(stringa, "%02X", converted[i]);
@ -2779,14 +2829,14 @@ int gsmopen_sendsms(private_t *tech_pvt, char *dest, char *text)
memset(mesg_test, '\0', sizeof(mesg_test));
sprintf(mesg_test, ":) ciao belè новости לק ראת ﺎﻠﺠﻤﻋﺓ 人大aèéàòçù"); //let's test the beauty of utf8
//sprintf(mesg_test,":) ciao belè èéàòìù");
//sprintf(mesg_test,":) ciao belè èéàòìù");
//text=mesg_test;
bad_8859 = utf8_to_iso_8859_1(tech_pvt, text, strlen(text), smscommand, sizeof(smscommand));
if (!bad_8859) {
err = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CMGF=0");
if (err) {
ERRORA("AT+CMGF=0 (set message sending to PDU (as opposed to TEXT) do not got OK from the phone\n", GSMOPEN_P_LOG);
ERRORA("AT+CMGF=0 (set message sending to PDU (as opposed to TEXT) didn't get OK from the phone\n", GSMOPEN_P_LOG);
}
SMSMessageRef smsMessage;
smsMessage = new SMSSubmitMessage(smscommand, dest);
@ -2823,13 +2873,13 @@ int gsmopen_sendsms(private_t *tech_pvt, char *dest, char *text)
err = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CMGF=1");
if (err) {
ERRORA("AT+CMGF=1 (set message sending to TEXT (as opposed to PDU) do not got OK from the phone\n", GSMOPEN_P_LOG);
ERRORA("AT+CMGF=1 (set message sending to TEXT (as opposed to PDU) didn't get OK from the phone\n", GSMOPEN_P_LOG);
}
/*
err = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"UCS2\"");
if (err) {
ERRORA("AT+CSCS=\"UCS2\" (set TE messages to ucs2) do not got OK from the phone\n", GSMOPEN_P_LOG);
ERRORA("AT+CSCS=\"UCS2\" (set TE messages to ucs2) didn't get OK from the phone\n", GSMOPEN_P_LOG);
}
*/
@ -2916,7 +2966,7 @@ int gsmopen_sendsms(private_t *tech_pvt, char *dest, char *text)
if (tech_pvt->at_cmgw[0]) {
/* let's see what we've sent, just for check TODO: Motorola it's not reliable! Motorola c350 tells that all was sent, but is not true! It just sends how much it fits into one SMS FIXME: need an algorithm to calculate how many ucs2 chars fits into an SMS. It make difference based, probably, on the GSM alphabet translation, or so */
/* let's see what we've sent, just for check TODO: Motorola isn't reliable! Motorola c350 tells that all was sent, but is not true! It just sends how much it fits into one SMS FIXME: need an algorithm to calculate how many ucs2 chars fits into an SMS. It make difference based, probably, on the GSM alphabet translation, or so */
sprintf(smscommand, "AT+CMGR=%s", tech_pvt->at_cmgw);
err = gsmopen_serial_write_AT_ack(tech_pvt, smscommand);
if (err) {
@ -2995,7 +3045,7 @@ int gsmopen_sound_boost(void *data, int samples_num, double boost)
} else if (x < -32768) {
x = -32768;
}
ptr[i] = x;
ptr[i] = (int16_t) x;
}
} else {
//printf("BOOST=%f\n", boost);
@ -3009,6 +3059,9 @@ int gsmopen_serial_getstatus_AT(private_t *tech_pvt)
int res;
private_t *p = tech_pvt;
if (!p)
return -1;
#if 0
if (p->owner) {
if (p->owner->_state != AST_STATE_UP && p->owner->_state != AST_STATE_DOWN) {
@ -3029,7 +3082,7 @@ int gsmopen_serial_getstatus_AT(private_t *tech_pvt)
if (strlen(p->at_query_battchg)) {
res = gsmopen_serial_write_AT_expect(p, p->at_query_battchg, p->at_query_battchg_expect);
if (res) {
WARNINGA("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, p->at_query_battchg, p->at_query_battchg_expect);
WARNINGA("%s didn't get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, p->at_query_battchg, p->at_query_battchg_expect);
}
gsmopen_sleep(1000);
}
@ -3037,7 +3090,7 @@ int gsmopen_serial_getstatus_AT(private_t *tech_pvt)
if (strlen(p->at_query_signal)) {
res = gsmopen_serial_write_AT_expect(p, p->at_query_signal, p->at_query_signal_expect);
if (res) {
WARNINGA("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, p->at_query_signal, p->at_query_signal_expect);
WARNINGA("%s didn't get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, p->at_query_signal, p->at_query_signal_expect);
}
gsmopen_sleep(1000);
}
@ -3045,7 +3098,7 @@ int gsmopen_serial_getstatus_AT(private_t *tech_pvt)
if (!p->network_creg_not_supported) {
res = gsmopen_serial_write_AT_ack(p, "AT+CREG?");
if (res) {
WARNINGA("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, "AT+CREG?", "OK");
WARNINGA("%s didn't get %s from the phone. Continuing.\n", GSMOPEN_P_LOG, "AT+CREG?", "OK");
}
gsmopen_sleep(1000);
}
@ -3055,7 +3108,7 @@ int gsmopen_serial_getstatus_AT(private_t *tech_pvt)
res = gsmopen_serial_write_AT_ack(p, "AT+MMGL=\"HEADER ONLY\"");
if (res) {
WARNINGA
("%s does not get %s from the phone. If your phone is not Motorola, please contact the gsmopen developers. Else, if your phone IS a Motorola, probably a long msg was incoming and ther first part was read and then deleted. The second part is now orphan. If you got this warning repeatedly, and you cannot correctly receive SMSs from this interface, please manually clean all messages (and the residual parts of them) from the cellphone/SIM. Continuing.\n",
("%s didn't get %s from the phone. If your phone is not Motorola, please contact the gsmopen developers. Else, if your phone IS a Motorola, probably a long msg was incoming and ther first part was read and then deleted. The second part is now orphan. If you got this warning repeatedly, and you cannot correctly receive SMSs from this interface, please manually clean all messages (and the residual parts of them) from the cellphone/SIM. Continuing.\n",
GSMOPEN_P_LOG, "AT+MMGL=\"HEADER ONLY\"", "OK");
} else {
gsmopen_sleep(1000);
@ -3064,7 +3117,7 @@ int gsmopen_serial_getstatus_AT(private_t *tech_pvt)
res = gsmopen_serial_write_AT_ack(p, "AT+CSCS=\"UCS2\"");
if (res) {
ERRORA("AT+CSCS=\"UCS2\" (set TE messages to ucs2) do not got OK from the phone\n", GSMOPEN_P_LOG);
ERRORA("AT+CSCS=\"UCS2\" (set TE messages to ucs2) didn't get OK from the phone\n", GSMOPEN_P_LOG);
memset(p->sms_message, 0, sizeof(p->sms_message));
}
@ -3076,18 +3129,18 @@ int gsmopen_serial_getstatus_AT(private_t *tech_pvt)
res = gsmopen_serial_write_AT_ack(p, at_command);
p->reading_sms_msg = 0;
if (res) {
ERRORA("AT+CMGR (read SMS) do not got OK from the phone, message sent was:|||%s|||\n", GSMOPEN_P_LOG, at_command);
ERRORA("AT+CMGR (read SMS) didn't get OK from the phone, message sent was:|||%s|||\n", GSMOPEN_P_LOG, at_command);
}
res = gsmopen_serial_write_AT_ack(p, "AT+CSCS=\"GSM\"");
if (res) {
ERRORA("AT+CSCS=\"GSM\" (set TE messages to GSM) do not got OK from the phone\n", GSMOPEN_P_LOG);
ERRORA("AT+CSCS=\"GSM\" (set TE messages to GSM) didn't get OK from the phone\n", GSMOPEN_P_LOG);
}
memset(at_command, 0, sizeof(at_command));
sprintf(at_command, "AT+CMGD=%d", p->unread_sms_msg_id); /* delete the message */
p->unread_sms_msg_id = 0;
res = gsmopen_serial_write_AT_ack(p, at_command);
if (res) {
ERRORA("AT+CMGD (Delete SMS) do not got OK from the phone, message sent was:|||%s|||\n", GSMOPEN_P_LOG, at_command);
ERRORA("AT+CMGD (Delete SMS) didn't get OK from the phone, message sent was:|||%s|||\n", GSMOPEN_P_LOG, at_command);
}
if (strlen(p->sms_message)) {
@ -3138,7 +3191,7 @@ int gsmopen_serial_getstatus_AT(private_t *tech_pvt)
/* we're not in a call, neither calling */
res = gsmopen_serial_write_AT_ack(p, "AT+CKPD=\"EEE\"");
if (res) {
ERRORA("AT+CKPD=\"EEE\" (cellphone screen back to user) do not got OK from the phone\n", GSMOPEN_P_LOG);
ERRORA("AT+CKPD=\"EEE\" (cellphone screen back to user) didn't get OK from the phone\n", GSMOPEN_P_LOG);
}
}
#endif
@ -3153,13 +3206,41 @@ int gsmopen_serial_getstatus_AT(private_t *tech_pvt)
int gsmopen_serial_init_audio_port(private_t *tech_pvt, int controldevice_audio_speed)
{
/*
* TODO
* hmm, it doesn't look very different from gsmopen_serial_init_port, does it?
*/
if (!tech_pvt)
return -1;
tech_pvt->serialPort_serial_audio = new ctb::SerialPort();
//if( tech_pvt->serialPort_serial_audio->Open( "COM8", 115200, "8N1", ctb::SerialPort::NoFlowControl ) >= 0 ) {
if (tech_pvt->serialPort_serial_audio->Open(tech_pvt->controldevice_audio_name, 115200, "8N1", ctb::SerialPort::NoFlowControl) >= 0) {
/* windows: com ports above com9 need a special trick, which also works for com ports below com10 ... */
char devname[512] = "";
strcpy(devname, tech_pvt->controldevice_audio_name);
#ifdef WIN32
strcpy(devname,"\\\\.\\");
strcat(devname, tech_pvt->controldevice_audio_name);
#endif
if (tech_pvt->serialPort_serial_audio->Open(devname, 115200, "8N1", ctb::SerialPort::NoFlowControl) >= 0) {
DEBUGA_GSMOPEN("port %s, SUCCESS open\n", GSMOPEN_P_LOG, tech_pvt->controldevice_audio_name);
} else {
#ifdef WIN32
LPVOID msg;
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &msg,
0,
NULL);
ERRORA("port open failed for %s - %s", GSMOPEN_P_LOG, devname, (LPCTSTR) msg);
LocalFree(msg);
#else
ERRORA("port %s, NOT open\n", GSMOPEN_P_LOG, tech_pvt->controldevice_audio_name);
#endif
return -1;
}
@ -3186,11 +3267,12 @@ int serial_audio_shutdown(private_t *tech_pvt)
{
int res;
int err;
if (!tech_pvt || !tech_pvt->serialPort_serial_audio)
return -1;
res = tech_pvt->serialPort_serial_audio->Close();
DEBUGA_GSMOPEN("serial_audio_shutdown res=%d (controldev_audio_fd is %d)\n", GSMOPEN_P_LOG, res, tech_pvt->controldev_audio_fd);
err = res;
return err;
return res;
}

View File

@ -86,7 +86,7 @@ SWITCH_MODULE_DEFINITION(mod_gsmopen, mod_gsmopen_load, mod_gsmopen_shutdown, NU
SWITCH_END_EXTERN_C
#define GSMOPEN_CHAT_PROTO "sms"
#if 1
SWITCH_STANDARD_API(gsm_function);
SWITCH_STANDARD_API(gsm_function);
/* BEGIN: Changes here */
#define GSM_SYNTAX "list [full] || console || AT_command || remove < interface_name | interface_id > || reload"
/* END: Changes heres */
@ -391,7 +391,7 @@ static switch_status_t remove_interface(char *the_interface)
goto end;
}
LOKKA(tech_pvt->controldev_lock);
LOKKA(tech_pvt->controldev_lock);
globals.GSMOPEN_INTERFACES[interface_id].running = 0;
@ -473,7 +473,7 @@ static switch_status_t remove_interface(char *the_interface)
close(tech_pvt->GSMopenHandles.fdesc[1]);
#endif /* WIN32 */
UNLOCKA(tech_pvt->controldev_lock);
UNLOCKA(tech_pvt->controldev_lock);
switch_mutex_lock(globals.mutex);
if (globals.gsm_console == &globals.GSMOPEN_INTERFACES[interface_id]) {
DEBUGA_GSMOPEN("interface '%s' no more console\n", GSMOPEN_P_LOG, the_interface);
@ -496,8 +496,8 @@ static switch_status_t remove_interface(char *the_interface)
/* END: Changes here */
/*
State methods they get called when the state changes to the specific state
/*
State methods that get called when the state changes to the specific state
returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
*/
@ -509,6 +509,8 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
tech_pvt = (private_t *) switch_core_session_get_private(session);
switch_assert(tech_pvt != NULL);
memset(tech_pvt->buffer2, 0, sizeof(tech_pvt->buffer2));
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
//ERRORA("%s CHANNEL INIT\n", GSMOPEN_P_LOG, tech_pvt->name);
@ -559,6 +561,7 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session)
if (tech_pvt->phone_callflow == CALLFLOW_STATUS_FINISHED) {
tech_pvt->phone_callflow = CALLFLOW_CALL_IDLE;
}
memset(tech_pvt->buffer2, 0, sizeof(tech_pvt->buffer2));
switch_core_session_set_private(session, NULL);
} else {
DEBUGA_GSMOPEN("!!!!!!NO tech_pvt!!!! CHANNEL DESTROY %s\n", GSMOPEN_P_LOG, switch_core_session_get_uuid(session));
@ -689,7 +692,9 @@ static switch_status_t channel_on_consume_media(switch_core_session_t *session)
tech_pvt = (private_t *) switch_core_session_get_private(session);
DEBUGA_GSMOPEN("%s CHANNEL CONSUME_MEDIA\n", GSMOPEN_P_LOG, tech_pvt->name);
if (tech_pvt) {
DEBUGA_GSMOPEN("%s CHANNEL CONSUME_MEDIA\n", GSMOPEN_P_LOG, tech_pvt->name);
}
return SWITCH_STATUS_SUCCESS;
}
@ -697,7 +702,9 @@ static switch_status_t channel_on_exchange_media(switch_core_session_t *session)
{
private_t *tech_pvt = NULL;
tech_pvt = (private_t *) switch_core_session_get_private(session);
DEBUGA_GSMOPEN("%s CHANNEL EXCHANGE_MEDIA\n", GSMOPEN_P_LOG, tech_pvt->name);
if (tech_pvt) {
DEBUGA_GSMOPEN("%s CHANNEL EXCHANGE_MEDIA\n", GSMOPEN_P_LOG, tech_pvt->name);
}
return SWITCH_STATUS_SUCCESS;
}
@ -705,7 +712,9 @@ static switch_status_t channel_on_soft_execute(switch_core_session_t *session)
{
private_t *tech_pvt = NULL;
tech_pvt = (private_t *) switch_core_session_get_private(session);
DEBUGA_GSMOPEN("%s CHANNEL SOFT_EXECUTE\n", GSMOPEN_P_LOG, tech_pvt->name);
if (tech_pvt) {
DEBUGA_GSMOPEN("%s CHANNEL SOFT_EXECUTE\n", GSMOPEN_P_LOG, tech_pvt->name);
}
return SWITCH_STATUS_SUCCESS;
}
@ -729,7 +738,6 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
switch_byte_t *data;
int samples;
int samples2;
char digit_str[256];
char buffer2[640];
@ -757,6 +765,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
if (tech_pvt->no_sound) {
goto cng;
}
memset(buffer2, 0, sizeof(buffer2));
samples = tech_pvt->serialPort_serial_audio->Read(buffer2, 640);
if (samples >= 320) {
@ -778,6 +787,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
tech_pvt->buffer2_full = 0;
samples = 320;
DEBUGA_GSMOPEN("samples=%d FROM BUFFER\n", GSMOPEN_P_LOG, samples);
memset(tech_pvt->buffer2, 0, sizeof(tech_pvt->buffer2));
}
}
@ -793,6 +803,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
switch_mutex_unlock(tech_pvt->flag_mutex);
if (samples != 320) {
memset(tech_pvt->buffer2, 0, sizeof(tech_pvt->buffer2));
if (samples != 0) {
DEBUGA_GSMOPEN("samples=%d, goto cng\n", GSMOPEN_P_LOG, samples);
}
@ -809,7 +820,6 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
switch_time_t new_dtmf_timestamp = switch_time_now();
if ((new_dtmf_timestamp - tech_pvt->old_dtmf_timestamp) > 350000) { //FIXME: make it configurable
char *p = digit_str;
switch_channel_t *channel = switch_core_session_get_channel(session);
while (p && *p) {
switch_dtmf_t dtmf = { 0 };
@ -907,7 +917,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
sent = tech_pvt->serialPort_serial_audio->Write((char *) frame->data, (int) (frame->datalen));
if (sent && sent != frame->datalen && sent != -1) {
DEBUGA_GSMOPEN("sent %d\n", GSMOPEN_P_LOG, sent);
DEBUGA_GSMOPEN("sent %u\n", GSMOPEN_P_LOG, sent);
}
}
return SWITCH_STATUS_SUCCESS;
@ -1056,7 +1066,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
private_t *tech_pvt = NULL;
int result;
if ((*new_session = switch_core_session_request_uuid(gsmopen_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, flags, pool, switch_event_get_header(var_event, "origination_uuid"))) != 0) {
if ((*new_session = switch_core_session_request_uuid(gsmopen_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, flags, pool, switch_event_get_header(var_event, "origination_uuid"))) != 0) {
switch_channel_t *channel = NULL;
switch_caller_profile_t *caller_profile;
@ -1198,12 +1208,12 @@ static switch_status_t load_config(int reload_type)
private_t *tech_pvt = NULL;
#ifdef WIN32
DEBUGA_GSMOPEN("Windows CODEPAGE Input =%d\n", GSMOPEN_P_LOG, GetConsoleCP());
DEBUGA_GSMOPEN("Windows CODEPAGE Input =%u\n", GSMOPEN_P_LOG, GetConsoleCP());
SetConsoleCP(65001);
DEBUGA_GSMOPEN("Windows CODEPAGE Input =%d\n", GSMOPEN_P_LOG, GetConsoleCP());
DEBUGA_GSMOPEN("Windows CODEPAGE Output =%d\n", GSMOPEN_P_LOG, GetConsoleOutputCP());
DEBUGA_GSMOPEN("Windows CODEPAGE Input =%u\n", GSMOPEN_P_LOG, GetConsoleCP());
DEBUGA_GSMOPEN("Windows CODEPAGE Output =%u\n", GSMOPEN_P_LOG, GetConsoleOutputCP());
SetConsoleOutputCP(65001);
DEBUGA_GSMOPEN("Windows CODEPAGE Output =%d\n", GSMOPEN_P_LOG, GetConsoleOutputCP());
DEBUGA_GSMOPEN("Windows CODEPAGE Output =%u\n", GSMOPEN_P_LOG, GetConsoleOutputCP());
//let's hope to have unicode in console now. You need to use Lucida Console or, much better, Courier New font for the command prompt to show unicode
#endif // WIN32
NOTICA("GSMOPEN Charset Output Test 0 %s\n", GSMOPEN_P_LOG, "èéòàù");
@ -1664,7 +1674,7 @@ static switch_status_t load_config(int reload_type)
globals.GSMOPEN_INTERFACES[interface_id].controldevprotocol = controldevprotocol; //FIXME
globals.GSMOPEN_INTERFACES[interface_id].running = running; //FIXME
WARNINGA("STARTING interface_id=%d\n", GSMOPEN_P_LOG, interface_id);
WARNINGA("STARTING interface_id=%u\n", GSMOPEN_P_LOG, interface_id);
DEBUGA_GSMOPEN("id=%s\n", GSMOPEN_P_LOG, globals.GSMOPEN_INTERFACES[interface_id].id);
DEBUGA_GSMOPEN("name=%s\n", GSMOPEN_P_LOG, globals.GSMOPEN_INTERFACES[interface_id].name);
DEBUGA_GSMOPEN("hold-music=%s\n", GSMOPEN_P_LOG, globals.GSMOPEN_INTERFACES[interface_id].hold_music);
@ -1681,8 +1691,7 @@ static switch_status_t load_config(int reload_type)
globals.GSMOPEN_INTERFACES[interface_id].controldevfd =
gsmopen_serial_init(&globals.GSMOPEN_INTERFACES[interface_id], globals.GSMOPEN_INTERFACES[interface_id].controldevice_speed);
if (globals.GSMOPEN_INTERFACES[interface_id].controldevfd == -1) {
ERRORA("gsmopen_serial_init failed\n", GSMOPEN_P_LOG);
ERRORA("STARTING interface_id=%d FAILED\n", GSMOPEN_P_LOG, interface_id);
ERRORA("STARTING interface_id=%u FAILED: gsmopen_serial_init failed\n", GSMOPEN_P_LOG, interface_id);
//return SWITCH_STATUS_FALSE;
globals.GSMOPEN_INTERFACES[interface_id].running = 0;
alarm_event(&globals.GSMOPEN_INTERFACES[interface_id], ALARM_FAILED_INTERFACE, "gsmopen_serial_init failed");
@ -1707,7 +1716,7 @@ static switch_status_t load_config(int reload_type)
}
}
if (res) {
ERRORA("STARTING interface_id=%d FAILED\n", GSMOPEN_P_LOG, interface_id);
ERRORA("STARTING interface_id=%u FAILED\n", GSMOPEN_P_LOG, interface_id);
//return SWITCH_STATUS_FALSE;
globals.GSMOPEN_INTERFACES[interface_id].running = 0;
alarm_event(&globals.GSMOPEN_INTERFACES[interface_id], ALARM_FAILED_INTERFACE, "gsmopen_serial_config failed");
@ -1721,7 +1730,7 @@ static switch_status_t load_config(int reload_type)
if (globals.GSMOPEN_INTERFACES[interface_id].no_sound == 0) {
if (serial_audio_init(&globals.GSMOPEN_INTERFACES[interface_id])) {
ERRORA("serial_audio_init failed\n", GSMOPEN_P_LOG);
ERRORA("STARTING interface_id=%d FAILED\n", GSMOPEN_P_LOG, interface_id);
ERRORA("STARTING interface_id=%u FAILED\n", GSMOPEN_P_LOG, interface_id);
//return SWITCH_STATUS_FALSE;
globals.GSMOPEN_INTERFACES[interface_id].running = 0;
alarm_event(&globals.GSMOPEN_INTERFACES[interface_id], ALARM_FAILED_INTERFACE, "serial_audio_init failed");
@ -1733,7 +1742,7 @@ static switch_status_t load_config(int reload_type)
if (serial_audio_shutdown(&globals.GSMOPEN_INTERFACES[interface_id])) {
ERRORA("serial_audio_shutdown failed\n", GSMOPEN_P_LOG);
ERRORA("STARTING interface_id=%d FAILED\n", GSMOPEN_P_LOG, interface_id);
ERRORA("STARTING interface_id=%u FAILED\n", GSMOPEN_P_LOG, interface_id);
//return SWITCH_STATUS_FALSE;
globals.GSMOPEN_INTERFACES[interface_id].running = 0;
alarm_event(&globals.GSMOPEN_INTERFACES[interface_id], ALARM_FAILED_INTERFACE, "serial_audio_shutdown failed");
@ -1759,10 +1768,10 @@ static switch_status_t load_config(int reload_type)
&globals.GSMOPEN_INTERFACES[interface_id], gsmopen_module_pool);
switch_sleep(100000);
WARNINGA("STARTED interface_id=%d\n", GSMOPEN_P_LOG, interface_id);
WARNINGA("STARTED interface_id=%u\n", GSMOPEN_P_LOG, interface_id);
} else {
ERRORA("interface id %d is higher than GSMOPEN_MAX_INTERFACES (%d)\n", GSMOPEN_P_LOG, interface_id, GSMOPEN_MAX_INTERFACES);
ERRORA("interface id %u is higher than GSMOPEN_MAX_INTERFACES (%d)\n", GSMOPEN_P_LOG, interface_id, GSMOPEN_MAX_INTERFACES);
alarm_event(&globals.GSMOPEN_INTERFACES[interface_id], ALARM_FAILED_INTERFACE, "interface id is higher than GSMOPEN_MAX_INTERFACES");
continue;
}
@ -2020,11 +2029,15 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_gsmopen_shutdown)
DEBUGA_GSMOPEN("SHUTDOWN tech_pvt->controldevfd=%d\n", GSMOPEN_P_LOG, tech_pvt->controldevfd);
}
serial_audio_shutdown(tech_pvt);
if (!globals.GSMOPEN_INTERFACES[interface_id].no_sound) {
serial_audio_shutdown(tech_pvt);
}
int res;
res = tech_pvt->serialPort_serial_control->Close();
DEBUGA_GSMOPEN("serial_shutdown res=%d (controldevfd is %d)\n", GSMOPEN_P_LOG, res, tech_pvt->controldevfd);
if (tech_pvt->serialPort_serial_control) {
int res;
res = tech_pvt->serialPort_serial_control->Close();
DEBUGA_GSMOPEN("serial_shutdown res=%d (controldevfd is %d)\n", GSMOPEN_P_LOG, res, tech_pvt->controldevfd);
}
#ifndef WIN32
shutdown(tech_pvt->audiogsmopenpipe[0], 2);
@ -2238,13 +2251,13 @@ private_t *find_available_gsmopen_interface_rr(private_t *tech_pvt_calling)
{
private_t *tech_pvt = NULL;
int i;
//int num_interfaces = GSMOPEN_MAX_INTERFACES;
//int num_interfaces = GSMOPEN_MAX_INTERFACES;
//int num_interfaces = globals.real_interfaces;
switch_mutex_lock(globals.mutex);
/* Fact is the real interface start from 1 */
//XXX no, is just a convention, but you can have it start from 0. I do not, for aestetic reasons :-)
//XXX no, is just a convention, but you can have it start from 0. I do not, for aestetic reasons :-)
//if (globals.next_interface == 0) globals.next_interface = 1;
for (i = 0; i < GSMOPEN_MAX_INTERFACES; i++) {
@ -2267,7 +2280,7 @@ private_t *find_available_gsmopen_interface_rr(private_t *tech_pvt_calling)
DEBUGA_GSMOPEN("returning as available gsmopen interface name: %s, state: %d callflow: %d\n", GSMOPEN_P_LOG, tech_pvt->name, gsmopen_state,
tech_pvt->phone_callflow);
/*set to Dialing state to avoid other thread fint it, don't know if it is safe */
//XXX no, it's not safe
//XXX no, it's not safe
if (tech_pvt_calling == NULL) {
tech_pvt->interface_state = GSMOPEN_STATE_SELECTED;
}
@ -2475,9 +2488,9 @@ SWITCH_STANDARD_API(gsmopen_dump_function)
stream->write_function(stream, "ERROR, usage: %s", GSMOPEN_DUMP_SYNTAX);
goto end;
}
if (argc == 1) {
int i;
if (argc == 1 && argv[0]) {
int found = 0;
int i = 0;
for (i = 0; !found && i < GSMOPEN_MAX_INTERFACES; i++) {
/* we've been asked for a normal interface name, or we have not found idle interfaces to serve as the "ANY" interface */
@ -2491,7 +2504,6 @@ SWITCH_STANDARD_API(gsmopen_dump_function)
}
if (!found && (strcmp("list", argv[0]) == 0)) {
int i;
stream->write_function(stream, "gsmopen_dump LIST\n\n");
for (i = 0; i < GSMOPEN_MAX_INTERFACES; i++) {
if (strlen(globals.GSMOPEN_INTERFACES[i].name)) {
@ -2628,7 +2640,7 @@ SWITCH_STANDARD_API(gsmopen_boost_audio_function)
argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
}
if (argc == 1 || argc == 3) {
if ((argc == 1 || argc == 3) && argv[0]) {
int i;
int found = 0;
@ -2811,8 +2823,8 @@ void *gsmopen_do_gsmopenapi_thread_func(void *obj)
private_t *tech_pvt = (private_t *) obj;
time_t now_timestamp;
//if (gsmopen_present(GSMopenHandles))
while (running && tech_pvt->running) {
//if (gsmopen_present(GSMopenHandles))
while (running && tech_pvt && tech_pvt->running) {
int res;
//gsmopen_sleep(1000000); //1 sec
//DEBUGA_GSMOPEN("ciao!\n", GSMOPEN_P_LOG);
@ -2933,6 +2945,9 @@ int dump_event_full(private_t *tech_pvt, int is_alarm, int alarm_code, const cha
switch_channel_t *channel = NULL;
switch_status_t status;
if (!tech_pvt) {
return -1;
}
session = switch_core_session_locate(tech_pvt->session_uuid_str);
if (session) {
channel = switch_core_session_get_channel(session);
@ -3030,13 +3045,17 @@ int alarm_event(private_t *tech_pvt, int alarm_code, const char *alarm_message)
int sms_incoming(private_t *tech_pvt)
{
switch_event_t *event;
#ifdef NOTDEF
switch_core_session_t *session = NULL;
int event_sent_to_esl = 0;
#endif
if (!tech_pvt) {
return -1;
}
//DEBUGA_GSMOPEN("received SMS on interface %s: %s\n", GSMOPEN_P_LOG, tech_pvt->name, tech_pvt->sms_message);
DEBUGA_GSMOPEN("received SMS on interface %s: DATE=%s, SENDER=%s, BODY=%s|\n", GSMOPEN_P_LOG, tech_pvt->name, tech_pvt->sms_date, tech_pvt->sms_sender,
tech_pvt->sms_body);
tech_pvt->sms_body);
#ifdef NOTDEF
if (!zstr(tech_pvt->session_uuid_str)) {
session = switch_core_session_locate(tech_pvt->session_uuid_str);