//-------------------------------------------------------------------------------------------------- LE_SHARED le_result_t le_comm_Send (void* handle, const void* buf, size_t len) { HandleRecord_t* connectionRecordPtr = (HandleRecord_t*) handle; ssize_t bytesSent; // Now send the message (retry if interrupted by a signal). do { bytesSent = send(connectionRecordPtr->fd, buf, len, 0); } while ((bytesSent < 0) && (errno == EINTR)); if (bytesSent < 0) { switch (errno) { case EAGAIN: // Same as EWOULDBLOCK return LE_NO_MEMORY; case ENOTCONN: case ECONNRESET: LE_WARN("sendmsg() failed with errno %d", errno); return LE_COMM_ERROR; default: LE_ERROR("sendmsg() failed with errno %d", errno); return LE_FAULT; } } if (bytesSent < len) { LE_ERROR("The last %zu data bytes (of %zu total) were discarded by sendmsg()!", len - bytesSent, len); return LE_FAULT; } return LE_OK; }
//-------------------------------------------------------------------------------------------------- le_result_t le_avdata_RecordString ( le_avdata_AssetInstanceRef_t instRef, ///< [IN] const char* fieldName, ///< [IN] const char* value, ///< [IN] uint64_t timeStamp ///< [IN] ) { le_result_t result; // Map safeRef to desired data instRef = GetInstRefFromSafeRef(instRef, __func__); int fieldId; if ( assetData_GetFieldIdFromName(instRef, fieldName, &fieldId) != LE_OK ) { LE_KILL_CLIENT("Invalid instance '%p' or unknown field name '%s'", instRef, fieldName); } result = assetData_client_RecordString(instRef, fieldId, value, timeStamp); if (result == LE_NO_MEMORY) { LE_WARN("Time series buffer full for field=%i", fieldId); } else if (result != LE_OK) { LE_ERROR("Error setting field=%i", fieldId); } return result; }
static int mqttClient_sendConnect(mqttClient_t* clientData, MQTTPacket_connectData* connectData) { int rc = LE_OK; LE_ASSERT(clientData); LE_ASSERT(connectData); if (clientData->session.isConnected) { LE_WARN("already connected"); goto cleanup; } int len = MQTTSerialize_connect(clientData->session.tx.buf, sizeof(clientData->session.tx.buf), connectData); if (len <= 0) { LE_ERROR("MQTTSerialize_connect() failed(%d)", len); rc = len; goto cleanup; } LE_DEBUG("<--- CONNECT"); rc = mqttClient_write(clientData, len); if (rc) { LE_ERROR("mqttClient_write() failed(%d)", rc); goto cleanup; } rc = le_timer_Start(clientData->session.cmdTimer); if (rc) { LE_ERROR("le_timer_Start() failed(%d)", rc); goto cleanup; } cleanup: return rc; }
int mqttClient_unsubscribe(mqttClient_t* clientData, const char* topicFilter) { MQTTString topic = MQTTString_initializer; int rc = LE_OK; LE_ASSERT(clientData); if (!clientData->session.isConnected) { LE_WARN("not connected"); goto cleanup; } topic.cstring = (char *)topicFilter; int len = MQTTSerialize_unsubscribe(clientData->session.tx.buf, sizeof(clientData->session.tx.buf), 0, mqttClient_getNextPacketId(clientData), 1, &topic); if (len <= 0) { LE_ERROR("MQTTSerialize_unsubscribe() failed(%d)", len); rc = LE_BAD_PARAMETER; goto cleanup; } rc = mqttClient_write(clientData, len); if (rc) { LE_ERROR("mqttClient_write() failed(%d)", rc); goto cleanup; } rc = le_timer_Start(clientData->session.cmdTimer); if (rc) { LE_ERROR("le_timer_Start() failed(%d)", rc); goto cleanup; } cleanup: return rc; }
//-------------------------------------------------------------------------------------------------- bool le_mrc_IsCellularNetworkForbidden ( le_mrc_ScanInformation_Ref_t scanInformationRef ///< [IN] Scan information reference ) { pa_mrc_ScanInformation_t* scanInformationPtr = le_ref_Lookup(ScanInformationRefMap, scanInformationRef); if (scanInformationPtr == NULL) { LE_KILL_CLIENT("Invalid reference (%p) provided!", scanInformationRef); return false; } bool forbidden; if ( pa_mrc_GetScanInformationForbidden(scanInformationPtr,&forbidden) != LE_OK) { LE_WARN("Could not retrieved Network forbidden status for %p!",scanInformationRef); return false; } return forbidden; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_mrc_GetNetworkRegState ( le_mrc_NetRegState_t* statePtr ///< [OUT] The network registration state. ) { le_result_t result=LE_NOT_POSSIBLE; int32_t val; if (!statePtr) { LE_WARN("One parameter is NULL"); return LE_BAD_PARAMETER; } result = GetNetworkReg(false,&val); if ( result == LE_OK ) { *statePtr = (le_mrc_NetRegState_t)val; } return result; }
//-------------------------------------------------------------------------------------------------- bool le_mrc_IsCellularNetworkAvailable ( le_mrc_ScanInformation_Ref_t scanInformationRef ///< [IN] Scan information reference ) { pa_mrc_ScanInformation_t* scanInformationPtr = le_ref_Lookup(ScanInformationRefMap, scanInformationRef); if (scanInformationPtr == NULL) { LE_KILL_CLIENT("Invalid reference (%p) provided!", scanInformationRef); return false; } bool available; if ( pa_mrc_GetScanInformationAvailable(scanInformationPtr,&available) != LE_OK) { LE_WARN("Could not retrieved Network in use status for %p!", scanInformationRef); return false; } return available; }
int mqttClient_publish(mqttClient_t* clientData, const char* topicName, mqttClient_msg_t* message) { int rc = LE_OK; MQTTString topic = MQTTString_initializer; topic.cstring = (char *)topicName; int len = 0; LE_ASSERT(clientData); if (!clientData->session.isConnected) { LE_WARN("not connected"); goto cleanup; } if (message->qos == MQTT_CLIENT_QOS1 || message->qos == MQTT_CLIENT_QOS2) message->id = mqttClient_getNextPacketId(clientData); len = MQTTSerialize_publish(clientData->session.tx.buf, sizeof(clientData->session.tx.buf), 0, message->qos, message->retained, message->id, topic, (unsigned char*)message->payload, message->payloadLen); if (len <= 0) { LE_ERROR("MQTTSerialize_publish() failed(%d)", len); rc = LE_BAD_PARAMETER; goto cleanup; } rc = mqttClient_write(clientData, len); if (rc) { LE_ERROR("mqttClient_write() failed(%d)", rc); goto cleanup; } cleanup: return rc; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_mrc_GetNetworkRegConfig ( pa_mrc_NetworkRegSetting_t* settingPtr ///< [OUT] The selected Network registration setting. ) { le_result_t result=LE_NOT_POSSIBLE; int32_t val; if (!settingPtr) { LE_WARN("One parameter is NULL"); return LE_BAD_PARAMETER; } result = GetNetworkReg(true,&val); if ( result == LE_OK ) { *settingPtr = (pa_mrc_NetworkRegSetting_t)val; ThisMode = val; } return result; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_mrc_Init ( void ) { if (atports_GetInterface(ATPORT_COMMAND)==NULL) { LE_WARN("radio control Module is not initialize in this session"); return LE_NOT_POSSIBLE; } EventUnsolicitedId = le_event_CreateId("RCEventIdUnsol",sizeof(atmgr_UnsolResponse_t)); EventNewRcStatusId = le_event_CreateIdWithRefCounting("EventNewRcStatus"); le_event_AddHandler("RCUnsolHandler",EventUnsolicitedId ,CREGUnsolHandler); RegStatePoolRef = le_mem_CreatePool("regStatePool",sizeof(le_mrc_NetRegState_t)); RegStatePoolRef = le_mem_ExpandPool(RegStatePoolRef,DEFAULT_REGSTATE_POOL_SIZE); SubscribeUnsolCREG(PA_MRC_ENABLE_REG_LOC_NOTIFICATION); pa_mrc_GetNetworkRegConfig(&ThisMode); return LE_OK; }
// Deleting mutexes of the specified range from the current thread. // The range is specified such that, for a list of n items, Min is 1 and Max is n. // In order to delete from x to (n - y) items, "offsetFromMin" is x - 1, and "offsetFromMax" is y. // The offsets are distances from Min and Max, therefore they must be greater than 0. // If they result in a range such that the lower bound is greater than the upper bound, no mutex is // deleted. static void DelMutexes ( long offsetFromMin, long offsetFromMax ) { if ((offsetFromMin < 0) || (offsetFromMax < 0)) { LE_WARN("DelMutexes bad params - negative offset(s)."); return; } struct timespec sleepTime = {0, DelInv}; MutexRefArray_t* mraRef = (MutexRefArray_t*)pthread_getspecific(TsdMutexRefKey); long idx = offsetFromMin; while (idx < (mraRef->size - offsetFromMax)) { nanosleep(&sleepTime, NULL); le_mutex_Unlock(mraRef->mutexRefArray[idx]); idx++; } }
//-------------------------------------------------------------------------------------------------- rlim_t resLim_GetSandboxedAppTmpfsLimit ( app_Ref_t appRef ///< [IN] The application to set resource limits for. ) { // Get the resource limit from the config tree. Zero means unlimited for tmpfs mounts and is // not allowed. // Determine the file system limit to set. rlim_t fileSysLimit = DEFAULT_LIMIT_FILE_SYSTEM_SIZE; // Create a config iterator to get the file system limit from the config tree. le_cfg_IteratorRef_t appCfg = le_cfg_CreateReadTxn(app_GetConfigPath(appRef)); le_cfg_GoToNode(appCfg, CFG_NODE_LIMIT_FILE_SYSTEM_SIZE); if (le_cfg_NodeExists(appCfg, "") == false) { LE_WARN("No resource limit %s. Assuming the default value %d.", CFG_NODE_LIMIT_FILE_SYSTEM_SIZE, DEFAULT_LIMIT_FILE_SYSTEM_SIZE); } else if ( (GetCfgResourceLimit(appCfg, &fileSysLimit) != LE_OK) || (fileSysLimit == 0) ) { // Use the default limit. LE_ERROR("Configured resource limit %s is invalid. Assuming the default value %d.", CFG_NODE_LIMIT_FILE_SYSTEM_SIZE, DEFAULT_LIMIT_FILE_SYSTEM_SIZE); fileSysLimit = DEFAULT_LIMIT_FILE_SYSTEM_SIZE; } le_cfg_CancelTxn(appCfg); return fileSysLimit; }
//-------------------------------------------------------------------------------------------------- bool le_mrc_IsCellularNetworkRatAvailable ( le_mrc_ScanInformation_Ref_t scanInformationRef, ///< [IN] Scan information reference le_mrc_Rat_t rat ///< [IN] The Radio Access Technology ) { pa_mrc_ScanInformation_t* scanInformationPtr = le_ref_Lookup(ScanInformationRefMap, scanInformationRef); if (scanInformationPtr == NULL) { LE_KILL_CLIENT("Invalid reference (%p) provided!", scanInformationRef); return LE_FAULT; } uint32_t paRat = 0; if ( pa_mrc_GetScanInformationRat(scanInformationPtr,&paRat) != LE_OK ) { LE_WARN("Could not get rat scan information"); return false; } return (rat == paRat); }
//-------------------------------------------------------------------------------------------------- static uint32_t ConvertRatValue ( const char* ratValue ) { if ( strcmp(ratValue, "GSM") == 0 ) { return PA_MRC_METWORK_RATMASK_GSM; } else if ( strcmp(ratValue, "UTMS") == 0 ) { return PA_MRC_METWORK_RATMASK_UTMS; } else if ( strcmp(ratValue, "LTE") == 0 ) { return PA_MRC_METWORK_RATMASK_LTE; } else if ( strcmp(ratValue, "GSM compact") == 0 ) { return PA_MRC_METWORK_RATMASK_GSMCOMPACT; } LE_WARN("This rat value '%s' is not supported",ratValue); return 0; }
//-------------------------------------------------------------------------------------------------- void simTest_SimAccess ( le_sim_Id_t simId ) { //======================================== // 1. Read IMSI using le_sim_SendApdu API //======================================== uint8_t selectDfAdfApdu[] = {0x00, 0xA4, 0x00, 0x0C, 0x02, 0x7F, 0xFF}; uint8_t selectApdu[] = {0x00, 0xA4, 0x00, 0x0C, 0x02, 0x6F, 0x07}; uint8_t readApdu[] = {0x00, 0xB0, 0x00, 0x00, 0x09}; uint8_t rspImsi[SIM_RSP_LEN]; size_t rspImsiLen = SIM_RSP_LEN; // Select ADF Dedicated File (DF_ADF) LE_ASSERT_OK(le_sim_SendApdu(simId, selectDfAdfApdu, sizeof(selectDfAdfApdu), rspImsi, &rspImsiLen)); PrintApdu(rspImsi, rspImsiLen); // Select the EF(IMSI) rspImsiLen = SIM_RSP_LEN; LE_ASSERT_OK(le_sim_SendApdu(simId, selectApdu, sizeof(selectApdu), rspImsi, &rspImsiLen)); PrintApdu(rspImsi, rspImsiLen); // Read the EF(IMSI) rspImsiLen = SIM_RSP_LEN; LE_ASSERT_OK(le_sim_SendApdu(simId, readApdu, sizeof(readApdu), rspImsi, &rspImsiLen)); PrintApdu(rspImsi, rspImsiLen); //===================================================================================== // 2. Read IMSI using le_sim_SendSimCommand API, and check value get by le_sim_SendApdu //====================================================================================== size_t rspImsiLen2 = SIM_RSP_LEN; uint8_t rspImsi2[SIM_RSP_LEN]; uint8_t swi1, swi2; char dfGsmPath[]="3F007FFF"; // Read EF(IMSI) using the le_sim_SendSimCommand API. le_result_t res = le_sim_SendCommand(simId, LE_SIM_READ_BINARY, "6F07", 0, 0, 0, NULL, 0, dfGsmPath, &swi1, &swi2, rspImsi2, &rspImsiLen2); if (LE_UNSUPPORTED == res) { LE_WARN("le_sim_SendCommand() API not supported by the platform"); return; } if (res != LE_OK) { strcpy(dfGsmPath, "3F007F20"); // Check backward compatibility res = le_sim_SendCommand(simId, LE_SIM_READ_BINARY, "6F07", 0, 0, 0, NULL, 0, dfGsmPath, &swi1, &swi2, rspImsi2, &rspImsiLen2); } LE_ASSERT(res == LE_OK); LE_INFO("swi1=0x%02X, swi2=0x%02X", swi1, swi2); PrintApdu(rspImsi2, rspImsiLen2); // Check both IMSI results LE_ASSERT(0 == memcmp(rspImsi, rspImsi2, rspImsiLen2)); size_t rspLen = SIM_RSP_LEN; uint8_t rsp[rspLen]; //================================================================================== // 3. Check read and write record elementary file // Write the 5th entry in EF(ADN): equivalent to AT+CPBW=5,"01290917",129,"Jacky" // Then, read the written data and check //================================================================================== // Write EF(ADN) using the le_sim_SendSimCommand API. uint8_t dataAdn[] = {0x4A, 0x61, 0x63, 0x6B, 0x79, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x05, 0x81, 0x10, 0x92, 0x90, 0x71, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; LE_ASSERT_OK(le_sim_SendCommand(simId, LE_SIM_UPDATE_RECORD, "6F3A", 5, 0, 0, dataAdn, sizeof(dataAdn), "3F007F10", &swi1, &swi2, rsp, &rspLen)); LE_INFO("swi1=0x%02X, swi2=0x%02X", swi1, swi2); // Read EF(ADN) using the le_sim_SendSimCommand API. rspLen = SIM_RSP_LEN; LE_ASSERT_OK(le_sim_SendCommand(simId, LE_SIM_READ_RECORD, "6F3A", 5, 0, 0, NULL, 0, "3F007F10", &swi1, &swi2, rsp, &rspLen)); LE_INFO("swi1=0x%02X, swi2=0x%02X", swi1, swi2); PrintApdu(rsp, rspLen); LE_ASSERT(rspLen == sizeof(dataAdn)); LE_ASSERT(0 == memcmp(rsp, dataAdn, rspLen)); //================================================================================== // 4. Check read and write transparent elementary file // - Read language indication file // - Erase first entry of the file // - Check that it is really erased (by reading again) // - Re-write the initial value // - Check that the initial value is correct (read again) //================================================================================== // Read binary EF(6F05) Language indication size_t rspLenLi = SIM_RSP_LEN; uint8_t rspLi[rspLenLi]; LE_ASSERT_OK(le_sim_SendCommand(simId, LE_SIM_READ_BINARY, "6F05", 0, 0, 0, NULL, 0, dfGsmPath, &swi1, &swi2, rspLi, &rspLenLi)); LE_INFO("swi1=0x%02X, swi2=0x%02X", swi1, swi2); PrintApdu(rspLi, rspLenLi); uint8_t dataLi[] = {0xFF, 0xFF}; // Erase first Language entry rspLen = 0; LE_ASSERT_OK(le_sim_SendCommand(simId, LE_SIM_UPDATE_BINARY, "6F05", 0, 0, 0, dataLi, sizeof(dataLi), dfGsmPath, &swi1, &swi2, rsp, &rspLen)); LE_INFO("swi1=0x%02X, swi2=0x%02X", swi1, swi2); // Read again... rspLen = SIM_RSP_LEN; LE_ASSERT_OK(le_sim_SendCommand(simId, LE_SIM_READ_BINARY, "6F05", 0, 0, 0, NULL, 0, dfGsmPath, &swi1, &swi2, rsp, &rspLen)); LE_INFO("swi1=0x%02X, swi2=0x%02X", swi1, swi2); PrintApdu(rsp, rspLen); // Check it is correctly erased LE_ASSERT(0 == memcmp(rsp, dataLi, sizeof(dataLi))); // Re-write initial values rspLen = 0; LE_ASSERT_OK(le_sim_SendCommand(simId, LE_SIM_UPDATE_BINARY, "6F05", 0, 0, 0, rspLi, rspLenLi, dfGsmPath, &swi1, &swi2, rsp, &rspLen)); LE_INFO("swi1=0x%02X, swi2=0x%02X", swi1, swi2); // And read again... rspLen = SIM_RSP_LEN; LE_ASSERT_OK(le_sim_SendCommand(simId, LE_SIM_READ_BINARY, "6F05", 0, 0, 0, NULL, 0, dfGsmPath, &swi1, &swi2, rsp, &rspLen)); LE_INFO("swi1=0x%02X, swi2=0x%02X", swi1, swi2); PrintApdu(rsp, rspLen); // Check it is correctly erased LE_ASSERT(0 == memcmp(rsp, rspLi, sizeof(rspLenLi))); //===================================================================================== // 5. Read IMSI using a dedicated logical channel // Note that a SIM card supporting logical channels is necessary for this test. //====================================================================================== uint8_t channel = 0; // Open a logical channel LE_ASSERT_OK(le_sim_OpenLogicalChannel(&channel)); LE_ASSERT(channel); // Select ADF Dedicated File (DF_ADF) selectDfAdfApdu[0] = channel; LE_ASSERT_OK(le_sim_SendApduOnChannel(simId, channel, selectDfAdfApdu, sizeof(selectDfAdfApdu), rspImsi, &rspImsiLen)); PrintApdu(rspImsi, rspImsiLen); // Select the EF(IMSI) rspImsiLen = SIM_RSP_LEN; selectApdu[0] = channel; LE_ASSERT_OK(le_sim_SendApduOnChannel(simId, channel, selectApdu, sizeof(selectApdu), rspImsi, &rspImsiLen)); PrintApdu(rspImsi, rspImsiLen); // Read the EF(IMSI) rspImsiLen = SIM_RSP_LEN; readApdu[0] = channel; LE_ASSERT_OK(le_sim_SendApduOnChannel(simId, channel, readApdu, sizeof(readApdu), rspImsi, &rspImsiLen)); PrintApdu(rspImsi, rspImsiLen); // Close the logical channel LE_ASSERT_OK(le_sim_CloseLogicalChannel(channel)); LE_INFO("SIM access test OK"); }
//-------------------------------------------------------------------------------------------------- static void TestRxHandler(le_sms_msg_Ref_t msg, void* contextPtr) { le_sms_msg_Format_t myformat; le_sms_msg_Status_t mystatus; le_result_t res; char tel[LE_SMS_TEL_NMBR_MAX_LEN]; char timestamp[LE_SMS_TIMESTAMP_MAX_LEN]; char text[LE_SMS_TEXT_MAX_LEN]; size_t uintval; LE_INFO("-TEST- New SMS message received ! msg.%p", msg); myformat=le_sms_msg_GetFormat(msg); if (myformat == LE_SMS_FORMAT_TEXT) { receivedTextMsg=msg; res=le_sms_msg_GetSenderTel(msg, tel, 1); if(res != LE_OVERFLOW) { LE_ERROR("-TEST 1/13- Check le_sms_msg_GetSenderTel failure (LE_OVERFLOW expected) !"); } else { LE_INFO("-TEST 1/13- Check le_sms_msg_GetSenderTel passed (LE_OVERFLOW expected)."); } res=le_sms_msg_GetSenderTel(msg, tel, sizeof(tel)); if(res != LE_OK) { LE_ERROR("-TEST 2/13- Check le_sms_msg_GetSenderTel failure (LE_OK expected) !"); } else { LE_INFO("-TEST 2/13- Check le_sms_msg_GetSenderTel passed (%s) (LE_OK expected).", tel); } if(strncmp(&tel[strlen(tel)-4], &DEST_TEST_PATTERN[strlen(DEST_TEST_PATTERN)-4], 4)) { LE_ERROR("-TEST 3/13- Check le_sms_msg_GetSenderTel, bad Sender Telephone number! (%s)", tel); } else { LE_INFO("-TEST 3/13- Check le_sms_msg_GetSenderTel, Sender Telephone number OK."); } uintval=le_sms_msg_GetUserdataLen(msg); if((uintval != strlen(TEXT_TEST_PATTERN)) && (uintval != strlen(SHORT_TEXT_TEST_PATTERN)) && (uintval != strlen(LARGE_TEXT_TEST_PATTERN))) { LE_ERROR("-TEST 4/13- Check le_sms_msg_GetLen, bad expected text length! (%zd)", uintval); } else { LE_INFO("-TEST 4/13- Check le_sms_msg_GetLen OK."); } res=le_sms_msg_GetTimeStamp(msg, timestamp, 1); if(res != LE_OVERFLOW) { LE_ERROR("-TEST 5/13- Check le_sms_msg_GetTimeStamp -LE_OVERFLOW error- failure!"); } else { LE_INFO("-TEST 5/13- Check le_sms_msg_GetTimeStamp -LE_OVERFLOW error- OK."); } res=le_sms_msg_GetTimeStamp(msg, timestamp, sizeof(timestamp)); if(res != LE_OK) { LE_ERROR("-TEST 6/13- Check le_sms_msg_GetTimeStamp failure!"); } else { LE_INFO("-TEST 6/13- Check le_sms_msg_GetTimeStamp OK (%s).", timestamp); } res=le_sms_msg_GetText(msg, text, sizeof(text)); if(res != LE_OK) { LE_ERROR("-TEST 7/13- Check le_sms_msg_GetText failure!"); } else { LE_INFO("-TEST 7/13- Check le_sms_msg_GetText OK."); } if((strncmp(text, TEXT_TEST_PATTERN, strlen(TEXT_TEST_PATTERN)) != 0) && (strncmp(text, SHORT_TEXT_TEST_PATTERN, strlen(SHORT_TEXT_TEST_PATTERN)) != 0) && (strncmp(text, LARGE_TEXT_TEST_PATTERN, strlen(LARGE_TEXT_TEST_PATTERN) != 0)) ) { LE_ERROR("-TEST 8/13- Check le_sms_msg_GetText, bad expected received text! (%s)", text); } else { LE_INFO("-TEST 8/13- Check le_sms_msg_GetText, received text OK."); } // Verify that the message is read-only res=le_sms_msg_SetDestination(msg, DEST_TEST_PATTERN); if(res != LE_NOT_PERMITTED) { LE_ERROR("-TEST 9/13- Check le_sms_msg_SetDestination, parameter check failure!"); } else { LE_INFO("-TEST 9/13- Check le_sms_msg_SetDestination OK."); } res=le_sms_msg_SetText(msg, TEXT_TEST_PATTERN); if(res != LE_NOT_PERMITTED) { LE_ERROR("-TEST 10/13- Check le_sms_msg_SetText, parameter check failure!"); } else { LE_INFO("-TEST 10/13- Check le_sms_msg_SetText OK."); } // Verify Mark Read/Unread functions le_sms_msg_MarkRead(msg); mystatus=le_sms_msg_GetStatus(msg); if(mystatus != LE_SMS_RX_READ) { LE_ERROR("-TEST 11/13- Check le_sms_msg_GetStatus, bad status (%d)!", mystatus); } else { LE_INFO("-TEST 11/13- Check le_sms_msg_GetStatus, status OK."); } le_sms_msg_MarkUnread(msg); mystatus=le_sms_msg_GetStatus(msg); if(mystatus != LE_SMS_RX_UNREAD) { LE_ERROR("-TEST 12/13- Check le_sms_msg_GetStatus, bad status (%d)!", mystatus); } else { LE_INFO("-TEST 12/13- Check le_sms_msg_GetStatus, status OK."); } res=le_sms_msg_DeleteFromStorage(msg); if(res != LE_OK) { LE_ERROR("-TEST 13/13- Check le_sms_msg_DeleteFromStorage failure!"); } else { LE_INFO("-TEST 13/13- Check le_sms_msg_DeleteFromStorage OK."); } } else { LE_WARN("-TEST- I check only Text message!"); } le_sms_msg_Delete(msg); }
//--------------------- ----------------------------------------------------------------------------- static void RxMessageHandler ( le_sms_MsgRef_t msgRef, void* contextPtr ) { le_result_t res; char tel[LE_MDMDEFS_PHONE_NUM_MAX_LEN]; char timestamp[LE_SMS_TIMESTAMP_MAX_LEN]; char text[LE_SMS_TEXT_MAX_LEN]; char text_return[LE_SMS_TEXT_MAX_LEN]; LE_INFO("A New SMS message is received with ref.%p", msgRef); if (le_sms_GetFormat(msgRef) == LE_SMS_FORMAT_TEXT) { res = le_sms_GetSenderTel(msgRef, tel, sizeof(tel)); if(res != LE_OK) { LE_ERROR("le_sms_GetSenderTel has failed (res.%d)!", res); } else { LE_INFO("Message is received from %s.", tel); } res = le_sms_GetTimeStamp(msgRef, timestamp, sizeof(timestamp)); if(res != LE_OK) { LE_ERROR("le_sms_GetTimeStamp has failed (res.%d)!", res); } else { LE_INFO("Message timestamp is %s.", timestamp); } res = le_sms_GetText(msgRef, text, sizeof(text)); if(res != LE_OK) { LE_ERROR("le_sms_GetText has failed (res.%d)!", res); } else { LE_INFO("Message content: \"%s\"", text); } snprintf(text_return, LE_SMS_TEXT_MAX_LEN, MESSAGE_FEEDBACK, tel); // Return a message to sender with phone number include (see smsMO.c file) res = smsmo_SendMessage(tel, text_return); if (res != LE_OK) { LE_ERROR("SmsMoMessage has failed (res.%d)!", res); } else { LE_INFO("the message has been successfully sent."); } res = le_sms_DeleteFromStorage(msgRef); if(res != LE_OK) { LE_ERROR("le_sms_DeleteFromStorage has failed (res.%d)!", res); } else { LE_INFO("the message has been successfully deleted from storage."); } } else { LE_WARN("Warning! I read only Text messages!"); } le_sms_Delete(msgRef); }
//-------------------------------------------------------------------------------------------------- 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; }
//-------------------------------------------------------------------------------------------------- static void ECallStateHandler ( le_ecall_CallRef_t eCallRef, le_ecall_State_t state, void* contextPtr ) { LE_INFO("New eCall state for eCallRef.%p", eCallRef); switch(state) { case LE_ECALL_STATE_STARTED: { LE_INFO("New eCall state is LE_ECALL_STATE_STARTED."); break; } case LE_ECALL_STATE_CONNECTED: { LE_INFO("New eCall state is LE_ECALL_STATE_CONNECTED."); break; } case LE_ECALL_STATE_DISCONNECTED: { LE_INFO("New eCall state is LE_ECALL_STATE_DISCONNECTED."); break; } case LE_ECALL_STATE_WAITING_PSAP_START_IND: { LE_INFO("New eCall state is LE_ECALL_STATE_WAITING_PSAP_START_IND."); break; } case LE_ECALL_STATE_PSAP_START_IND_RECEIVED: { LE_INFO("New eCall state is LE_ECALL_STATE_PSAP_START_IND_RECEIVED."); if (le_ecall_SendMsd(eCallRef) != LE_OK) { LE_ERROR("Could not send the MSD"); } break; } case LE_ECALL_STATE_MSD_TX_STARTED: { LE_INFO("New eCall state is LE_ECALL_STATE_MSD_TX_STARTED."); break; } case LE_ECALL_STATE_LLNACK_RECEIVED: { LE_INFO("New eCall state is LE_ECALL_STATE_LLNACK_RECEIVED."); break; } case LE_ECALL_STATE_LLACK_RECEIVED: { LE_INFO("New eCall state is LE_ECALL_STATE_LLACK_RECEIVED."); break; } case LE_ECALL_STATE_MSD_TX_COMPLETED: { LE_INFO("New eCall state is LE_ECALL_STATE_MSD_TX_COMPLETED."); break; } case LE_ECALL_STATE_MSD_TX_FAILED: { LE_INFO("New eCall state is LE_ECALL_STATE_MSD_TX_FAILED."); break; } case LE_ECALL_STATE_ALACK_RECEIVED_POSITIVE: { LE_INFO("New eCall state is LE_ECALL_STATE_ALACK_RECEIVED_POSITIVE."); break; } case LE_ECALL_STATE_ALACK_RECEIVED_CLEAR_DOWN: { LE_INFO("New eCall state is LE_ECALL_STATE_ALACK_RECEIVED_CLEAR_DOWN."); break; } case LE_ECALL_STATE_STOPPED: { LE_INFO("New eCall state is LE_ECALL_STATE_STOPPED."); break; } case LE_ECALL_STATE_RESET: { LE_INFO("New eCall state is LE_ECALL_STATE_RESET."); break; } case LE_ECALL_STATE_COMPLETED: { LE_INFO("New eCall state is LE_ECALL_STATE_COMPLETED."); le_ecall_End(eCallRef); le_ecall_Delete(eCallRef); break; } case LE_ECALL_STATE_FAILED: { LE_INFO("New eCall state is LE_ECALL_STATE_FAILED."); break; } case LE_ECALL_STATE_END_OF_REDIAL_PERIOD: { LE_INFO("New eCall state is LE_ECALL_STATE_END_OF_REDIAL_PERIOD."); break; } case LE_ECALL_STATE_UNKNOWN: default: { LE_WARN("Unknown eCall state %d!", state); break; } } }
//-------------------------------------------------------------------------------------------------- le_fdMonitor_Ref_t le_fdMonitor_Create ( const char* name, ///< [in] Name of the object (for diagnostics). int fd, ///< [in] File descriptor to be monitored for events. le_fdMonitor_HandlerFunc_t handlerFunc, ///< [in] Handler function. short events ///< [in] Initial set of events to be monitored. ) //-------------------------------------------------------------------------------------------------- { // Get a pointer to the thread-specific event loop data record. event_PerThreadRec_t* perThreadRecPtr = thread_GetEventRecPtr(); // Allocate the object. FdMonitor_t* fdMonitorPtr = le_mem_ForceAlloc(FdMonitorPool); // Initialize the object. fdMonitorPtr->link = LE_DLS_LINK_INIT; fdMonitorPtr->fd = fd; fdMonitorPtr->epollEvents = PollToEPoll(events) | EPOLLWAKEUP; // Non-deferrable by default. fdMonitorPtr->isAlwaysReady = false; fdMonitorPtr->threadRecPtr = perThreadRecPtr; fdMonitorPtr->handlerFunc = handlerFunc; fdMonitorPtr->contextPtr = NULL; // Copy the name into it. if (le_utf8_Copy(fdMonitorPtr->name, name, sizeof(fdMonitorPtr->name), NULL) == LE_OVERFLOW) { LE_WARN("FD Monitor object name '%s' truncated to '%s'.", name, fdMonitorPtr->name); } LOCK // Create a safe reference for the object. fdMonitorPtr->safeRef = le_ref_CreateRef(FdMonitorRefMap, fdMonitorPtr); // Add it to the thread's FD Monitor list. le_dls_Queue(&perThreadRecPtr->fdMonitorList, &fdMonitorPtr->link); // Tell epoll(7) to start monitoring this fd. struct epoll_event ev; memset(&ev, 0, sizeof(ev)); ev.events = fdMonitorPtr->epollEvents; ev.data.ptr = fdMonitorPtr->safeRef; if (epoll_ctl(perThreadRecPtr->epollFd, EPOLL_CTL_ADD, fd, &ev) == -1) { if (errno == EPERM) { LE_DEBUG("fd %d doesn't support epoll(), assuming always readable and writeable.", fd); fdMonitorPtr->isAlwaysReady = true; // If either EPOLLIN or EPOLLOUT are enabled, queue up the handler for this now. uint32_t epollEvents = fdMonitorPtr->epollEvents & (EPOLLIN | EPOLLOUT); if (epollEvents != 0) { fdMon_Report(fdMonitorPtr->safeRef, epollEvents); } } else { LE_FATAL("epoll_ctl(ADD) failed for fd %d. errno = %d (%m)", fd, errno); } } UNLOCK return fdMonitorPtr->safeRef; }
//-------------------------------------------------------------------------------------------------- static void LoadPreferredList ( ) { uint32_t idx = 0; le_dls_List_t preferredNetworkList = LE_DLS_LIST_INIT; // Check that the modemRadioControl has a configuration value for preferred list. le_cfg_IteratorRef_t mrcCfg = le_cfg_CreateReadTxn(CFG_MODEMSERVICE_MRC_PATH"/"CFG_NODE_PREFERREDLIST); if (le_cfg_NodeExists(mrcCfg,"") == false) { LE_DEBUG("'%s' does not exist. Stop reading configuration", CFG_MODEMSERVICE_MRC_PATH"/"CFG_NODE_PREFERREDLIST); le_cfg_CancelTxn(mrcCfg); return; } // Read all network from configDB do { uint32_t ratMask; char mccNodePath[LIMIT_MAX_PATH_BYTES] = {0}; char mncNodePath[LIMIT_MAX_PATH_BYTES] = {0}; char ratNodePath[LIMIT_MAX_PATH_BYTES] = {0}; char mccStr[LIMIT_MAX_PATH_BYTES] = {0}; char mncStr[LIMIT_MAX_PATH_BYTES] = {0}; // Get the node name. char nodeName[LIMIT_MAX_PATH_BYTES] = {0}; sprintf(nodeName,PATTERN_NETWORK"%d",idx); if (le_cfg_IsEmpty(mrcCfg, nodeName)) { LE_DEBUG("'%s' does not exist. stop reading configuration", nodeName); break; } snprintf(mccNodePath, sizeof(mccNodePath), "%s/%s",nodeName,CFG_NODE_MCC); snprintf(mncNodePath, sizeof(mncNodePath), "%s/%s",nodeName,CFG_NODE_MNC); snprintf(ratNodePath, sizeof(ratNodePath), CFG_MODEMSERVICE_MRC_PATH"/"CFG_NODE_PREFERREDLIST"/%s/%s",nodeName,CFG_NODE_RAT); if ( le_cfg_GetString(mrcCfg,mccNodePath,mccStr,sizeof(mccStr),"") != LE_OK ) { LE_WARN("String value for '%s' too large.",mccNodePath); break; } if ( strcmp(mccStr,"") == 0 ) { LE_WARN("No node value set for '%s'",mccNodePath); break; } if ( le_cfg_GetString(mrcCfg,mncNodePath,mncStr,sizeof(mncStr),"") != LE_OK ) { LE_WARN("String value for '%s' too large.",mncNodePath); break; } if ( strcmp(mncStr,"") == 0 ) { LE_WARN("No node value set for '%s'",mncNodePath); break; } if ( LoadRatList(ratNodePath,&ratMask) != LE_OK ) { LE_WARN("Could not read rat information in '%s'",ratNodePath); break; } if ( pa_mrc_AddPreferredNetwork(&preferredNetworkList,mccStr,mncStr,ratMask) != LE_OK ) { LE_WARN("Could not add [%s,%s] into the preferred list",mccStr,mncStr); } ++idx; } while (true); le_cfg_CancelTxn(mrcCfg); if ( pa_mrc_SavePreferredList(&preferredNetworkList) != LE_OK ) { LE_WARN("Could not save the preferred list"); } pa_mrc_ClearPreferedList(&preferredNetworkList); }
//-------------------------------------------------------------------------------------------------- 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 ECallStateHandler ( le_ecall_CallRef_t eCallRef, le_ecall_State_t state, void* contextPtr ) { LE_INFO("New eCall state for eCallRef.%p", eCallRef); switch(state) { case LE_ECALL_STATE_STARTED: { LE_INFO("New eCall state is LE_ECALL_STATE_STARTED."); break; } case LE_ECALL_STATE_CONNECTED: { LE_INFO("New eCall state is LE_ECALL_STATE_CONNECTED."); break; } case LE_ECALL_STATE_DISCONNECTED: { LE_INFO("New eCall state is LE_ECALL_STATE_DISCONNECTED."); LE_INFO("Termination reason: %d", le_ecall_GetTerminationReason(eCallRef) ); break; } case LE_ECALL_STATE_WAITING_PSAP_START_IND: { LE_INFO("New eCall state is LE_ECALL_STATE_WAITING_PSAP_START_IND."); break; } case LE_ECALL_STATE_PSAP_START_IND_RECEIVED: { LE_INFO("New eCall state is LE_ECALL_STATE_PSAP_START_IND_RECEIVED."); if (le_ecall_SendMsd(eCallRef) != LE_OK) { LE_ERROR("Could not send the MSD"); } break; } case LE_ECALL_STATE_MSD_TX_STARTED: { LE_INFO("New eCall state is LE_ECALL_STATE_MSD_TX_STARTED."); break; } case LE_ECALL_STATE_LLNACK_RECEIVED: { LE_INFO("New eCall state is LE_ECALL_STATE_LLNACK_RECEIVED."); break; } case LE_ECALL_STATE_LLACK_RECEIVED: { LE_INFO("New eCall state is LE_ECALL_STATE_LLACK_RECEIVED."); break; } case LE_ECALL_STATE_MSD_TX_COMPLETED: { LE_INFO("New eCall state is LE_ECALL_STATE_MSD_TX_COMPLETED."); break; } case LE_ECALL_STATE_MSD_TX_FAILED: { LE_INFO("New eCall state is LE_ECALL_STATE_MSD_TX_FAILED."); break; } case LE_ECALL_STATE_ALACK_RECEIVED_POSITIVE: { LE_INFO("New eCall state is LE_ECALL_STATE_ALACK_RECEIVED_POSITIVE."); break; } case LE_ECALL_STATE_ALACK_RECEIVED_CLEAR_DOWN: { LE_INFO("New eCall state is LE_ECALL_STATE_ALACK_RECEIVED_CLEAR_DOWN."); break; } case LE_ECALL_STATE_STOPPED: { LE_INFO("New eCall state is LE_ECALL_STATE_STOPPED."); break; } case LE_ECALL_STATE_RESET: { LE_INFO("New eCall state is LE_ECALL_STATE_RESET."); break; } case LE_ECALL_STATE_COMPLETED: { LE_INFO("New eCall state is LE_ECALL_STATE_COMPLETED."); break; } case LE_ECALL_STATE_FAILED: { LE_INFO("New eCall state is LE_ECALL_STATE_FAILED."); break; } case LE_ECALL_STATE_END_OF_REDIAL_PERIOD: { LE_INFO("New eCall state is LE_ECALL_STATE_END_OF_REDIAL_PERIOD."); break; } case LE_ECALL_STATE_TIMEOUT_T2: { LE_INFO("New eCall state is LE_ECALL_STATE_TIMEOUT_T2."); break; } case LE_ECALL_STATE_TIMEOUT_T3: { LE_INFO("New eCall state is LE_ECALL_STATE_TIMEOUT_T3."); break; } case LE_ECALL_STATE_TIMEOUT_T5: { LE_INFO("New eCall state is LE_ECALL_STATE_TIMEOUT_T5."); break; } case LE_ECALL_STATE_TIMEOUT_T6: { LE_INFO("New eCall state is LE_ECALL_STATE_TIMEOUT_T6."); break; } case LE_ECALL_STATE_TIMEOUT_T7: { LE_INFO("New eCall state is LE_ECALL_STATE_TIMEOUT_T7."); break; } case LE_ECALL_STATE_TIMEOUT_T9: { LE_INFO("New eCall state is LE_ECALL_STATE_TIMEOUT_T9."); break; } case LE_ECALL_STATE_TIMEOUT_T10: { LE_INFO("New eCall state is LE_ECALL_STATE_TIMEOUT_T10."); break; } case LE_ECALL_STATE_UNKNOWN: default: { LE_WARN("Unknown eCall state %d!", state); break; } } }
//-------------------------------------------------------------------------------------------------- static void StartSession ( uint32_t paxCount, ///< [IN] number of passengers int32_t hMinAccuracy, ///< [IN] minimum horizontal accuracy to trust the position (in meters) int32_t dirMinAccuracy ///< [IN] minimum direction accuracy to trust the position (in degrees) ) { bool isPosTrusted = false; int32_t latitude = 0x7FFFFFFF; int32_t longitude = 0x7FFFFFFF; int32_t hAccuracy = 0; int32_t direction = 0x7FFFFFFF; int32_t dirAccuracy = 0; LE_DEBUG("StartSession called"); if (ECallRef) { LE_WARN("End and Delete previous eCall session."); le_ecall_End(ECallRef); le_ecall_Delete(ECallRef); ECallRef = NULL; } ECallRef=le_ecall_Create(); LE_FATAL_IF((!ECallRef), "Unable to create an eCall object, exit the app!"); LE_DEBUG("Create eCallRef.%p", ECallRef); // Get the position data if ((le_pos_Get2DLocation(&latitude, &longitude, &hAccuracy) == LE_OK) && (le_pos_GetDirection(&direction, &dirAccuracy) == LE_OK)) { if ((hAccuracy < hMinAccuracy) && (dirAccuracy < dirMinAccuracy)) { isPosTrusted = true; LE_INFO("Position can be trusted."); } else { LE_WARN("Position can't be trusted!"); } } else { LE_WARN("Position can't be trusted!"); } LE_ERROR_IF((le_ecall_SetMsdPosition(ECallRef, isPosTrusted, latitude, longitude, direction) != LE_OK), "Unable to set the position!"); if (paxCount > 0) { LE_ERROR_IF((le_ecall_SetMsdPassengersCount(ECallRef, paxCount) != LE_OK), "Unable to set the number of passengers!"); } LE_ERROR_IF((le_ecall_StartTest(ECallRef) != LE_OK), "Unable to start an eCall, try again!"); LE_INFO("Test eCall has been successfully triggered."); }
//-------------------------------------------------------------------------------------------------- static le_clk_Time_t GetConfigKickTimeoutInterval ( pid_t procId, ///< The process id of the client uid_t appId ///< The user id of the application ) { char appName[LIMIT_MAX_APP_NAME_BYTES] = ""; char procName[LIMIT_MAX_PROCESS_NAME_BYTES] = ""; char configPath[LIMIT_MAX_PATH_BYTES] = ""; const int defaultTimeout = TIMEOUT_DEFAULT; int proc_milliseconds = CFG_TIMEOUT_USE_DEFAULT; int app_milliseconds = CFG_TIMEOUT_USE_DEFAULT; if (LE_OK == user_GetAppName(appId, appName, sizeof(appName) )) { // Check if there is a config for the process name first else check under the app name // It's a real app. Let's look up the config! LE_DEBUG("Getting configured watchdog timeout for app %s", appName); if (le_path_Concat("/", configPath, sizeof(configPath), "apps", appName, "watchdogTimeout", NULL) == LE_OK) { app_milliseconds = le_cfg_QuickGetInt(configPath, CFG_TIMEOUT_USE_DEFAULT); } if (LE_OK == GetProcessNameFromPid( procId, procName, sizeof(procName))) { // get the config configPath[0]='\0'; LE_DEBUG("Getting configured watchdog timeout for process %s", procName); if(le_path_Concat("/", configPath, sizeof(configPath), "apps", appName, "procs", procName, "watchdogTimeout", NULL) == LE_OK) { proc_milliseconds = le_cfg_QuickGetInt(configPath, CFG_TIMEOUT_USE_DEFAULT); } } // find a valid value starting at proc level and working up if (proc_milliseconds == CFG_TIMEOUT_USE_DEFAULT) { if (app_milliseconds == CFG_TIMEOUT_USE_DEFAULT) { proc_milliseconds = defaultTimeout; LE_WARN("No watchdog timeout configured for %s - using default %d ms", appName, proc_milliseconds); } else { proc_milliseconds = app_milliseconds; LE_INFO("No watchdog timeout configured for process %s - using app timeout %d ms", procName, proc_milliseconds); } } else { LE_DEBUG("Watchdog timeout configured for %s - timeout %d ms", procName, proc_milliseconds); } } else { // We have no idea what process is calling us, but we can set a default timeout // and play along. // TODO: Find a way to get the configured watchdog timeout duration for unsandboxed // apps, which run as root. proc_milliseconds = defaultTimeout; LE_WARN("Unknown app with uid %u requested watchdog - using default timeout %d ms", appId, proc_milliseconds); } return MakeTimerInterval(proc_milliseconds); }
//-------------------------------------------------------------------------------------------------- static void LoadScanMode ( ) { char configPath[LIMIT_MAX_PATH_BYTES]; snprintf(configPath, sizeof(configPath), "%s/%s",CFG_MODEMSERVICE_MRC_PATH,CFG_NODE_SCANMODE); LE_DEBUG("Start reading MRC scanMode information in ConfigDB"); le_cfg_IteratorRef_t mrcCfg = le_cfg_CreateReadTxn(configPath); do { if ( le_cfg_GetBool(mrcCfg,CFG_NODE_MANUAL,false) ) { char mccStr[LIMIT_MAX_PATH_BYTES] = {0}; char mncStr[LIMIT_MAX_PATH_BYTES] = {0}; if ( le_cfg_GetString(mrcCfg,CFG_NODE_MCC,mccStr,sizeof(mccStr),"") != LE_OK ) { LE_WARN("String value for '%s' too large.",CFG_NODE_MCC); break; } if ( strcmp(mccStr,"") == 0 ) { LE_WARN("No node value set for '%s'",CFG_NODE_MCC); break; } if ( le_cfg_GetString(mrcCfg,CFG_NODE_MNC,mncStr,sizeof(mncStr),"") != LE_OK ) { LE_WARN("String value for '%s' too large.",CFG_NODE_MNC); break; } if ( strcmp(mncStr,"") == 0 ) { LE_WARN("No node value set for '%s'",CFG_NODE_MNC); break; } if ( le_mrc_ConnectCellularNetwork(mccStr,mncStr) != LE_OK ) { LE_WARN("Could not connect to Network [%s,%s]",mccStr ,mncStr); break; } } else { if ( pa_mrc_SetAutomaticNetworkRegistration() != LE_OK ) { LE_WARN("Could not set the Automatic Network Registration"); break; } } } while (false); le_cfg_CancelTxn(mrcCfg); }
//-------------------------------------------------------------------------------------------------- static le_result_t PlayAmrFile ( le_audio_Stream_t* streamPtr, pa_audio_SamplePcmConfig_t* samplePcmConfigPtr ) { char header[10] = {0}; // Try to detect the 5th first characters if ( read(streamPtr->fd, header, 9) != 9 ) { LE_WARN("AMR detection: cannot read header"); return LE_FAULT; } if ( strncmp(header, "#!AMR", 5) == 0 ) { MediaAmrContext_t * amrCtxtPtr = le_mem_ForceAlloc(AudioAmrContextPool); le_media_Format_t format = LE_MEDIA_FORMAT_MAX; int pipefd[2]; if (amrCtxtPtr == NULL) { LE_ERROR("Failed to allocate memeory"); return LE_FAULT; } memset(amrCtxtPtr, 0, sizeof(MediaAmrContext_t)); if ( strncmp(header+5, "-WB\n", 4) == 0 ) { LE_DEBUG("AMR-WB found"); format = LE_MEDIA_AMR_WB; } else if ( strncmp(header+5, "-NB\n", 4) == 0 ) { LE_DEBUG("AMR-NB found"); format = LE_MEDIA_AMR_NB; } else if ( strncmp(header+5, "\n", 1) == 0 ) { LE_DEBUG("AMR-NB found"); format = LE_MEDIA_AMR_NB; lseek(streamPtr->fd, -3, SEEK_CUR); } else { LE_ERROR("Not an AMR file"); le_mem_Release(amrCtxtPtr); return LE_FAULT; } if ( pa_media_InitAmrDecoder(format, &amrCtxtPtr->paAmrDecoderCtxPtr) != LE_OK ) { LE_ERROR("Failed to init AMR Decoder"); le_mem_Release(amrCtxtPtr); return LE_FAULT; } if (format == LE_MEDIA_AMR_WB) { samplePcmConfigPtr->sampleRate = 16000; } else { samplePcmConfigPtr->sampleRate = 8000; } samplePcmConfigPtr->channelsCount = 1; samplePcmConfigPtr->bitsPerSample = 16; samplePcmConfigPtr->fileSize = (-1); if (pipe(pipefd) == -1) { LE_ERROR("Failed to create the pipe"); le_mem_Release(amrCtxtPtr); return LE_FAULT; } amrCtxtPtr->fd_in = streamPtr->fd; amrCtxtPtr->fd_pipe_input = pipefd[1]; streamPtr->fd = pipefd[0]; amrCtxtPtr->fd_pipe_output = pipefd[0]; amrCtxtPtr->streamPtr = streamPtr; amrCtxtPtr->mediaHandler = le_audio_AddMediaHandler(streamPtr->streamRef, MyMediaAmrHandler, amrCtxtPtr); le_thread_Start(le_thread_Create("PlaySamples", PlayAmrThread, amrCtxtPtr)); } return LE_OK; }
//-------------------------------------------------------------------------------------------------- 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; }
//-------------------------------------------------------------------------------------------------- static void PopulateAppInfoObjects ( void ) //-------------------------------------------------------------------------------------------------- { appCfg_Iter_t appIterRef = appCfg_CreateAppsIter(); char appName[MAX_APP_NAME_BYTES] = ""; char versionBuffer[MAX_VERSION_STR_BYTES] = ""; le_result_t result; int foundAppCount = 0; result = appCfg_GetNextItem(appIterRef); while (result == LE_OK) { result = appCfg_GetAppName(appIterRef, appName, sizeof(appName)); if ((result == LE_OK) && (false == IsHiddenApp(appName))) { LE_DEBUG("Loading object instance for app, '%s'.", appName); assetData_InstanceDataRef_t instanceRef = GetObject9InstanceForApp(appName, false); if (appCfg_GetVersion(appIterRef, versionBuffer, sizeof(versionBuffer)) == LE_OVERFLOW) { LE_WARN("Warning, app, '%s' version string truncated to '%s'.", appName, versionBuffer); } if (0 == strlen(versionBuffer)) { // Use the application hash if the version is empty le_appInfo_GetHash(appName, versionBuffer, sizeof(versionBuffer)); } assetData_client_SetString(instanceRef, O9F_PKG_VERSION, versionBuffer); assetData_client_SetBool(instanceRef, O9F_UPDATE_SUPPORTED_OBJECTS, false); // No need to save the status in config tree, while populating object9 SetObj9State(instanceRef, US_INSTALLED, UR_INSTALLED, false); foundAppCount++; } else { LE_WARN("Application name too large or is hidden, '%s.'", appName); } result = appCfg_GetNextItem(appIterRef); } appCfg_DeleteIter(appIterRef); LE_FATAL_IF(result != LE_NOT_FOUND, "Application cache initialization, unexpected error returned, (%d): \"%s\"", result, LE_RESULT_TXT(result)); int index = 0; LE_DEBUG("Found app count %d.", foundAppCount); while (foundAppCount > 0) { assetData_InstanceDataRef_t instanceRef = NULL; le_result_t result = assetData_GetInstanceRefById(LWM2M_NAME, 9, index, &instanceRef); LE_DEBUG("Index %d.", index); if (result == LE_OK) { assetData_client_GetString(instanceRef, O9F_PKG_NAME, appName, sizeof(appName)); LE_DEBUG("Mapping app '%s'.", appName); SetObject9InstanceForApp(appName, instanceRef); foundAppCount--; } index++; } }
//-------------------------------------------------------------------------------------------------- static void LoadSimFromSecStore ( le_sim_Id_t simId ) { uint32_t attemptCounter = SECSTORE_ATTEMPT_MAX; le_result_t result; le_sim_States_t simState; LE_DEBUG("Start reading SIM-%d information in secure storage",simId); do { simState = le_sim_GetState(simId); switch (simState) { case LE_SIM_INSERTED: { // Set the secure storage path for the SIM char secStorePath[LE_SECSTORE_MAX_NAME_BYTES]; snprintf(secStorePath, sizeof(secStorePath), "%s/%d/%s", SECSTORE_NODE_SIM, simId, SECSTORE_NODE_PIN); char simPin[LE_SIM_PIN_MAX_BYTES] = {0}; size_t simSize = LE_SIM_PIN_MAX_BYTES; // Read PIN code stored in secure storage result = le_secStore_Read(secStorePath, (uint8_t *)simPin, &simSize); if (LE_NOT_FOUND == result) { LE_ERROR("SIM PIN code isn't found in the secure storage"); return; } else if (LE_OVERFLOW == result) { LE_WARN("PIN string too large for SIM-%d", simId); return; } else if (LE_OK != result) { LE_ERROR("Unable to retrieve PIN for SIM-%d, error %s", simId, LE_RESULT_TXT(result)); return; } if (0 == strncmp(simPin, "", sizeof(simPin))) { LE_WARN("PIN not set for SIM-%d", simId); return; } if (LE_OK != (result = le_sim_EnterPIN(simId, simPin))) { LE_ERROR("Error.%d Failed to enter SIM pin for SIM-%d", result, simId); return; } LE_DEBUG("Sim-%d is unlocked", simId); attemptCounter = 1; break; } case LE_SIM_BLOCKED: { LE_EMERG("Be careful the sim-%d is BLOCKED, need to enter PUK code",simId); attemptCounter = 1; break; } case LE_SIM_BUSY: if (attemptCounter==1) { LE_WARN("Could not load the configuration because " "the SIM is still busy after %d attempts", SECSTORE_ATTEMPT_MAX); } else { LE_WARN("Sim-%d was busy when loading configuration," "retry in 1 seconds",simId); } sleep(1); // Retry in 1 second. break; case LE_SIM_READY: LE_DEBUG("Sim-%d is ready",simId); attemptCounter = 1; break; case LE_SIM_ABSENT: LE_WARN("Sim-%d is absent",simId); attemptCounter = 1; break; case LE_SIM_POWER_DOWN: LE_WARN("Sim-%d is powered down",simId); break; case LE_SIM_STATE_UNKNOWN: break; } } while (--attemptCounter); LE_DEBUG("Load SIM information is done"); }