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.

324 lines
13 KiB

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. };
  19. };
  20. kernelModuleModemManager::~kernelModuleModemManager(){
  21. };
  22. bool kernelModuleModemManager::reloadSettings(){
  23. return true;
  24. };
  25. bool kernelModuleModemManager::startService(){
  26. return true;
  27. };
  28. bool kernelModuleModemManager::stopService( bool force ){
  29. return true;
  30. };
  31. void kernelModuleModemManager::m_fThreadProc( void ){
  32. };
  33. void kernelModuleModemManager::dispatchEvent(EVENT_CONTAINER *Evt){
  34. };
  35. bool kernelModuleModemManager::validate(){
  36. DBC_MODEM_DATA *tDATA = getModemInfo( 0 );
  37. if ( tDATA ) {
  38. free( tDATA );
  39. };
  40. return true;
  41. };
  42. void parseModemsInSystem(){
  43. "mmcli --list-modems";
  44. };
  45. typedef enum E_CFG_TAG_ID{
  46. CFG_GENERAL = 0,
  47. CFG_HARDWARE = 1,
  48. CFG_SYSTEM,
  49. CFG_STATUS,
  50. CFG_MODES,
  51. CFG_BANDS,
  52. CFG_IP,
  53. CFG_EPS,
  54. CFG_3GPP,
  55. CFG_SIM,
  56. CFG_BEARER,
  57. CFG_COUNT
  58. }CFG_TAG_ID;
  59. const CSTR cfg_tags[]={
  60. "General",
  61. "Hardware",
  62. "System",
  63. "Status",
  64. "Modes",
  65. "Bands",
  66. "IP",
  67. "3GPP EPS",
  68. "3GPP",
  69. "SIM",
  70. "Bearer"
  71. };
  72. DBC_MODEM_DATA *kernelModuleModemManager::getModemInfo( uint32_t modem_id ){
  73. char tB[1024];
  74. char expBuf[1024];
  75. FILE * fd = NULL;
  76. CFG_TAG_ID cMode = CFG_GENERAL;
  77. DBC_MODEM_DATA * retVal = (DBC_MODEM_DATA *)malloc(sizeof(DBC_MODEM_DATA));
  78. if ( retVal != NULL ) {
  79. memset( retVal, 0 , sizeof(DBC_MODEM_DATA));
  80. sprintf( tB, "mmcli --modem=%d", modem_id );
  81. fd = popen( tB, "r");
  82. if (fd!= NULL ) {
  83. retVal->modem_id = modem_id;
  84. while ( !feof( fd )) {
  85. fgets( (CSTR)tB, 1024, fd );
  86. trim( tB );
  87. if( strstr(tB, "error:" ) != NULL){
  88. free( retVal );
  89. retVal = NULL;
  90. break;
  91. };
  92. LOG(tB);
  93. strncpy( expBuf, tB, 1024 );
  94. CArray *CA = explode( ':', expBuf );
  95. if( CA ){
  96. if( CA->size() ){
  97. for( int ii = CFG_GENERAL; ii < CFG_COUNT; ii++ ){
  98. if( strstr( CA->at(0), cfg_tags[ii] ) != NULL ){
  99. cMode = (CFG_TAG_ID) ii;
  100. break;
  101. };
  102. };
  103. switch( cMode ){
  104. case CFG_GENERAL:{
  105. //LOG("GEN");
  106. if ( strstr( CA->at(0), "device id") != NULL ) {
  107. trim(CA->at(1));
  108. strncpy( retVal->dbus_dev_id, CA->at(1), 64 );
  109. retVal->dbus_dev_id[64] = (char)0;
  110. break;
  111. };
  112. break;
  113. };
  114. case CFG_HARDWARE:{
  115. //LOG("HW");
  116. if ( strstr( tB, "manufacturer") != NULL ) {
  117. trim(CA->at(1));
  118. strncpy( retVal->hw_manufac, CA->at(1), 64);
  119. retVal->hw_manufac[64] = (char)0;
  120. break;
  121. };
  122. if ( strstr( tB, "model") != NULL ) {
  123. trim(CA->at(1));
  124. strncpy(retVal->hw_model, CA->at(1), 64);
  125. retVal->hw_model[64] = (char)0;
  126. break;
  127. };
  128. if ( strstr( tB, "h/w revision") != NULL ) {
  129. trim(CA->at(1));
  130. strncpy(retVal->hw_revision, CA->at(1), 64);
  131. retVal->hw_revision[64] = (char)0;
  132. break;
  133. };
  134. if ( strstr( tB, "revision") != NULL ) {
  135. trim(CA->at(1));
  136. strncpy(retVal->hw_version, CA->at(1), 32);
  137. retVal->hw_revision[32] = (char)0;
  138. break;
  139. };
  140. if ( strstr( tB, "equipment id") != NULL ) {
  141. trim(CA->at(1));
  142. strncpy(retVal->hw_id, CA->at(1), 32);
  143. retVal->hw_id[32] = (char)0;
  144. break;
  145. };
  146. break;
  147. };
  148. case CFG_SYSTEM:{
  149. //LOG("SYS");
  150. if ( strstr( tB, "ports") != NULL ) {
  151. trim(CA->at(1));
  152. CArray *CZ = explode( ':', CA->at(1) );
  153. if ( CZ ) {
  154. int CP = 0;
  155. for (int z=0; z< CZ->size(); z++) {
  156. if ( strstr(CZ->at(z),"(at)")!= NULL ) {
  157. if (CP == 0 ) {
  158. retVal->at_uart_id = 1;//getUartIdByDevice();
  159. } else {
  160. retVal->at_uart_id_aux = 2;
  161. };
  162. CP++;
  163. };
  164. if (CP == 2) break;
  165. };
  166. delete( CZ );
  167. };
  168. break;
  169. };
  170. break;
  171. };
  172. case CFG_STATUS:{
  173. //LOG("STAT");
  174. if ( strstr( tB, "power state") != NULL ) {
  175. if ( strstr(CA->at(1),"on") ) {
  176. retVal->power[0] = 'E';
  177. retVal->power[1]=(char)0;
  178. } else {
  179. retVal->power[0] = 'D';
  180. retVal->power[1]=(char)0;
  181. };
  182. break;
  183. };
  184. if ( strstr( tB, "state") != NULL ) {
  185. if ( strstr(CA->at(1),"registered") ) {
  186. retVal->status[0]='R';
  187. retVal->status[1]=(char)0;
  188. } else {
  189. };
  190. break;
  191. };
  192. if ( strstr( tB, "access tech") != NULL ) {
  193. trim(CA->at(1));
  194. strncpy(retVal->conmection_tech, CA->at(1), 5);
  195. retVal->conmection_tech[5] = (char)0;
  196. break;
  197. };
  198. if ( strstr( tB, "signal quality") != NULL ) {
  199. trim(CA->at(1));
  200. retVal->signal = atoi(CA->at(1));
  201. break;
  202. };
  203. break;
  204. };
  205. case CFG_MODES:{
  206. //LOG("MOD");
  207. //if ( strstr( CA->at(0), "current") != NULL ) {
  208. // trim(CA->at(1));
  209. // strncpy( retVal->hw_manufac, CA->at(1), 64);
  210. // retVal->hw_manufac[64] = (char)0;
  211. // break;
  212. //};
  213. break;
  214. };
  215. case CFG_IP:{
  216. //LOG("IP");
  217. break;
  218. };
  219. case CFG_EPS:{
  220. //LOG("EPS");
  221. break;
  222. };
  223. case CFG_3GPP:{
  224. // LOG("3GPP");
  225. if ( strstr( tB, "imei") != NULL ) {
  226. trim(CA->at(1));
  227. strncpy( retVal->imei, CA->at(1), 16);
  228. retVal->imei[16] = (char)0;
  229. break;
  230. };
  231. if ( strstr( tB, "operator id") != NULL ) {
  232. trim(CA->at(1));
  233. retVal->operator_id = atoi(CA->at(1));
  234. break;
  235. };
  236. if ( strstr( tB, "registration") != NULL ) {
  237. trim(CA->at(1));
  238. strncpy(retVal->registration, CA->at(1), 64);
  239. retVal->registration[64] = (char)0;
  240. break;
  241. };
  242. break;
  243. };
  244. case CFG_SIM:{
  245. // LOG("SIM");
  246. break;
  247. };
  248. case CFG_BEARER:{
  249. // LOG("BEAR");
  250. break;
  251. };
  252. //default: LOG("UNK");
  253. };
  254. } else {
  255. LOG("No CA Parts!");
  256. };
  257. delete( CA );
  258. } else {
  259. LOG("No CA!");
  260. };
  261. };
  262. fclose(fd);
  263. };
  264. };
  265. #ifdef DEBUG_EXTRA
  266. if ( retVal ) {
  267. char ttB[256];
  268. sprintf(ttB, "Modem ID: [%d]", retVal->modem_id);
  269. LOG(ttB);
  270. sprintf(ttB, "Modem HW Manufac: [%s]", retVal->hw_manufac);
  271. LOG(ttB);
  272. sprintf(ttB, "Modem HW Model: [%s]", retVal->hw_model);
  273. LOG(ttB);
  274. sprintf(ttB, "Modem HW id: [%s]", retVal->hw_id);
  275. LOG(ttB);
  276. sprintf(ttB, "Modem Revision id: [%s]", retVal->hw_revision);
  277. LOG(ttB);
  278. sprintf(ttB, "Modem Revision Version: [%s]", retVal->hw_version);
  279. LOG(ttB);
  280. sprintf(ttB, "Modem DBus id: [%s]", retVal->dbus_dev_id);
  281. LOG(ttB);
  282. sprintf(ttB, "Modem IMEI: [%s]", retVal->imei);
  283. LOG(ttB);
  284. sprintf(ttB, "Modem Access Tech: [%s]", retVal->conmection_tech);
  285. LOG(ttB);
  286. sprintf(ttB, "Modem Operator: [%d]", retVal->operator_id);
  287. LOG(ttB);
  288. sprintf(ttB, "Modem Power: [%s]", retVal->power);
  289. LOG(ttB);
  290. sprintf(ttB, "Modem Registration: [%s]", retVal->registration);
  291. LOG(ttB);
  292. sprintf(ttB, "Modem Signal Power: [%d%%]", retVal->signal);
  293. LOG(ttB);
  294. sprintf(ttB, "Modem Status: [%s]", retVal->status);
  295. LOG(ttB);
  296. };
  297. #endif
  298. return retVal;
  299. };
  300. #undef LOG
  301. #undef LOG_ERROR