int handleBatCmd(char* line, int cmdId) { int result = -1; int param = -1; char response[MAX_AT_RESPONSE]; LOGATCI(LOG_DEBUG, "line: %s", line); switch(cmdId) { case 0: result = AT_get_charging_state_flag(); break; case 1: result = AT_get_bat_voltage(); break; case 2: result = AT_set_Charger_Current(CUT_CHARGER_CURRENT); break; default: LOGATCI(LOG_DEBUG, "atcid not support this at command: %s", line); } if(result != -1) { sprintf(response, "%d\r\nOK\r\n\0", result); writeDataToSerial(response, strlen(response)); } else { sprintf(response, "ERROR\r\n\0"); writeDataToSerial(response, strlen(response)); } return result; }
int custom_command_hdlr(char* line){ int i = 0, ret = 0; int table_size = 0; char response[MAX_AT_RESPONSE]; char* line_cut = cut_cmd_line(line); memset(response, 0, sizeof(response)); table_size = (sizeof(custom_cmd_table)/sizeof(customcmd_type)); for(i = 0; i < table_size;i++){ LOGATCI(LOG_DEBUG, "custom_cmd_table[%d].cmdName = %s", i, custom_cmd_table[i].cmdName); if(strcmp(line_cut, custom_cmd_table[i].cmdName) == 0){ ATOP_t at_op = getAtOp(&line); LOGATCI(LOG_DEBUG, "The command op is %d; Support op is %d", at_op, custom_cmd_table[i].opType); if((at_op & custom_cmd_table[i].opType) == 0){ writeDataToserialByResponseType(AT_NOT_IMPL); }else{ ret = custom_cmd_table[i].cmd_handle_func(line, at_op, response); if(strlen(response) > 0){ writeDataToSerial(response, strlen(response)); } if(ret != AT_NONE_OP){ writeDataToserialByResponseType(ret); } } free(line_cut); return 1; //The command is handled here } } free(line_cut); return 0; }
ATRESPONSE_t pas_cclk_handler(char* cmdline, ATOP_t opType, char* response){ time_t timep; struct tm *p; struct tm setclk; char tm_buffer[40]; pid_t child_pid; int status; LOGATCI(LOG_DEBUG, "cmdline %s", cmdline); switch(opType){ case AT_READ_OP: time(&timep); p=localtime(&timep); sprintf(response, "%02d/%02d/%02d,%02d:%02d:%02d\n", (1900+p->tm_year)%100, (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec); return AT_OK; break; case AT_SET_OP: if(strlen(cmdline) != strlen("yy/MM/dd,hh:mm:ss")){ sprintf(response, "CME ERROR: Invalid parameters"); return AT_ERROR; } sscanf(cmdline, "%2d/%2d/%2d,%2d:%2d:%2d", &setclk.tm_year, &setclk.tm_mon, &setclk.tm_mday, &setclk.tm_hour, &setclk.tm_min, &setclk.tm_sec); LOGATCI(LOG_DEBUG, "%02d/%02d/%02d,%02d:%02d:%02d", setclk.tm_year, setclk.tm_mon, setclk.tm_mday, setclk.tm_hour, setclk.tm_min, setclk.tm_sec); setclk.tm_year = setclk.tm_year + 2000; memset(tm_buffer, 0, sizeof(tm_buffer)); sprintf(tm_buffer, "%4d%02d%02d.%02d%02d%02d", setclk.tm_year, setclk.tm_mon, setclk.tm_mday, setclk.tm_hour, setclk.tm_min, setclk.tm_sec); LOGATCI(LOG_DEBUG, "Set Date/Time is [%s]", tm_buffer); child_pid = fork(); if (child_pid < 0) { LOGATCI(LOG_ERR, "Can't fork for execute command"); return AT_ERROR; } if (child_pid != 0){ waitpid(child_pid,&status,0); LOGATCI(LOG_DEBUG, "child status is [%d]", status); }else{ if(execl("/system/bin/date","date", "-s", tm_buffer, NULL) == -1){ exit(1); } } return AT_OK; break; case AT_TEST_OP: strcpy(response, "+CCLK: yy/MM/dd,hh:mm:ss"); return AT_OK; break; default: break; } return AT_ERROR; }
ATRESPONSE_t pas_echo_handler(char* cmdline, ATOP_t opType, char* response){ int len = 0, i = 0, flag = -1; LOGATCI(LOG_DEBUG, "cmdline %s", cmdline); len = strlen(cmdline); for(i = 0; i < len; i ++){ if( cmdline[i] == 'E' || cmdline[i] == 'e'){ if(i < len-1){ flag = cmdline[i+1] - '0'; break; } }else{ i++; } } if(flag == 0 || flag == 1){ setEchoOption(flag); return AT_OK; } return AT_ERROR; }
int handleBspCmd(char* cmdData, int cmdId){ cmd_data_type cmd_data; int fd = -1, result = -1; ATOP_t at_op; char response[MAX_AT_RESPONSE]; LOGATCI(LOG_DEBUG,"Enter with cmdId:%d", cmdId); at_op = getAtOp(&cmdData); LOGATCI(LOG_DEBUG, "The command op is %d; Support op is %d", at_op, bsp_cmd_table[cmdId].opType); memset(response, 0, sizeof(response)); if((at_op & bsp_cmd_table[cmdId].opType) != 0){ //Open the FD to handle LOGATCI(LOG_DEBUG, "Open FD: %s", bsp_cmd_table[cmdId].devPath); fd = open(bsp_cmd_table[cmdId].devPath, O_RDWR); if(fd < 0){ LOGATCI(LOG_ERR, "Fail to open FD with errno:%d", errno); writeDataToserialByResponseType(AT_ERROR); return 0; } //Initalize the cmd data structure memset(cmd_data.cmdDataRequest, 0, sizeof(cmd_data.cmdDataRequest)); memset(cmd_data.cmdDataResponse, 0, sizeof(cmd_data.cmdDataResponse)); strcpy(cmd_data.cmdDataRequest, cmdData); cmd_data.opType = at_op; //Send IOControl to device driver result = ioctl(fd, bsp_cmd_table[cmdId].cmdId, &cmd_data); if(result < 0){ LOGATCI(LOG_ERR, "Fail to IO Control[%d] with errno:%d", bsp_cmd_table[cmdId].cmdId, errno); writeDataToserialByResponseType(AT_ERROR); return 0; } if(strlen(cmd_data.cmdDataResponse) > 0){ sprintf(response, "\r\n%s\r\n", cmd_data.cmdDataResponse); writeDataToSerial(response, strlen(response)); } }else{ writeDataToserialByResponseType(AT_NOT_IMPL); } return 0; }
int ril_command_hdlr(char* line){ int i = 0, ret = 0; int table_size = 0; char response[MAX_AT_RESPONSE]; char* line_cut = cut_cmd_line(line); memset(response, 0, sizeof(response)); table_size = (sizeof(ril_mmi_cmd_table)/sizeof(rilmmicmd_type)); for(i = 0; i< table_size; i++) { LOGATCI(LOG_DEBUG, "ril_mmi_cmd_table[%d].cmdName = %s", i, ril_mmi_cmd_table[i].cmdName); if(strcmp(line_cut, ril_mmi_cmd_table[i].cmdName) == 0){ ATOP_t at_op = getAtOp(&line); LOGATCI(LOG_DEBUG, "The cus mmi command op is 0x%x; Support op is 0x%x", at_op, ril_mmi_cmd_table[i].opType); if((at_op & ril_mmi_cmd_table[i].opType)) { if(ISMMIRSPCMD((at_op << 4) & ril_mmi_cmd_table[i].opType)) { if (atRilMmi_info.cmdNameEIdx <= MAX_QUEUE_MMI_CMD_IDX) { LOGATCI(LOG_DEBUG, "Match ril mmi command.EIdx[%d]",atRilMmi_info.cmdNameEIdx); atRilMmi_info.atOp = at_op << 4; atRilMmi_info.hasRilMMICmd = 1; strcpy(atRilMmi_info.cmdName[atRilMmi_info.cmdNameEIdx], line_cut); if(AT_READ_OP == at_op) strcat(atRilMmi_info.cmdName[atRilMmi_info.cmdNameEIdx],"?"); else if(AT_TEST_OP == at_op) strcat(atRilMmi_info.cmdName[atRilMmi_info.cmdNameEIdx],"=?"); else if(AT_SET_OP == at_op) strcat(atRilMmi_info.cmdName[atRilMmi_info.cmdNameEIdx],"="); strcat(atRilMmi_info.cmdName[atRilMmi_info.cmdNameEIdx],MTKATCIRILPATTERN); atRilMmi_info.cmdNameEIdx++; if(MAX_QUEUE_MMI_CMD_IDX <= atRilMmi_info.cmdNameEIdx) atRilMmi_info.cmdNameEIdx = 0; } } }else{ LOGATCI(LOG_DEBUG, "This is a normal RIL AT command."); } free(line_cut); return 1; //The command is treated as RIL_TYPE } } free(line_cut); return 0; }
ATRESPONSE_t pas_esuo_handler(char* cmdline, ATOP_t opType, char* response){ int err = 0, cmdID = 0; char simIDProperty[PROPERTY_VALUE_MAX]; int simID = 0; LOGATCI(LOG_DEBUG, "pas_esuo_handler enter with opType: %d", opType); switch(opType){ case AT_SET_OP: err = at_tok_nextint(&cmdline, &cmdID); if (err < 0) return -1; if(cmdID == 4){ //Configure the default SIM to SIM1 property_set(ATCI_SIM, "0"); LOGATCI(LOG_DEBUG, "Set default to SIM1"); return AT_OK; }else if(cmdID == 5){ //Configure the default SIM to SIM2 property_set(ATCI_SIM, "1"); LOGATCI(LOG_DEBUG, "Set default to SIM2"); return AT_OK; } break; case AT_TEST_OP: writeDataToSerial("+ESUO: (4-5)", strlen("+ESUO: (4-5)")); return AT_OK; break; case AT_READ_OP: property_get(ATCI_SIM, simIDProperty, "0"); simID = atoi(simIDProperty); if(simID == 1){ strcpy(response, "+ESUO:5\r\n"); }else{ strcpy(response, "+ESUO:4\r\n"); } return AT_OK; break; default: break; } return AT_ERROR; }
/* * Purpose: The main program loop * Input: argc - number of input arguments * argv - array of strings (input arguments) * Return: 0 */ int main(int argc,char *argv[]) { int rc=-1; int i = 0; LOGATCI(LOG_INFO, "atcid-daemon start!!!"); //Initial the parameter for serial dervice initSerialDevice(&serial); strcpy(serial.devicename[0],TTY_GS0); strcpy(serial.devicename[1],TTY_GS1); for(i = 0; i < MAX_DEVICE_NUM; i++) { if ((serial.fd[i] = open_serial_device(&serial, serial.devicename[i])) == INVALIDE_SOCKET_FD) { LOGATCI(LOG_ERR, "Could not open serial device [%d] and start atci service", i); return ATCID_OPEN_SERIAL_DEV_ERR; } } create_thread(); readerLoop((void*) &serial); pthread_join(s_tid_atcid, NULL); return 0; }
int generic_command_hdlr(char* line){ int i = 0; int table_size = 0; char* line_cut = cut_cmd_line(line); table_size = (sizeof(generic_cmd_table)/sizeof(generic_cmd_type)); LOGATCI(LOG_DEBUG, "The size of generic_cmd_table is %d", table_size); for(i = 0; i < table_size;i++){ if(strcmp(line_cut, generic_cmd_table[i].cmdName) == 0){ //Write the AT command to generic service by socket interface free(line_cut); return 1; } } free(line_cut); return 0; }
ATRESPONSE_t pas_reboot_handler(char* cmdline, ATOP_t opType, char* response){ LOGATCI(LOG_DEBUG, "handle cmdline:%s", cmdline); if(opType != AT_ACTION_OP){ return AT_ERROR; } switch(opType){ case AT_ACTION_OP: system("shutdown -r -t 3"); return AT_OK; break; default: break; } return AT_ERROR; }
int process_cmd_line(char* line){ LOGATCI(LOG_DEBUG,"Enter"); //Check the command is belonged to customized command table LOGATCI(LOG_DEBUG, "handle in custom_command_hdlr"); if(ril_command_hdlr(line)){ return RIL_TYPE; } if(custom_command_hdlr(line)){ return ATCI_TYPE; } LOGATCI(LOG_DEBUG, "handle in generic_command_hdlr"); if(generic_command_hdlr(line)){ return GENERIC_TYPE; } LOGATCI(LOG_DEBUG, "handle in bsp_command_hdlr"); if(bsp_command_hdlr(line)){ return PLATFORM_TYPE; } LOGATCI(LOG_DEBUG, "handle in audio_command_hdlr"); if(audio_command_hdlr(line)) { return AUDIO_TYPE; } LOGATCI(LOG_DEBUG, "handle in bat_command_hdlr"); if(bat_command_hdlr(line)) { return BATTERY_TYPE; } return RIL_TYPE; }