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

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
4 years ago
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
  1. #include "kernelModuleModemManager.h"
  2. #include "../../components/base/basicFunctionality.h"
  3. #define LOG( X ) kernelModule::m_pLog->Log( "MOD_MODEM", this, X )
  4. #ifdef DEBUG
  5. #define LOG_ERROR( X ) {\
  6. char _tBfrErrMSG2w34[256];\
  7. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  8. kernelModule::m_pLog->Log( "MOD_MODEM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  9. }
  10. #else
  11. #define LOG_ERROR( X ) kernelModule::m_pLog->Log( "MOD_MODEM", this, _LOG_ERROR, X );
  12. #endif
  13. kernelModuleModemManager::kernelModuleModemManager( uint32_t moduleID ): kernelModule( moduleID, KERNEL_MODULE_MODEM_MANAGER ), basicThread(){
  14. LOG("Creating!");
  15. if( checkCmdExists("mmcli") > 0 ){
  16. //Modem Manager Exists
  17. LOG("Manager OK!");
  18. //m_pDBC->clenupModemInfos();
  19. DBC_INT_LIST * tList = enumerateModems();
  20. if ( tList != NULL ) {
  21. if( tList->size() ) {
  22. for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) {
  23. DBC_MODEM_DATA * tRecord = getModemInfo( *idx );
  24. if ( tRecord ) {
  25. //m_pDBC->updateModemInfo( tRecord );
  26. free( tRecord );
  27. };
  28. };
  29. } else {
  30. LOG("No Modems Presented in the System!");
  31. };
  32. delete(tList);
  33. };
  34. };
  35. };
  36. kernelModuleModemManager::~kernelModuleModemManager(){
  37. //if ( m_pvModems!= NULL ) delete( m_pvModems );
  38. };
  39. bool kernelModuleModemManager::reloadSettings(){
  40. return true;
  41. };
  42. bool kernelModuleModemManager::startService(){
  43. return true;
  44. };
  45. bool kernelModuleModemManager::stopService( bool force ){
  46. return true;
  47. };
  48. void kernelModuleModemManager::m_fThreadProc( void ){
  49. };
  50. void kernelModuleModemManager::dispatchEvent(EVENT_CONTAINER *Evt){
  51. };
  52. bool kernelModuleModemManager::validate(){
  53. //DBC_MODEM_DATA *tDATA = getModemInfo( 0 );
  54. //if ( tDATA ) {
  55. // free( tDATA );
  56. //};
  57. return true;
  58. };
  59. typedef enum E_CFG_TAG_ID{
  60. CFG_GENERAL = 0,
  61. CFG_HARDWARE = 1,
  62. CFG_SYSTEM,
  63. CFG_STATUS,
  64. CFG_MODES,
  65. CFG_BANDS,
  66. CFG_IP,
  67. CFG_EPS,
  68. CFG_3GPP,
  69. CFG_SIM,
  70. CFG_BEARER,
  71. CFG_COUNT
  72. }CFG_TAG_ID;
  73. const CSTR cfg_tags[]={
  74. "General",
  75. "Hardware",
  76. "System",
  77. "Status",
  78. "Modes",
  79. "Bands",
  80. "IP",
  81. "3GPP EPS",
  82. "3GPP",
  83. "SIM",
  84. "Bearer"
  85. };
  86. DBC_MODEM_DATA *kernelModuleModemManager::getModemInfo( uint32_t modem_id ){
  87. char tB[1024];
  88. char expBuf[1024];
  89. FILE * fd = NULL;
  90. CFG_TAG_ID cMode = CFG_GENERAL;
  91. DBC_MODEM_DATA * retVal = (DBC_MODEM_DATA *)malloc(sizeof(DBC_MODEM_DATA));
  92. if ( retVal != NULL ) {
  93. memset( retVal, 0 , sizeof(DBC_MODEM_DATA)); // --output-json
  94. sprintf( tB, "mmcli --modem=%d", modem_id );
  95. fd = popen( tB, "r");
  96. bool tPortsParsing = false;
  97. if (fd!= NULL ) {
  98. retVal->modem_id = modem_id;
  99. while ( !feof( fd )) {
  100. fgets( (CSTR)tB, 1024, fd );
  101. trim( tB );
  102. if( strstr(tB, "error:" ) != NULL){
  103. free( retVal );
  104. retVal = NULL;
  105. break;
  106. };
  107. LOG(tB);
  108. strncpy( expBuf, tB, 1024 );
  109. CArray *CA = explode( ':', expBuf );
  110. if( CA ){
  111. if( CA->size() ){
  112. for( int ii = CFG_GENERAL; ii < CFG_COUNT; ii++ ){
  113. if( strstr( CA->at(0), cfg_tags[ii] ) != NULL ){
  114. cMode = (CFG_TAG_ID) ii;
  115. break;
  116. };
  117. };
  118. switch( cMode ){
  119. case CFG_GENERAL:{
  120. //LOG("GEN");
  121. if ( strstr( CA->at(0), "device id") != NULL ) {
  122. trim(CA->at(1));
  123. strncpy( retVal->dbus_dev_id, CA->at(1), 64 );
  124. retVal->dbus_dev_id[64] = (char)0;
  125. break;
  126. };
  127. break;
  128. };
  129. case CFG_HARDWARE:{
  130. //LOG("HW");
  131. if ( strstr( tB, "manufacturer") != NULL ) {
  132. trim(CA->at(1));
  133. strncpy( retVal->hw_manufac, CA->at(1), 64);
  134. retVal->hw_manufac[64] = (char)0;
  135. break;
  136. };
  137. if ( strstr( tB, "model") != NULL ) {
  138. trim(CA->at(1));
  139. strncpy(retVal->hw_model, CA->at(1), 64);
  140. retVal->hw_model[64] = (char)0;
  141. break;
  142. };
  143. if ( strstr( tB, "h/w revision") != NULL ) {
  144. trim(CA->at(1));
  145. strncpy(retVal->hw_revision, CA->at(1), 64);
  146. retVal->hw_revision[64] = (char)0;
  147. break;
  148. };
  149. if ( strstr( tB, "revision") != NULL ) {
  150. trim(CA->at(1));
  151. strncpy(retVal->hw_version, CA->at(1), 32);
  152. retVal->hw_revision[32] = (char)0;
  153. break;
  154. };
  155. if ( strstr( tB, "equipment id") != NULL ) {
  156. trim(CA->at(1));
  157. strncpy(retVal->hw_id, CA->at(1), 32);
  158. retVal->hw_id[32] = (char)0;
  159. break;
  160. };
  161. break;
  162. };
  163. case CFG_SYSTEM:{
  164. //LOG("SYS");
  165. if ( strstr( tB, "ports") != NULL ) {
  166. tPortsParsing = true;
  167. };
  168. if( tPortsParsing ){
  169. trim( CA->at(1) );
  170. LOG("Ports:");
  171. LOG( CA->at(1) );
  172. CArray *CZ = explode( ':', CA->at(1) );
  173. if ( CZ ) {
  174. int CP = 0;
  175. for (int z=0; z< CZ->size(); z++) {
  176. if ( strstr(CZ->at(z),"(at)")!= NULL ) {
  177. if( CP == 0 ){
  178. retVal->at_uart_id = 0;//m_pDBC->getUartIdByDevice();
  179. } else {
  180. retVal->at_uart_id_aux = 0;
  181. };
  182. CP++;
  183. };
  184. if (CP == 2) break;
  185. };
  186. delete( CZ );
  187. };
  188. break;
  189. };
  190. break;
  191. };
  192. case CFG_STATUS:{
  193. //LOG("STAT");
  194. if ( strstr( tB, "power state") != NULL ) {
  195. if ( strstr(CA->at(1),"on") ) {
  196. retVal->power[0] = 'E';
  197. retVal->power[1]=(char)0;
  198. } else {
  199. retVal->power[0] = 'D';
  200. retVal->power[1]=(char)0;
  201. };
  202. break;
  203. };
  204. if ( strstr( tB, "state") != NULL ) {
  205. if ( strstr(CA->at(1),"disabled") ) {
  206. retVal->status[0]='D';
  207. retVal->status[1]=(char)0;
  208. break;
  209. };
  210. if ( strstr(CA->at(1),"registered") ) {
  211. retVal->status[0]='R';
  212. retVal->status[1]=(char)0;
  213. break;
  214. };
  215. break;
  216. };
  217. if ( strstr( tB, "access tech") != NULL ) {
  218. trim(CA->at(1));
  219. strncpy(retVal->conmection_tech, CA->at(1), 5);
  220. retVal->conmection_tech[5] = (char)0;
  221. break;
  222. };
  223. if ( strstr( tB, "signal quality") != NULL ) {
  224. trim(CA->at(1));
  225. retVal->signal = atoi(CA->at(1));
  226. break;
  227. };
  228. break;
  229. };
  230. case CFG_MODES:{
  231. //LOG("MOD");
  232. //if ( strstr( CA->at(0), "current") != NULL ) {
  233. // trim(CA->at(1));
  234. // strncpy( retVal->hw_manufac, CA->at(1), 64);
  235. // retVal->hw_manufac[64] = (char)0;
  236. // break;
  237. //};
  238. break;
  239. };
  240. case CFG_IP:{
  241. //LOG("IP");
  242. break;
  243. };
  244. case CFG_EPS:{
  245. //LOG("EPS");
  246. break;
  247. };
  248. case CFG_3GPP:{
  249. // LOG("3GPP");
  250. if ( strstr( tB, "imei") != NULL ) {
  251. trim(CA->at(1));
  252. strncpy( retVal->imei, CA->at(1), 16);
  253. retVal->imei[16] = (char)0;
  254. break;
  255. };
  256. if ( strstr( tB, "operator id") != NULL ) {
  257. trim(CA->at(1));
  258. retVal->operator_id = atoi(CA->at(1));
  259. break;
  260. };
  261. if ( strstr( tB, "registration") != NULL ) {
  262. trim(CA->at(1));
  263. strncpy(retVal->registration, CA->at(1), 64);
  264. retVal->registration[64] = (char)0;
  265. break;
  266. };
  267. break;
  268. };
  269. case CFG_SIM:{
  270. // LOG("SIM");
  271. break;
  272. };
  273. case CFG_BEARER:{
  274. // LOG("BEAR");
  275. break;
  276. };
  277. //default: LOG("UNK");
  278. };
  279. } else {
  280. LOG("No CA Parts!");
  281. };
  282. delete( CA );
  283. } else {
  284. LOG("No CA!");
  285. };
  286. };
  287. fclose(fd);
  288. };
  289. };
  290. #ifdef DEBUG
  291. if ( retVal ) {
  292. char ttB[256];
  293. sprintf(ttB, "Modem ID: [%d]", retVal->modem_id);
  294. LOG(ttB);
  295. sprintf(ttB, "Modem HW Manufac: [%s]", retVal->hw_manufac);
  296. LOG(ttB);
  297. sprintf(ttB, "Modem HW Model: [%s]", retVal->hw_model);
  298. LOG(ttB);
  299. sprintf(ttB, "Modem HW id: [%s]", retVal->hw_id);
  300. LOG(ttB);
  301. sprintf(ttB, "Modem Revision id: [%s]", retVal->hw_revision);
  302. LOG(ttB);
  303. sprintf(ttB, "Modem Revision Version: [%s]", retVal->hw_version);
  304. LOG(ttB);
  305. sprintf(ttB, "Modem DBus id: [%s]", retVal->dbus_dev_id);
  306. LOG(ttB);
  307. sprintf(ttB, "Modem IMEI: [%s]", retVal->imei);
  308. LOG(ttB);
  309. sprintf(ttB, "Modem Access Tech: [%s]", retVal->conmection_tech);
  310. LOG(ttB);
  311. sprintf(ttB, "Modem Operator: [%d]", retVal->operator_id);
  312. LOG(ttB);
  313. sprintf(ttB, "Modem Power: [%s]", retVal->power);
  314. LOG(ttB);
  315. sprintf(ttB, "Modem Registration: [%s]", retVal->registration);
  316. LOG(ttB);
  317. sprintf(ttB, "Modem Signal Power: [%d%%]", retVal->signal);
  318. LOG(ttB);
  319. sprintf(ttB, "Modem Status: [%s]", retVal->status);
  320. LOG(ttB);
  321. };
  322. #endif
  323. return retVal;
  324. };
  325. DBC_INT_LIST *kernelModuleModemManager::enumerateModems(){
  326. DBC_INT_LIST *retVal = new DBC_INT_LIST();
  327. if( retVal != NULL ){
  328. char tB[1024];
  329. char expBuf[1024];
  330. FILE * fd = NULL;
  331. sprintf( tB, "mmcli -L" );
  332. fd = popen( tB, "r");
  333. LOG("BEGIN");
  334. if( fd!= NULL ) {
  335. while ( !feof( fd )) {
  336. if( fgets( (CSTR)tB, 1024, fd ) ){
  337. trim( tB );
  338. strncpy( expBuf, tB, 1024 );
  339. LOG( expBuf );
  340. CArray *CA = explode( '/', expBuf );
  341. if ( CA ) {
  342. int cMID = -1;
  343. cMID = atoi( CA->at( CA->size()-1) );
  344. char tB[128];
  345. sprintf( tB ,"Detected Modem [%d]", cMID );
  346. retVal->push_back( cMID );
  347. LOG( tB );
  348. delete( CA );
  349. };
  350. };
  351. };
  352. fclose(fd);
  353. };
  354. LOG("DONE");
  355. };
  356. return retVal;
  357. };
  358. #undef LOG
  359. #undef LOG_ERROR