//-------------------------------------------------------------------------------------------------- static void CGEVUnsolHandler ( void* reportPtr ) { atmgr_UnsolResponse_t* unsolPtr = reportPtr; uint32_t numParam=0; pa_mdc_SessionStateData_t *sessionStatePtr=NULL; LE_DEBUG("Handler received -%s-",unsolPtr->line); if ( ( FIND_STRING("+CGEV: NW DEACT", unsolPtr->line) ) || ( FIND_STRING("+CGEV: ME DEACT", unsolPtr->line) ) ) { numParam = atcmd_CountLineParameter(unsolPtr->line); if (numParam == 4) { sessionStatePtr = le_mem_ForceAlloc(NewSessionStatePool); sessionStatePtr->profileIndex = atoi(atcmd_GetLineParameter(unsolPtr->line,4)); sessionStatePtr->newState = LE_MDC_DISCONNECTED; SetCurrentDataSessionIndex(INVALID_PROFILE_INDEX); LE_DEBUG("Send Event for %d with state %d", sessionStatePtr->profileIndex,sessionStatePtr->newState); le_event_ReportWithRefCounting(NewSessionStateEvent,sessionStatePtr); } else { LE_WARN("this Response pattern is not expected -%s-",unsolPtr->line); } } }
//-------------------------------------------------------------------------------------------------- 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; }
//-------------------------------------------------------------------------------------------------- static bool CheckStatus ( const char *lineStr, ///< [IN] line to parse le_sim_States_t *statePtr ///< [OUT] SIM state ) { *statePtr = LE_SIM_STATE_UNKNOWN; le_result_t result = true; #define MAXLINE 18 char line[MAXLINE+1]; memcpy(line,lineStr,MAXLINE); line[MAXLINE] = '\0'; atcmd_CountLineParameter(line); if (FIND_STRING("OK",atcmd_GetLineParameter(line,1))) { *statePtr = LE_SIM_READY; } else if (FIND_STRING("+CME ERROR:",atcmd_GetLineParameter(line,1))) { CheckStatus_CmeErrorCode(atcmd_GetLineParameter(line,2),statePtr); } else if (FIND_STRING("+CMS ERROR:",atcmd_GetLineParameter(line,1))) { CheckStatus_CmsErrorCode(atcmd_GetLineParameter(line,2),statePtr); } else if (FIND_STRING("+CPIN:",atcmd_GetLineParameter(line,1))) { CheckStatus_CpinCode(atcmd_GetLineParameter(line,2),statePtr); } else if (FIND_STRING("+WIND:",atcmd_GetLineParameter(line,1))) { CheckStatus_WindCode(atcmd_GetLineParameter(line,2),statePtr); } else { LE_DEBUG("this pattern is not expected -%s-",line); *statePtr = LE_SIM_STATE_UNKNOWN; result = false; } LE_DEBUG("SIM Card Status %d",*statePtr); return result; }
//-------------------------------------------------------------------------------------------------- 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; }
//-------------------------------------------------------------------------------------------------- static void CREGUnsolHandler(void* reportPtr) { atmgr_UnsolResponse_t* unsolPtr = reportPtr; uint32_t numParam=0; le_mrc_NetRegState_t *statePtr; LE_DEBUG("Handler received -%s-",unsolPtr->line); numParam = atcmd_CountLineParameter(unsolPtr->line); if ( ThisMode == PA_MRC_ENABLE_REG_NOTIFICATION ) { if (numParam == 2) { statePtr = le_mem_ForceAlloc(RegStatePoolRef); switch(atoi(atcmd_GetLineParameter(unsolPtr->line,2))) { case 0: *statePtr = LE_MRC_REG_NONE; break; case 1: *statePtr = LE_MRC_REG_HOME; break; case 2: *statePtr = LE_MRC_REG_SEARCHING; break; case 3: *statePtr = LE_MRC_REG_DENIED; break; case 4: *statePtr = LE_MRC_REG_UNKNOWN; break; case 5: *statePtr = LE_MRC_REG_ROAMING; break; default: *statePtr = LE_MRC_REG_UNKNOWN; break; } LE_DEBUG("Send Event with state %d",*statePtr); le_event_ReportWithRefCounting(EventNewRcStatusId,statePtr); } else { LE_WARN("this Response pattern is not expected -%s-",unsolPtr->line); } } else if (ThisMode == PA_MRC_ENABLE_REG_LOC_NOTIFICATION) { if (numParam == 5) { statePtr = le_mem_ForceAlloc(RegStatePoolRef); switch(atoi(atcmd_GetLineParameter(unsolPtr->line,2))) { case 0: *statePtr = LE_MRC_REG_NONE; break; case 1: *statePtr = LE_MRC_REG_HOME; break; case 2: *statePtr = LE_MRC_REG_SEARCHING; break; case 3: *statePtr = LE_MRC_REG_DENIED; break; case 4: *statePtr = LE_MRC_REG_UNKNOWN; break; case 5: *statePtr = LE_MRC_REG_ROAMING; break; default: *statePtr = LE_MRC_REG_UNKNOWN; break; } LE_DEBUG("Send Event with state %d",*statePtr); le_event_ReportWithRefCounting(EventNewRcStatusId,statePtr); } else { LE_WARN("this Response pattern is not expected -%s-",unsolPtr->line); } } }
//-------------------------------------------------------------------------------------------------- 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; }