//-------------------------------------------------------------------------------------------------- le_result_t pa_sim_GetIMSI ( pa_sim_Imsi_t imsi ///< [OUT] IMSI value ) { le_result_t result; atcmdsync_ResultRef_t resRef = NULL; // IMSI start with 0|1|2|3|4|5|6|7|8|9 const char* interRespPtr[] = {"0","1","2","3","4","5","6","7","8","9",NULL}; if (!imsi) { LE_DEBUG("One parameter is NULL"); return LE_BAD_PARAMETER; } result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), "at+cimi", &resRef, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(resRef); return result; } le_sim_States_t simState=LE_SIM_STATE_UNKNOWN; char* line = atcmdsync_GetLine(resRef,0); if (CheckStatus(line,&simState)) { ReportStatus(NumCard,simState); } // If there is more than one line then it mean that the command is OK so the first line is // the intermediate one if (atcmdsync_GetNumLines(resRef) == 2) { line = atcmdsync_GetLine(resRef,0); // copy just the first line because of '\0' atcmd_CopyStringWithoutQuote(imsi, line, strlen(line)); result = LE_OK; } // it is not expected else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } le_mem_Release(resRef); // Release atcmdsync_SendCommandDefaultExt return result; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_sim_EnterPUK ( pa_sim_PukType_t type, ///< [IN] puk type const pa_sim_Puk_t puk, ///< [IN] PUK code const pa_sim_Pin_t pin ///< [IN] new PIN code ) { atcmdsync_ResultRef_t resRef = NULL; char atcommand[ATCOMMAND_SIZE] ; atcmdsync_PrepareString(atcommand,ATCOMMAND_SIZE,"at+cpin=%s,%s",puk,pin); le_result_t result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), atcommand, &resRef, NULL, 30000); if ( result != LE_OK ) { le_mem_Release(resRef); return result; } le_sim_States_t simState=LE_SIM_STATE_UNKNOWN; char* line = atcmdsync_GetLine(resRef,0); if (CheckStatus(line,&simState)) { ReportStatus(NumCard,simState); } le_mem_Release(resRef); // release atcmdsync_SendCommandDefault return LE_OK; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_common_GetWindIndicator ( uint32_t* windPtr ) { le_result_t result = LE_OK; atcmdsync_ResultRef_t resRef = NULL; const char* interRespPtr[] = {"+WIND:",NULL}; LE_ASSERT(windPtr); result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), "AT+WIND?", &resRef, interRespPtr, 30000); if ( result == LE_OK ) { char* line = atcmdsync_GetLine(resRef,0); if ( sscanf(line,"+WIND: %d",windPtr) != 1) { LE_DEBUG("cannot qet wind indicator"); result = LE_FAULT; } } le_mem_Release(resRef); return result; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_mrc_GetRadioPower ( le_onoff_t* powerPtr ///< [OUT] The power state. ) { int32_t result=LE_NOT_POSSIBLE; atcmdsync_ResultRef_t resRef = NULL; const char* interRespPtr[] = {"+CFUN:",NULL}; result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), "at+cfun?", &resRef, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(resRef); // release atcmdsync_SendCommandDefaultExt return result; } // If there is more than one line then it mean that the command is OK so the first line is // the intermediate one if (atcmdsync_GetNumLines(resRef) == 2) { // it parse just the first line because of '\0' char* line = atcmdsync_GetLine(resRef,0); // it parse just the first line because of '\0' uint32_t numParam = atcmd_CountLineParameter(line); // Check is the +CREG intermediate response is in good format if (FIND_STRING("+CFUN:",atcmd_GetLineParameter(line,1))) { if (numParam==2) { if(atoi(atcmd_GetLineParameter(line,2)) != 0) { *powerPtr = LE_ON; } else { *powerPtr = LE_OFF; } result = LE_OK; } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } le_mem_Release(resRef); // Release atcmdsync_SendCommand return result; }
//-------------------------------------------------------------------------------------------------- static le_result_t pa_sim_GetRemainingAttempts ( uint32_t idx, ///< [IN] idx to read uint32_t* attemptsPtr ///< [OUT] The number of attempts still possible ) { le_result_t result=LE_NOT_POSSIBLE; atcmdsync_ResultRef_t resRef = NULL; const char* interRespPtr[] = {"+CPINC:",NULL}; if (!attemptsPtr) { LE_DEBUG("One parameter is NULL"); return LE_BAD_PARAMETER; } result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), "at+cpinc", &resRef, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(resRef); // release atcmdsync_SendCommandDefaultExt return result; } // If there is more than one line then it mean that the command is OK so the first line is // the intermediate one if (atcmdsync_GetNumLines(resRef) == 2) { // it parse just the first line because of '\0' char* line = atcmdsync_GetLine(resRef,0); uint32_t numParam = atcmd_CountLineParameter(line); // it parse just the first line because of '\0' if ((numParam==5) && (FIND_STRING("+CPINC:",atcmd_GetLineParameter(line,1)))) { *attemptsPtr = atoi(atcmd_GetLineParameter(line,idx)); result = LE_OK; } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } le_mem_Release(resRef); // Release atcmdsync_SendCommandDefaultExt return result; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_sim_GetSelectedCard ( uint32_t* cardNumPtr ///< [OUT] The card number selected. ) { le_result_t result=LE_OK; atcmdsync_ResultRef_t resRef = NULL; const char* interRespPtr[] = {"+WHCNF: 4",NULL}; result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), "at+whcnf?", &resRef, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(resRef); // release pa_at_SendSyncDefaultExt return result; } // If there is more than one line then it mean that the command is OK so the first line is // the intermediate one if (atcmdsync_GetNumLines(resRef) == 2) { char* line = atcmdsync_GetLine(resRef,0); if (FIND_STRING("+WHCNF: 4,1",line)) { *cardNumPtr = 1; } else if (FIND_STRING("+WHCNF: 4,2",line)) { *cardNumPtr = 2; } else { LE_WARN("this pattern is not expected"); result = LE_NOT_POSSIBLE; } } le_mem_Release(resRef); // Release pa_at_SendSyncDefaultExt return result; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_sim_ChangePIN ( pa_sim_PinType_t type, ///< [IN] The code type const pa_sim_Pin_t oldcode, ///< [IN] Old code const pa_sim_Pin_t newcode ///< [IN] New code ) { atcmdsync_ResultRef_t resRef = NULL; char atcommand[ATCOMMAND_SIZE] ; if (type==PA_SIM_PIN) { atcmdsync_PrepareString(atcommand,ATCOMMAND_SIZE,"at+cpwd=\"SC\",%s,%s",oldcode,newcode); } else if (type==PA_SIM_PIN2) { atcmdsync_PrepareString(atcommand,ATCOMMAND_SIZE,"at+cpwd=\"P2\",%s,%s",oldcode,newcode); } else { return LE_BAD_PARAMETER; } le_result_t result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), atcommand, &resRef, NULL, 30000); if ( result != LE_OK ) { le_mem_Release(resRef); return result; } le_sim_States_t simState=LE_SIM_STATE_UNKNOWN; char* line = atcmdsync_GetLine(resRef,0); if (CheckStatus(line,&simState)) { ReportStatus(NumCard,simState); } le_mem_Release(resRef); // Release atcmdsync_SendCommandDefault return LE_OK; }
//-------------------------------------------------------------------------------------------------- uint32_t pa_sim_CountSlots ( void ) { atcmdsync_ResultRef_t resRef = NULL; const char* interRespPtr[] = {"+WHCNF: 4",NULL}; uint32_t numberOfSim=1; le_result_t result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), "at+whcnf=?", &resRef, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(resRef); // release pa_at_SendSyncDefaultExt return result; } // If there is more than one line then it mean that the command is OK so the first line is if (atcmdsync_GetNumLines(resRef) == 2) { char* line = atcmdsync_GetLine(resRef,0); if (FIND_STRING("+WHCNF: 4,(0-3)",line)) { numberOfSim = 2; } else { LE_WARN("this pattern is not expected"); numberOfSim = 1; } } else { numberOfSim = 1; } le_mem_Release(resRef); // Release pa_at_SendSyncDefaultExt return numberOfSim; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_mdc_GetGatewayAddress ( uint32_t profileIndex, ///< [IN] The profile to use le_mdmDefs_IpVersion_t ipVersion, ///< [IN] IP Version char* gatewayAddrStr, ///< [OUT] The gateway IP address in dotted format size_t gatewayAddrStrSize ///< [IN] The size in bytes of the address buffer ) { le_result_t result = LE_FAULT; char atcommand[ATCOMMAND_SIZE] ; char atintermediate[ATCOMMAND_SIZE]; atcmdsync_PrepareString(atintermediate,ATCOMMAND_SIZE,"+CGPADDR: %d,",profileIndex); const char* interRespPtr[] = {atintermediate,NULL}; atcmdsync_ResultRef_t atRespPtr = NULL; atcmdsync_PrepareString(atcommand,ATCOMMAND_SIZE,"at+cgpaddr=%d",profileIndex); result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), atcommand, &atRespPtr, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(atRespPtr); return result; } // If there is more than one line then it mean that the command is OK so the first line is // the intermediate one if (atcmdsync_GetNumLines(atRespPtr) == 2) { // it parse just the first line because of '\0' char* line = atcmdsync_GetLine(atRespPtr,0); uint32_t numParam = atcmd_CountLineParameter(line); // it parse just the first line because of '\0' if (FIND_STRING("+CGPADDR:",atcmd_GetLineParameter(line,1))) { if (numParam==3) { if(atoi(atcmd_GetLineParameter(line,2)) == profileIndex) { const char* pAddr = atcmd_GetLineParameter(line,3); size_t length = strlen(pAddr); if (length-2 < gatewayAddrStrSize) { atcmd_CopyStringWithoutQuote(gatewayAddrStr,pAddr,gatewayAddrStrSize); result = LE_OK; } else { result = LE_OVERFLOW; } } else { LE_WARN("This is not the good profile %d", atoi(atcmd_GetLineParameter(line,2))); result = LE_FAULT; } } else { LE_WARN("this pattern is not expected"); result = LE_FAULT; } } else { LE_WARN("this pattern is not expected"); result = LE_FAULT; } } le_mem_Release(atRespPtr); // Release atcmdsync_SendCommandDefaultExt return result; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_mdc_ReadProfile ( uint32_t profileIndex, ///< [IN] The profile to read pa_mdc_ProfileData_t* profileDataPtr ///< [OUT] The profile data ) { le_result_t result = LE_FAULT; char atintermediate[ATCOMMAND_SIZE]; atcmdsync_PrepareString(atintermediate,ATCOMMAND_SIZE,"+CGDCONT: %d,",profileIndex); const char* interRespPtr[] = {atintermediate,NULL}; atcmdsync_ResultRef_t atRespPtr = NULL; result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), "at+cgdcont?", &atRespPtr, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(atRespPtr); // Release atcmdsync_SendCommandDefaultExt return result; } // If there is more than one line then it mean that the command is OK so the first line is // the intermediate one if (atcmdsync_GetNumLines(atRespPtr) == 2) { // it parse just the first line because of '\0' char* line = atcmdsync_GetLine(atRespPtr,0); uint32_t numParam = atcmd_CountLineParameter(line); // it parse just the first line because of '\0' if ( FIND_STRING("+CGDCONT:",atcmd_GetLineParameter(line,1))) { if (numParam==7) { if(atoi(atcmd_GetLineParameter(line,2)) == profileIndex) { strncpy(profileDataPtr->apn, atcmd_GetLineParameter(line,4), PA_MDC_APN_MAX_BYTES); result = LE_OK; } else { LE_WARN("This is not the good profile %d", atoi(atcmd_GetLineParameter(line,2))); result = LE_FAULT; } } else { LE_WARN("this pattern is not expected"); result=LE_FAULT; } } else { LE_WARN("this pattern is not expected"); result=LE_FAULT; } } le_mem_Release(atRespPtr); // Release atcmdsync_SendCommandDefaultExt return result; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_sim_GetCardIdentification ( pa_sim_CardId_t iccid ///< [OUT] CCID value ) { le_result_t result=LE_OK; atcmdsync_ResultRef_t resRef = NULL; const char* interRespPtr[] = {"+CCID:",NULL}; if (!iccid) { LE_DEBUG("One parameter is NULL"); return LE_BAD_PARAMETER; } result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), "at+ccid", &resRef, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(resRef); return result; } le_sim_States_t simState=LE_SIM_STATE_UNKNOWN; char* line = atcmdsync_GetLine(resRef,0); if (CheckStatus(line,&simState)) { ReportStatus(NumCard,simState); } // check error if (atcmdsync_GetNumLines(resRef) == 2) { line = atcmdsync_GetLine(resRef,0); uint32_t numParam = atcmd_CountLineParameter(line); // it parse just the first line because of '\0' if (FIND_STRING("+CCID:",atcmd_GetLineParameter(line,1))) { if (numParam==2) { atcmd_CopyStringWithoutQuote(iccid, atcmd_GetLineParameter(line,2), strlen(atcmd_GetLineParameter(line,2))); result = LE_OK; } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } le_mem_Release(resRef); // Release atcmdsync_SendCommandDefaultExt return result; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_mrc_GetSignalStrength ( int32_t* rssiPtr ///< [OUT] The received signal strength (in dBm). ) { int32_t result=LE_NOT_POSSIBLE; atcmdsync_ResultRef_t resRef = NULL; const char* interRespPtr[] = {"+CSQ:",NULL}; if (!rssiPtr) { LE_WARN("One parameter is NULL"); return LE_BAD_PARAMETER; } result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), "at+csq", &resRef, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(resRef); // Release atcmdsync_SendCommandDefaultExt return result; } // If there is more than one line then it mean that the command is OK so the first line is if (atcmdsync_GetNumLines(resRef) == 2) { // it parse just the first line because of '\0' char* line = atcmdsync_GetLine(resRef,0); uint32_t numParam = atcmd_CountLineParameter(line); // it parse just the first line because of '\0' if (FIND_STRING("+CSQ:",atcmd_GetLineParameter(line,1))) { if (numParam==3) { uint32_t val2 = atoi(atcmd_GetLineParameter(line,2)); if (val2==99) { LE_WARN("Quality signal not detectable"); result = LE_OUT_OF_RANGE; } else { *rssiPtr = (-113+(2*val2)); result = LE_OK; } } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } le_mem_Release(resRef); // Release atcmdsync_SendCommand return result; }
//-------------------------------------------------------------------------------------------------- static le_result_t GetNetworkReg ( bool first, ///< true -> mode, false -> state int32_t* valuePtr ///< value that will be return ) { int32_t result=LE_NOT_POSSIBLE; atcmdsync_ResultRef_t resRef = NULL; const char* interRespPtr[] = {"+CREG:",NULL}; result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND), "at+creg?", &resRef, interRespPtr, 30000); if ( result != LE_OK ) { le_mem_Release(resRef); // release atcmdsync_SendCommandDefaultExt return result; } // If there is more than one line then it mean that the command is OK so the first line is // the intermediate one if (atcmdsync_GetNumLines(resRef) == 2) { // it parse just the first line because of '\0' char* line = atcmdsync_GetLine(resRef,0); uint32_t numParam = atcmd_CountLineParameter(line); // it parse just the first line because of '\0' if (FIND_STRING("+CREG:",atcmd_GetLineParameter(line,1))) { if ((numParam>2) && (numParam<7)) { int32_t val; if (first) { val=(int32_t)atoi(atcmd_GetLineParameter(line,2)); } else { val=(int32_t)atoi(atcmd_GetLineParameter(line,3)); } switch(val) { case 0: *valuePtr = LE_MRC_REG_NONE; break; case 1: *valuePtr = LE_MRC_REG_HOME; break; case 2: *valuePtr = LE_MRC_REG_SEARCHING; break; case 3: *valuePtr = LE_MRC_REG_DENIED; break; case 4: *valuePtr = LE_MRC_REG_UNKNOWN; break; case 5: *valuePtr = LE_MRC_REG_ROAMING; break; default: *valuePtr = LE_MRC_REG_UNKNOWN; break; } result = LE_OK; } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } else { LE_WARN("this pattern is not expected"); result=LE_NOT_POSSIBLE; } } le_mem_Release(resRef); // Release atcmdsync_SendCommand return result; }