void gsm4_init( void ) { engine_init( gsm4_evn_default ); at_cmd_save( "RING", 1000, NULL, NULL, NULL, gsm4_ev_ring ); at_cmd( "AT" ); at_cmd( "AT+CSCS=\"GSM\"" ); at_cmd( "AT+CMGF=1" ); }
static int at_parse_message_list(FILE *fp) { char buf[0x1000]; if (at_cmd(fp, NULL, "+CMGF=1") != 0) return -1; if (at_cmd(fp, buf, "+CPMS=?") != 1) return -1; return at_parse_brackets(fp, buf, at_parse_message_storage); }
int try_serial_mode (struct serial *s, struct serial_mode *serial_mode, flag_t flags) { if (set_serial (s, serial_mode) == -1) { error (0, 0, "could not set serial_mode"); return (-1); } if (!_anyset (flags, INT6KDETECT_CMD_MODE)) wakeup (s); at_cmd (s); return (at_cmd (s)); }
static bool test_rawdata_transfer(void) { int ret; char http_req[] = "GET /404.file HTTP/1.0\r\nHost: " SERVER_HOST "\r\n\r\n"; char http_resp_expected[] = "HTTP/1.0 404 Not Found"; char http_resp[1024 * 100]; size_t resp_size = sizeof(http_resp); ASSERT(wait_gsm_status(1), "wait_gsm_status(%d) failed", 1); ret = gsm_activate_context(f_gsm); ASSERT(ret == 0, "gsm_activate_context() = %d", ret); ret = at_cmd(f_gsm, "AT#SKTD=0," SERVER_PORT ",\"" SERVER_HOST "\",0,0"); ASSERT(ret == 0, "at_cmd(AT#SKTD) = %d\n", ret); ret = at_verify_response(f_gsm, "\r\nCONNECT\r\n", 60 * HZ); ASSERT(ret == 0, "at_verify_response(CONNECT) = %d\n", ret); ret = fwrite(http_req, 1, sizeof(http_req) - 1, f_gsm); ASSERT(ret == sizeof(http_req) - 1, "fwrite(HTTP) = %d\n", ret); ret = at_recv(http_resp, &resp_size); ASSERT((ret == 0 || ret == -ETIMEOUT) && resp_size > 100, "at_recv(http_resp) = %d\n", ret); http_resp[resp_size] = '\0'; ret = memcmp(http_resp, http_resp_expected, strlen(http_resp_expected)); ASSERT(ret == 0, "HTTP response mismatch, buf = %s", http_resp); printf("%s: HTTP response from %s OK\n", __func__, SERVER_HOST); return true; }
void gsm4_send_sms( uint8_t* rsp, uint8_t rsp_len ) { at_cmd( "AT+CMGS=\"0643280993\"" ); at_cmd_addition( "Hello it's me, Hexiwear! :)" ); Delay_ms( 1000 ); sent_f = true; }
static int at_parse_phonebook_list(FILE *fp) { char buf[0x1000]; if (at_cmd(fp, buf, "+CPBS=?") != 1) return -1; return at_parse_brackets(fp, buf, at_parse_phonebook); }
static int at_parse_psn_identification(FILE *fp) { char buf[0x1000]; if (at_cmd(fp, buf, "+GSN") < 1) return -1; printf("\t<imei>%s</imei>\n", buf); return 0; }
static int at_parse_revision_identification(FILE *fp) { char buf[0x1000]; if (at_cmd(fp, buf, "+GMR") < 1) return -1; printf("\t<revision>%s</revision>\n", buf); return 0; }
static int at_parse_model_identification(FILE *fp) { char buf[0x1000]; if (at_cmd(fp, buf, "+GMM") < 1) return -1; printf("\t<model>%s</model>\n", buf); return 0; }
static int at_parse_phonebook(FILE *fp, const char *name) { char buf[0x1000], *ptr; size_t start, end, used, size, i, found; if (at_cmd(fp, NULL, "+CPBS=%s", name) != 0) return -1; if ((manuf == MANUF_NOKIA) || (manuf == MANUF_UNKNOWN)) { if (at_cmd(fp, buf, "+CPBS?") != 1) return -1; if (!(ptr = strchr(buf, ','))) return -1; if (sscanf(++ptr, "%u,%u", &used, &size) != 2) return -1; if (!used) return -1; } if (at_cmd(fp, buf, "+CPBR=?") != 1) return -1; if (sscanf(buf, "+CPBR: (%u-%u)", &start, &end) != 2) return -1; if (manuf == MANUF_ERICSSON) { // FIXME used = size = end; } printf("\t<phonebook name=%s size=\"%u\">\n", name, size); for (i = start, found = 0; i <= end && found < used; i++) if (!at_parse_phonebook_entry(fp, i)) found++; printf("\t</phonebook>\n"); fflush(stdout); return 0; }
static int at_parse_message(FILE *fp, size_t num) { char buf[0x1000], *ptr; if (at_cmd(fp, buf, "+CMGR=%u", num) < 1) return -1; ptr = buf; if (!strncmp(ptr, "+CMGR: ", 7)) ptr += 7; printf("\t\t<message>%s</message>\n", ptr); fflush(stdout); return 0; }
static int at_parse_manufacturer_identification(FILE *fp) { char buf[0x1000]; if (at_cmd(fp, buf, "+GMI") < 1) return -1; if (strstr(buf, "Ericsson")) manuf = MANUF_ERICSSON; else if (strstr(buf, "Nokia")) manuf = MANUF_NOKIA; else manuf = MANUF_UNKNOWN; printf("\t<manufacturer>%s</manufacturer>\n", buf); return 0; }
static int at_parse_phonebook_entry(FILE *fp, size_t num) { char buf[0x1000], *ptr, *start, *end; char *number_ptr, *name_ptr; ssize_t number_len, name_len; if (at_cmd(fp, buf, "+CPBR=%u", num) != 1) return -1; ptr = buf; if (!strncmp(ptr, "+CPBR: ", 7)) ptr += 7; puts("\t\t<contact>"); if (((start = strchr(ptr, '\"'))) && (end = strchr(++start, '\"'))) { number_ptr = start; number_len = end - start; } else { number_ptr = NULL; } if (((start = strchr(++end, '\"'))) && (end = strrchr(&ptr[strlen(ptr) - 1], '\"'))) { name_ptr = ++start; name_len = end - start; } else { name_ptr = NULL; } if ((number_ptr) && (name_ptr)) { printf("\t\t\t<name>%.*s</name>\n", name_len, name_ptr); printf("\t\t\t<number>%.*s</number>\n", number_len, number_ptr); } else { printf("\t\t\t<raw>%s</raw>\n", ptr); } puts("\t\t</contact>"); fflush(stdout); return 0; }
static int at_parse_message_storage(FILE *fp, const char *name) { char buf[0x1000]; size_t i, msgnum, size; if (at_cmd(fp, buf, "+CPMS=%s", name) != 1) return -1; if (sscanf(buf, "+CPMS: %u,%u", &msgnum, &size) != 2) return -1; printf("\t<msgstorage name=%s>\n", name); for (i = 1; i <= msgnum; i++) at_parse_message(fp, i); puts("\t</msgstorage>"); return 0; }
void get_serial_modem(hd_data_t *hd_data) { hd_t *hd; int i, j, fd; unsigned modem_info, baud; char *command; ser_device_t *sm; int chk_usb = hd_probe_feature(hd_data, pr_modem_usb); /* serial modems & usb modems */ for(hd = hd_data->hd; hd; hd = hd->next) { if( ( ( hd->base_class.id == bc_comm && hd->sub_class.id == sc_com_ser && !hd->tag.ser_skip && hd->tag.ser_device != 2 && /* cf. serial.c */ !has_something_attached(hd_data, hd) ) || ( chk_usb && hd->bus.id == bus_usb && hd->base_class.id == bc_modem ) ) && hd->unix_dev_name ) { if(dev_name_duplicate(hd_data, hd->unix_dev_name)) continue; if((fd = open(hd->unix_dev_name, O_RDWR | O_NONBLOCK)) >= 0) { sm = add_ser_modem_entry(&hd_data->ser_modem, new_mem(sizeof *sm)); sm->dev_name = new_str(hd->unix_dev_name); sm->fd = fd; sm->hd_idx = hd->idx; sm->do_io = 1; init_modem(sm); } } } if(!hd_data->ser_modem) return; PROGRESS(2, 0, "init"); usleep(300000); /* PnP protocol; 200ms seems to be too fast */ for(sm = hd_data->ser_modem; sm; sm = sm->next) { modem_info = TIOCM_DTR | TIOCM_RTS; ioctl(sm->fd, TIOCMBIS, &modem_info); ioctl(sm->fd, TIOCMGET, &modem_info); if(!(modem_info & (TIOCM_DSR | TIOCM_CD))) { sm->do_io = 0; } } /* just a quick test if we get a response to an AT command */ for(i = 0; i < 4; i++) { PROGRESS(3, i + 1, "at test"); for(sm = hd_data->ser_modem; sm; sm = sm->next) { if(!sm->is_modem) set_modem_speed(sm, i == 0 ? 115200 : i == 1 ? 38400 : i == 2 ? 9600 : 1200); } at_cmd(hd_data, "AT\r", 1, 1); for(sm = hd_data->ser_modem; sm; sm = sm->next) { if(strstr(sm->buf, "OK") || strstr(sm->buf, "0")) { sm->is_modem = 1; sm->do_io = 0; } sm->buf_len = 0; /* clear buffer */ } } for(sm = hd_data->ser_modem; sm; sm = sm->next) { if((sm->do_io = sm->is_modem)) { sm->max_baud = sm->cur_baud; } } /* check for init string */ PROGRESS(4, 0, "init string"); command = NULL; for(i = 0; (unsigned) i < MAX_INIT_STRING; i++) { str_printf(&command, 0, "AT %s\r", init_strings[i]); at_cmd(hd_data, command, 1, 1); for(sm = hd_data->ser_modem; sm; sm = sm->next) { if(strstr(sm->buf, "OK") || strstr(sm->buf, "0")) { str_printf(&sm->init_string2, -1, "%s %s", sm->init_string2 ? "" : "AT", init_strings[i] ); } } } command = free_mem(command); for(sm = hd_data->ser_modem; sm; sm = sm->next) if(sm->is_modem) str_printf(&sm->init_string1, -1, "ATZ"); { int cmds[] = { 1, 3, 4, 5, 6 }; char at[10]; int i, j, ModemsCount = 0; str_list_t **responces = NULL; for(sm = hd_data->ser_modem; sm; sm = sm->next) if(sm->is_modem) ModemsCount++; responces = new_mem(ModemsCount * sizeof *responces); at_cmd(hd_data, "ATI\r", 0, 1); for(j = 0, sm = hd_data->ser_modem; sm; sm = sm->next) { if(sm->is_modem) responces[j++] = str_list_dup(sm->at_resp); } for(i = 0; (unsigned) i < sizeof cmds / sizeof *cmds; i++) { int atx = cmds[i]; sprintf(at, "ATI%d\r", atx); at_cmd(hd_data, at, 0, 1); for(j = 0, sm = hd_data->ser_modem; sm; sm = sm->next) { if(sm->is_modem) { if(atx == 1 && check_for_responce(responces[j], "Hagenuk", 7) && (check_for_responce(sm->at_resp, "Speed Dragon", 12) || check_for_responce(sm->at_resp, "Power Dragon", 12))) { free_mem(sm->init_string1); free_mem(sm->init_string2); sm->init_string1 = new_str("AT&F"); sm->init_string2 = new_str("ATB8"); } if(atx == 3 && check_for_responce(responces[j], "346900", 6) && check_for_responce(sm->at_resp, "3Com U.S. Robotics ISDN", 23)) { free_mem(sm->init_string1); free_mem(sm->init_string2); sm->init_string1 = new_str("AT&F"); sm->init_string2 = new_str("AT*PPP=1"); } if(atx == 4 && check_for_responce(responces[j], "SP ISDN", 7) && check_for_responce(sm->at_resp, "Sportster ISDN TA", 17)) { free_mem(sm->init_string1); free_mem(sm->init_string2); sm->init_string1 = new_str("AT&F"); sm->init_string2 = new_str("ATB3"); } if(atx == 6 && check_for_responce(responces[j], "644", 3) && check_for_responce(sm->at_resp, "ELSA MicroLink ISDN", 19)) { free_mem(sm->init_string1); free_mem(sm->init_string2); sm->init_string1 = new_str("AT&F"); sm->init_string2 = new_str("AT$IBP=HDLCP"); free_mem(sm->pppd_option); sm->pppd_option = new_str("default-asyncmap"); } if(atx == 6 && check_for_responce(responces[j], "643", 3) && check_for_responce(sm->at_resp, "MicroLink ISDN/TLV.34", 21)) { free_mem(sm->init_string1); free_mem(sm->init_string2); sm->init_string1 = new_str("AT&F"); sm->init_string2 = new_str("AT\\N10%P1"); } if(atx == 5 && check_for_responce(responces[j], "ISDN TA", 6) && check_for_responce(sm->at_resp, "ISDN TA;ASU", 4)) { free_mem(sm->vend); sm->vend = new_str("ASUS"); free_mem(sm->user_name); sm->user_name = new_str("ISDNLink TA"); free_mem(sm->init_string1); free_mem(sm->init_string2); sm->init_string1 = new_str("AT&F"); sm->init_string2 = new_str("ATB40"); } if(atx==3 && check_for_responce(responces[j], "128000", 6) && check_for_responce(sm->at_resp, "Lasat Speed", 11)) { free_mem(sm->init_string1); free_mem(sm->init_string2); sm->init_string1 = new_str("AT&F"); sm->init_string2 = new_str("AT\\P1&B2X3"); } if(atx == 1 && (check_for_responce(responces[j], "28642", 5) || check_for_responce(responces[j], "1281", 4) || check_for_responce(responces[j], "1282", 4) || check_for_responce(responces[j], "1283", 4) || check_for_responce(responces[j], "1291", 4) || check_for_responce(responces[j], "1292", 4) || check_for_responce(responces[j], "1293", 4)) && (check_for_responce(sm->at_resp, "Elite 2864I", 11) || check_for_responce(sm->at_resp, "ZyXEL omni", 10))) { free_mem(sm->init_string1); free_mem(sm->init_string2); sm->init_string1 = new_str("AT&F"); sm->init_string2 = new_str("AT&O2B40"); } j++; } } } for(i = 0; i < ModemsCount; i++) free_str_list(responces[i]); free_mem(responces); } /* now, go for the maximum speed... */ PROGRESS(5, 0, "speed"); for(i = MAX_SPEED - 1; i >= 0; i--) { baud = speeds[i].baud; for(j = 0, sm = hd_data->ser_modem; sm; sm = sm->next) { if(sm->is_modem) { if(baud > sm->max_baud) { sm->do_io = set_modem_speed(sm, baud) ? 0 : 1; if(sm->do_io) j++; } } } /* no modems */ if(!j) continue; at_cmd(hd_data, "AT\r", 1, 0); for(sm = hd_data->ser_modem; sm; sm = sm->next) { if(strstr(sm->buf, "OK") || strstr(sm->buf, "0")) { sm->max_baud = sm->cur_baud; } else { sm->do_io = 0; } sm->buf_len = 0; /* clear buffer */ } } /* now, fix it all up... */ for(sm = hd_data->ser_modem; sm; sm = sm->next) { if(sm->is_modem) { set_modem_speed(sm, sm->max_baud); sm->do_io = 1; } } #if 0 /* just for testing */ if((hd_data->debug & HD_DEB_MODEM)) { int i; int cmds[] = { 0, 1, 2, 3, 6 }; char at[10]; PROGRESS(8, 0, "testing"); at_cmd(hd_data, "ATI\r", 0, 1); for(i = 0; (unsigned) i < sizeof cmds / sizeof *cmds; i++) { sprintf(at, "ATI%d\r", cmds[i]); at_cmd(hd_data, at, 0, 1); } at_cmd(hd_data, "AT\r", 0, 1); } #endif PROGRESS(5, 0, "pnp id"); at_cmd(hd_data, "ATI9\r", 1, 1); for(sm = hd_data->ser_modem; sm; sm = sm->next) { if(sm->is_modem) { chk4id(sm); if(!sm->user_name) guess_modem_name(hd_data, sm); } /* reset serial lines */ tcflush(sm->fd, TCIOFLUSH); tcsetattr(sm->fd, TCSAFLUSH, &sm->tio); close(sm->fd); } }
void guess_modem_name(hd_data_t *hd_data, ser_device_t *modem) { ser_device_t *sm; str_list_t *sl; char *s; #ifdef __PPC__ char *s1, *s2; unsigned u; #endif for(sm = hd_data->ser_modem; sm; sm = sm->next) sm->do_io = 0; (sm = modem)->do_io = 1; #ifdef __PPC__ at_cmd(hd_data, "ATI0\r", 0, 1); sl = sm->at_resp; if(sl && !strcmp(sl->str, "ATI0")) sl = sl->next; /* skip AT cmd echo */ s1 = NULL; if(sl) { if(strstr(sl->str, "PowerBook")) { sm->vend = new_str("Apple"); sm->user_name = new_str(sl->str); return; } s1 = new_str(sl->str); } at_cmd(hd_data, "ATI1\r", 0, 1); sl = sm->at_resp; if(sl && !strcmp(sl->str, "ATI1")) sl = sl->next; /* skip AT cmd echo */ if(sl) { if(strstr(sl->str, "APPLE")) { sm->vend = new_str("Apple"); str_printf(&sm->user_name, 0, "AT Modem"); if(s1) { u = strtoul(s1, &s2, 10); if(u && !*s2 && !(u % 1000)) { str_printf(&sm->user_name, 0, "%uk AT Modem", u / 1000); } } s1 = free_mem(s1); return; } } s1 = free_mem(s1); #endif /* ATI3 command */ at_cmd(hd_data, "ATI3\r", 0, 1); sl = sm->at_resp; if(sl && !strcmp(sl->str, "ATI3")) sl = sl->next; /* skip AT cmd echo */ if(sl) { if(*sl->str == 'U' && strstr(sl->str, "Robotics ")) { /* looks like an U.S. Robotics... */ sm->vend = new_str("U.S. Robotics, Inc."); /* strip revision code */ if((s = strstr(sl->str, " Rev. "))) *s = 0; sm->user_name = canon_str(sl->str, strlen(sl->str)); return; } if(strstr(sl->str, "3Com U.S. Robotics ") == sl->str) { /* looks like an 3Com U.S. Robotics... */ sm->vend = new_str("3Com U.S. Robotics, Inc."); sm->user_name = canon_str(sl->str, strlen(sl->str)); return; } if(strstr(sl->str, "-V34_DS -d Z201 2836")) { /* looks like a Zoom V34X */ sm->vend = new_str("Zoom Telephonics, Inc."); sm->user_name = new_str("Zoom FaxModem V.34X Plus Model 2836"); return; } if(strstr(sl->str, "FM560 VER 3.01 V.90")) { /* looks like a Microcom DeskPorte 56K Voice ... */ sm->vend = new_str("Microcom"); sm->user_name = new_str("TravelCard 56K"); return; } if(strstr(sl->str, "Compaq Microcom 550 56K Modem")) { /* looks like a Microcom DeskPorte Pocket ... */ sm->vend = new_str("Compaq"); sm->user_name = new_str("Microcom 550 56K Modem"); return; } } /* ATI0 command */ at_cmd(hd_data, "ATI0\r", 0, 1); sl = sm->at_resp; if(sl && !strcmp(sl->str, "ATI0")) sl = sl->next; /* skip AT cmd echo */ if(sl) { if(strstr(sl->str, "DP Pocket")) { /* looks like a Microcom DeskPorte Pocket ... */ sm->vend = new_str("Microcom"); sm->user_name = new_str("DeskPorte Pocket"); return; } } /* ATI6 command */ at_cmd(hd_data, "ATI6\r", 0, 1); sl = sm->at_resp; if(sl && !strcmp(sl->str, "ATI6")) sl = sl->next; /* skip AT cmd echo */ if(sl) { if(strstr(sl->str, "RCV56DPF-PLL L8571A")) { /* looks like a Microcom DeskPorte 56K Voice ... */ sm->vend = new_str("Microcom"); sm->user_name = new_str("DeskPorte 56K Voice"); return; } } /* ATI2 command */ at_cmd(hd_data, "ATI2\r", 0, 1); sl = sm->at_resp; if(sl && !strcmp(sl->str, "ATI2")) sl = sl->next; /* skip AT cmd echo */ if(sl) { if(strstr(sl->str, "ZyXEL ")) { /* looks like a ZyXEL... */ sm->vend = new_str("ZyXEL"); at_cmd(hd_data, "ATI1\r", 0, 1); sl = sm->at_resp; if(sl && !strcmp(sl->str, "ATI1")) sl = sl->next; if(sl && sl->next) { sl = sl->next; if((s = strstr(sl->str, " V "))) *s = 0; sm->user_name = canon_str(sl->str, strlen(sl->str)); } return; } } }
static int at_disable_echo(FILE *fp) { at_cmd(fp, NULL, "E0"); }