You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
379 lines
15 KiB
379 lines
15 KiB
#include "kernelModuleModemManager.h"
|
|
#include "../../components/base/basicFunctionality.h"
|
|
|
|
#define LOG( X ) kernelModule::m_pLog->Log( "MOD_MODEM", this, X )
|
|
#ifdef DEBUG
|
|
#define LOG_ERROR( X ) {\
|
|
char _tBfrErrMSG2w34[256];\
|
|
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
|
|
kernelModule::m_pLog->Log( "MOD_MODEM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
|
|
}
|
|
#else
|
|
#define LOG_ERROR( X ) kernelModule::m_pLog->Log( "MOD_MODEM", this, _LOG_ERROR, X );
|
|
#endif
|
|
|
|
|
|
kernelModuleModemManager::kernelModuleModemManager( uint32_t moduleID ): kernelModule( moduleID, KERNEL_MODULE_MODEM_MANAGER ), basicThread(){
|
|
LOG("Creating!");
|
|
if( checkCmdExists("mmcli") > 0 ){
|
|
//Modem Manager Exists
|
|
LOG("Manager OK!");
|
|
//m_pDBC->clenupModemInfos();
|
|
DBC_INT_LIST * tList = enumerateModems();
|
|
if ( tList != NULL ) {
|
|
if( tList->size() ) {
|
|
for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) {
|
|
DBC_MODEM_DATA * tRecord = getModemInfo( *idx );
|
|
if ( tRecord ) {
|
|
//m_pDBC->updateModemInfo( tRecord );
|
|
free( tRecord );
|
|
};
|
|
};
|
|
} else {
|
|
LOG("No Modems Presented in the System!");
|
|
};
|
|
delete(tList);
|
|
};
|
|
};
|
|
};
|
|
|
|
kernelModuleModemManager::~kernelModuleModemManager(){
|
|
//if ( m_pvModems!= NULL ) delete( m_pvModems );
|
|
};
|
|
|
|
bool kernelModuleModemManager::reloadSettings(){
|
|
return true;
|
|
};
|
|
|
|
bool kernelModuleModemManager::startService(){
|
|
return true;
|
|
};
|
|
|
|
bool kernelModuleModemManager::stopService( bool force ){
|
|
return true;
|
|
};
|
|
|
|
void kernelModuleModemManager::m_fThreadProc( void ){
|
|
|
|
};
|
|
|
|
void kernelModuleModemManager::dispatchEvent(EVENT_CONTAINER *Evt){
|
|
};
|
|
|
|
bool kernelModuleModemManager::validate(){
|
|
//DBC_MODEM_DATA *tDATA = getModemInfo( 0 );
|
|
//if ( tDATA ) {
|
|
// free( tDATA );
|
|
//};
|
|
return true;
|
|
};
|
|
|
|
typedef enum E_CFG_TAG_ID{
|
|
CFG_GENERAL = 0,
|
|
CFG_HARDWARE = 1,
|
|
CFG_SYSTEM,
|
|
CFG_STATUS,
|
|
CFG_MODES,
|
|
CFG_BANDS,
|
|
CFG_IP,
|
|
CFG_EPS,
|
|
CFG_3GPP,
|
|
CFG_SIM,
|
|
CFG_BEARER,
|
|
CFG_COUNT
|
|
}CFG_TAG_ID;
|
|
|
|
const CSTR cfg_tags[]={
|
|
"General",
|
|
"Hardware",
|
|
"System",
|
|
"Status",
|
|
"Modes",
|
|
"Bands",
|
|
"IP",
|
|
"3GPP EPS",
|
|
"3GPP",
|
|
"SIM",
|
|
"Bearer"
|
|
};
|
|
|
|
DBC_MODEM_DATA *kernelModuleModemManager::getModemInfo( uint32_t modem_id ){
|
|
char tB[1024];
|
|
char expBuf[1024];
|
|
FILE * fd = NULL;
|
|
CFG_TAG_ID cMode = CFG_GENERAL;
|
|
DBC_MODEM_DATA * retVal = (DBC_MODEM_DATA *)malloc(sizeof(DBC_MODEM_DATA));
|
|
|
|
if ( retVal != NULL ) {
|
|
memset( retVal, 0 , sizeof(DBC_MODEM_DATA)); // --output-json
|
|
sprintf( tB, "mmcli --modem=%d", modem_id );
|
|
fd = popen( tB, "r");
|
|
bool tPortsParsing = false;
|
|
if (fd!= NULL ) {
|
|
retVal->modem_id = modem_id;
|
|
while ( !feof( fd )) {
|
|
fgets( (CSTR)tB, 1024, fd );
|
|
trim( tB );
|
|
if( strstr(tB, "error:" ) != NULL){
|
|
free( retVal );
|
|
retVal = NULL;
|
|
break;
|
|
};
|
|
LOG(tB);
|
|
strncpy( expBuf, tB, 1024 );
|
|
CArray *CA = explode( ':', expBuf );
|
|
if( CA ){
|
|
if( CA->size() ){
|
|
for( int ii = CFG_GENERAL; ii < CFG_COUNT; ii++ ){
|
|
if( strstr( CA->at(0), cfg_tags[ii] ) != NULL ){
|
|
cMode = (CFG_TAG_ID) ii;
|
|
break;
|
|
};
|
|
};
|
|
switch( cMode ){
|
|
case CFG_GENERAL:{
|
|
//LOG("GEN");
|
|
if ( strstr( CA->at(0), "device id") != NULL ) {
|
|
trim(CA->at(1));
|
|
strncpy( retVal->dbus_dev_id, CA->at(1), 64 );
|
|
retVal->dbus_dev_id[64] = (char)0;
|
|
break;
|
|
};
|
|
break;
|
|
};
|
|
case CFG_HARDWARE:{
|
|
//LOG("HW");
|
|
if ( strstr( tB, "manufacturer") != NULL ) {
|
|
trim(CA->at(1));
|
|
strncpy( retVal->hw_manufac, CA->at(1), 64);
|
|
retVal->hw_manufac[64] = (char)0;
|
|
break;
|
|
};
|
|
if ( strstr( tB, "model") != NULL ) {
|
|
trim(CA->at(1));
|
|
strncpy(retVal->hw_model, CA->at(1), 64);
|
|
retVal->hw_model[64] = (char)0;
|
|
break;
|
|
};
|
|
if ( strstr( tB, "h/w revision") != NULL ) {
|
|
trim(CA->at(1));
|
|
strncpy(retVal->hw_revision, CA->at(1), 64);
|
|
retVal->hw_revision[64] = (char)0;
|
|
break;
|
|
};
|
|
if ( strstr( tB, "revision") != NULL ) {
|
|
trim(CA->at(1));
|
|
strncpy(retVal->hw_version, CA->at(1), 32);
|
|
retVal->hw_revision[32] = (char)0;
|
|
break;
|
|
};
|
|
if ( strstr( tB, "equipment id") != NULL ) {
|
|
trim(CA->at(1));
|
|
strncpy(retVal->hw_id, CA->at(1), 32);
|
|
retVal->hw_id[32] = (char)0;
|
|
break;
|
|
};
|
|
break;
|
|
};
|
|
case CFG_SYSTEM:{
|
|
//LOG("SYS");
|
|
if ( strstr( tB, "ports") != NULL ) {
|
|
tPortsParsing = true;
|
|
};
|
|
if( tPortsParsing ){
|
|
trim( CA->at(1) );
|
|
LOG("Ports:");
|
|
LOG( CA->at(1) );
|
|
CArray *CZ = explode( ':', CA->at(1) );
|
|
if ( CZ ) {
|
|
int CP = 0;
|
|
for (int z=0; z< CZ->size(); z++) {
|
|
if ( strstr(CZ->at(z),"(at)")!= NULL ) {
|
|
if( CP == 0 ){
|
|
retVal->at_uart_id = 0;//m_pDBC->getUartIdByDevice();
|
|
} else {
|
|
retVal->at_uart_id_aux = 0;
|
|
};
|
|
CP++;
|
|
};
|
|
if (CP == 2) break;
|
|
};
|
|
delete( CZ );
|
|
};
|
|
break;
|
|
};
|
|
break;
|
|
};
|
|
case CFG_STATUS:{
|
|
//LOG("STAT");
|
|
if ( strstr( tB, "power state") != NULL ) {
|
|
if ( strstr(CA->at(1),"on") ) {
|
|
retVal->power[0] = 'E';
|
|
retVal->power[1]=(char)0;
|
|
} else {
|
|
retVal->power[0] = 'D';
|
|
retVal->power[1]=(char)0;
|
|
};
|
|
break;
|
|
};
|
|
if ( strstr( tB, "state") != NULL ) {
|
|
if ( strstr(CA->at(1),"disabled") ) {
|
|
retVal->status[0]='D';
|
|
retVal->status[1]=(char)0;
|
|
break;
|
|
};
|
|
if ( strstr(CA->at(1),"registered") ) {
|
|
retVal->status[0]='R';
|
|
retVal->status[1]=(char)0;
|
|
break;
|
|
};
|
|
break;
|
|
};
|
|
if ( strstr( tB, "access tech") != NULL ) {
|
|
trim(CA->at(1));
|
|
strncpy(retVal->conmection_tech, CA->at(1), 5);
|
|
retVal->conmection_tech[5] = (char)0;
|
|
break;
|
|
};
|
|
if ( strstr( tB, "signal quality") != NULL ) {
|
|
trim(CA->at(1));
|
|
retVal->signal = atoi(CA->at(1));
|
|
break;
|
|
};
|
|
break;
|
|
};
|
|
case CFG_MODES:{
|
|
//LOG("MOD");
|
|
//if ( strstr( CA->at(0), "current") != NULL ) {
|
|
// trim(CA->at(1));
|
|
// strncpy( retVal->hw_manufac, CA->at(1), 64);
|
|
// retVal->hw_manufac[64] = (char)0;
|
|
// break;
|
|
//};
|
|
break;
|
|
};
|
|
case CFG_IP:{
|
|
//LOG("IP");
|
|
break;
|
|
};
|
|
case CFG_EPS:{
|
|
//LOG("EPS");
|
|
break;
|
|
};
|
|
case CFG_3GPP:{
|
|
// LOG("3GPP");
|
|
if ( strstr( tB, "imei") != NULL ) {
|
|
trim(CA->at(1));
|
|
strncpy( retVal->imei, CA->at(1), 16);
|
|
retVal->imei[16] = (char)0;
|
|
break;
|
|
};
|
|
if ( strstr( tB, "operator id") != NULL ) {
|
|
trim(CA->at(1));
|
|
retVal->operator_id = atoi(CA->at(1));
|
|
break;
|
|
};
|
|
if ( strstr( tB, "registration") != NULL ) {
|
|
trim(CA->at(1));
|
|
strncpy(retVal->registration, CA->at(1), 64);
|
|
retVal->registration[64] = (char)0;
|
|
break;
|
|
};
|
|
break;
|
|
};
|
|
case CFG_SIM:{
|
|
// LOG("SIM");
|
|
break;
|
|
};
|
|
case CFG_BEARER:{
|
|
// LOG("BEAR");
|
|
break;
|
|
};
|
|
//default: LOG("UNK");
|
|
};
|
|
} else {
|
|
LOG("No CA Parts!");
|
|
};
|
|
delete( CA );
|
|
} else {
|
|
LOG("No CA!");
|
|
};
|
|
};
|
|
fclose(fd);
|
|
};
|
|
};
|
|
#ifdef DEBUG
|
|
if ( retVal ) {
|
|
char ttB[256];
|
|
sprintf(ttB, "Modem ID: [%d]", retVal->modem_id);
|
|
LOG(ttB);
|
|
sprintf(ttB, "Modem HW Manufac: [%s]", retVal->hw_manufac);
|
|
LOG(ttB);
|
|
sprintf(ttB, "Modem HW Model: [%s]", retVal->hw_model);
|
|
LOG(ttB);
|
|
sprintf(ttB, "Modem HW id: [%s]", retVal->hw_id);
|
|
LOG(ttB);
|
|
sprintf(ttB, "Modem Revision id: [%s]", retVal->hw_revision);
|
|
LOG(ttB);
|
|
sprintf(ttB, "Modem Revision Version: [%s]", retVal->hw_version);
|
|
LOG(ttB);
|
|
sprintf(ttB, "Modem DBus id: [%s]", retVal->dbus_dev_id);
|
|
LOG(ttB);
|
|
sprintf(ttB, "Modem IMEI: [%s]", retVal->imei);
|
|
LOG(ttB);
|
|
sprintf(ttB, "Modem Access Tech: [%s]", retVal->conmection_tech);
|
|
LOG(ttB);
|
|
sprintf(ttB, "Modem Operator: [%d]", retVal->operator_id);
|
|
LOG(ttB);
|
|
sprintf(ttB, "Modem Power: [%s]", retVal->power);
|
|
LOG(ttB);
|
|
sprintf(ttB, "Modem Registration: [%s]", retVal->registration);
|
|
LOG(ttB);
|
|
sprintf(ttB, "Modem Signal Power: [%d%%]", retVal->signal);
|
|
LOG(ttB);
|
|
sprintf(ttB, "Modem Status: [%s]", retVal->status);
|
|
LOG(ttB);
|
|
};
|
|
#endif
|
|
return retVal;
|
|
};
|
|
|
|
DBC_INT_LIST *kernelModuleModemManager::enumerateModems(){
|
|
DBC_INT_LIST *retVal = new DBC_INT_LIST();
|
|
if( retVal != NULL ){
|
|
char tB[1024];
|
|
char expBuf[1024];
|
|
FILE * fd = NULL;
|
|
sprintf( tB, "mmcli -L" );
|
|
fd = popen( tB, "r");
|
|
LOG("BEGIN");
|
|
if( fd!= NULL ) {
|
|
while ( !feof( fd )) {
|
|
if( fgets( (CSTR)tB, 1024, fd ) ){
|
|
trim( tB );
|
|
strncpy( expBuf, tB, 1024 );
|
|
LOG( expBuf );
|
|
CArray *CA = explode( '/', expBuf );
|
|
if ( CA ) {
|
|
int cMID = -1;
|
|
cMID = atoi( CA->at( CA->size()-1) );
|
|
char tB[128];
|
|
sprintf( tB ,"Detected Modem [%d]", cMID );
|
|
retVal->push_back( cMID );
|
|
LOG( tB );
|
|
delete( CA );
|
|
};
|
|
};
|
|
};
|
|
fclose(fd);
|
|
};
|
|
LOG("DONE");
|
|
};
|
|
return retVal;
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
|
|
|
|
|