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.

826 lines
19 KiB

2 years ago
2 years ago
​
2 years ago
​
​
​
​
​
2 years ago
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
4 months ago
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
4 months ago
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 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. { \
  7. char _tBfrErrMSG2w34[256]; \
  8. sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
  9. kernelModule::m_pLog->Log("MOD_MODEM", this, _LOG_ERROR, _tBfrErrMSG2w34); \
  10. }
  11. #else
  12. #define LOG_ERROR(X) kernelModule::m_pLog->Log("MOD_MODEM", this, _LOG_ERROR, X)
  13. #endif
  14. #define SLOG(X) DATA->parent->m_pLog->Log("SMOD_MODEM", DATA->parent, X)
  15. kernelModuleModemManager::kernelModuleModemManager(uint32_t moduleID) :
  16. kernelModule(moduleID, KERNEL_MODULE_MODEM_MANAGER), basicThread()
  17. {
  18. m_cMyWanIP[0] = (char) 0;
  19. moduleActive = false;
  20. sessionStarted = false;
  21. m_bEnabled = true;
  22. if (checkCmdExists("mmcli") > 0)
  23. {
  24. LOG("ModemManager Present!");
  25. DBC_MODEM_MANAGER_DATA * tData = m_pDBC->getModemManagerData(m_nDBAUXID);
  26. if (tData)
  27. {
  28. memcpy(&m_sMMData, tData, sizeof(DBC_MODEM_MANAGER_DATA));
  29. free(tData);
  30. // Hangup all currently active calls
  31. if( m_sMMData.active_call > -1 )
  32. {
  33. char tCMD[128];
  34. sprintf(tCMD, "mmcli -m %d --call %d --hangup", m_sMMData.modem_id, m_sMMData.active_call);
  35. system(tCMD);
  36. sprintf(tCMD, "mmcli -m %d --voice-delete-call=%d", m_sMMData.modem_id, m_sMMData.active_call);
  37. system(tCMD);
  38. };
  39. moduleActive = true;
  40. }
  41. else
  42. {
  43. LOG_ERROR("No ModemManager Data Fetched from DB!");
  44. m_bEnabled = false;
  45. };
  46. }
  47. else
  48. {
  49. LOG_ERROR("No ModemManager installed in the System!");
  50. };
  51. }
  52. kernelModuleModemManager::~kernelModuleModemManager()
  53. {
  54. // if ( m_vUserData.size() ) {
  55. // for ( VECTOR_MDM_USER_DATA::iterator idx = m_vUserData.begin(); idx < m_vUserData.end(); idx++ ) {
  56. // if ( !(*idx)->finished ) pthread_join( (*idx)->handler, NULL);
  57. // };
  58. //};
  59. }
  60. bool kernelModuleModemManager::reloadSettings()
  61. {
  62. // LOG("Reload");
  63. if (getWM() == MDM_IDLE_WM)
  64. {
  65. DBC_INT_LIST * pList = m_pDBC->listPhonebook();
  66. if (pList)
  67. {
  68. if (m_vPhoneBook.size())
  69. {
  70. for (VECTOR_MDM_PHONE_BOOK::iterator idx = m_vPhoneBook.begin(); idx < m_vPhoneBook.end(); idx++)
  71. {
  72. free(*idx);
  73. };
  74. m_vPhoneBook.clear();
  75. };
  76. if (pList->size())
  77. {
  78. for (DBC_INT_LIST::iterator idx = pList->begin(); idx < pList->end(); idx++)
  79. {
  80. DBC_MODEM_PHONEBOOK_RECORD * tPtr = m_pDBC->getModemPhonebookRecord(*idx);
  81. if (tPtr)
  82. {
  83. #ifdef DEBUG_EXTRA
  84. char tB[200];
  85. sprintf(tB, "PBN: %s, LBL: %s MSG: %s", tPtr->number, tPtr->label, tPtr->custom_msg);
  86. LOG(tB);
  87. #endif
  88. m_vPhoneBook.push_back(tPtr);
  89. };
  90. };
  91. }
  92. else
  93. {
  94. moduleActive = false;
  95. }
  96. };
  97. return true;
  98. };
  99. return false;
  100. }
  101. bool kernelModuleModemManager::startService()
  102. {
  103. sessionStarted = false;
  104. LOG("Start Service");
  105. if (! m_bEnabled)
  106. {
  107. LOG_ERROR("Module is Disabled!");
  108. return false;
  109. };
  110. // Load PhoneBook
  111. setWM(MDM_IDLE_WM);
  112. if (m_sMMData.sms_enabled)
  113. {
  114. LOG("SMS Enabled!");
  115. }
  116. else
  117. {
  118. LOG("SMS DISABLED!");
  119. }
  120. // Get current WAN IP Address
  121. if (updateWanIP())
  122. {
  123. LOG("WAN IP OK!");
  124. }
  125. else
  126. {
  127. LOG("WAN IP NOK!");
  128. }
  129. return moduleActive = init();
  130. }
  131. bool kernelModuleModemManager::stopService(bool force)
  132. {
  133. LOG("Stop Service");
  134. setWM(MDM_STOP_WM);
  135. if ( force ) {
  136. m_bEnabled = false;
  137. waitThreadEnd( force );
  138. } else {
  139. m_bEnabled = !uninit();
  140. };
  141. return true;
  142. }
  143. void kernelModuleModemManager::m_fThreadProc(void)
  144. {
  145. uint32_t nCurrentPhoneBookId = 0;
  146. int32_t nCurrentCallId = 0;
  147. uint64_t lNextWindowAction = 0;
  148. pthread_setname_np( pthread_self(), "ModemManager" );
  149. m_bThreadStatus = TH_WORKING;
  150. while (m_bThreadStatus < TH_ENDED)
  151. {
  152. uint8_t bCWM = getWM();
  153. switch (bCWM)
  154. {
  155. case MDM_IDLE_WM:
  156. {
  157. break;
  158. };
  159. case MDM_INIT_CALL_WM:
  160. {
  161. if (nCurrentPhoneBookId < m_vPhoneBook.size())
  162. {
  163. DBC_MODEM_PHONEBOOK_RECORD * tRECORD = m_vPhoneBook.at(nCurrentPhoneBookId);
  164. if (tRECORD)
  165. {
  166. m_bCurrentMode = tRECORD->mode;
  167. m_pDBC->updateModemManagerActivePhoneBookID(m_sMMData.id, tRECORD->id);
  168. switch (m_bCurrentMode)
  169. {
  170. case 0:
  171. {
  172. if (m_sMMData.sms_enabled)
  173. {
  174. nCurrentCallId = -1;
  175. LOG("Start SMS");
  176. char CMSG[512];
  177. char CMD[1024];
  178. sprintf(CMSG, "Alarm Message %s System at http://%s/", tRECORD->custom_msg, m_cMyWanIP);
  179. sprintf(CMD, "mmcli -m %d --messaging-create-sms=\"text='%s',number='%s'\"", m_sMMData.modem_id, CMSG, tRECORD->number);
  180. LOG(CMD);
  181. FILE * fd = popen(CMD, "r");
  182. if (fd)
  183. {
  184. char tB[1024];
  185. if (fread(tB, 1, 1023, fd) > 0)
  186. {
  187. CSTR tS = strstr(tB, "SMS/");
  188. if (tS)
  189. {
  190. nCurrentCallId = atoi(tS + 4);
  191. };
  192. };
  193. pclose(fd);
  194. }
  195. else
  196. {
  197. LOG_ERROR("Cannot Start POPEN 1!");
  198. }
  199. if (nCurrentCallId > -1)
  200. {
  201. sprintf(CMD, "mmcli -s %d --send", nCurrentCallId);
  202. system(CMD);
  203. m_pDBC->updateModemManagerActiveCall(m_sMMData.id, nCurrentCallId);
  204. lNextWindowAction = getMilliseconds() + m_sMMData.call_hangup_wait * 1000;
  205. // Need to wait till calling
  206. setWM(MDM_MODEM_IS_BUSY_WM);
  207. }
  208. else
  209. {
  210. setWM(MDM_FETCH_NEXT_WM);
  211. };
  212. m_bCurrentMode = 2;
  213. continue;
  214. };
  215. if (m_sMMData.call_enabled)
  216. {
  217. nCurrentCallId = -1;
  218. LOG("Start Call");
  219. char CMD[128];
  220. sprintf(CMD, "mmcli -m %d --voice-create-call='number=%s'", m_sMMData.modem_id, tRECORD->number);
  221. LOG(CMD);
  222. FILE * fd = popen(CMD, "r");
  223. if (fd)
  224. {
  225. char tB[1024];
  226. if (fread(tB, 1, 1023, fd) > 0)
  227. {
  228. CSTR tS = strstr(tB, "Call/");
  229. if (tS)
  230. {
  231. nCurrentCallId = atoi(tS + 5);
  232. };
  233. };
  234. pclose(fd);
  235. }
  236. else
  237. {
  238. LOG_ERROR("Cannot Start POPEN 1!");
  239. }
  240. if (nCurrentCallId > -1)
  241. {
  242. sprintf(CMD, "mmcli -m %d --call %d --start", m_sMMData.modem_id, nCurrentCallId);
  243. system(CMD);
  244. m_pDBC->updateModemManagerActiveCall(m_sMMData.id, nCurrentCallId);
  245. lNextWindowAction = getMilliseconds() + m_sMMData.call_hangup_wait * 1000;
  246. // Need to wait till calling
  247. setWM(MDM_MODEM_IS_BUSY_WM);
  248. }
  249. else
  250. {
  251. setWM(MDM_FETCH_NEXT_WM);
  252. };
  253. m_bCurrentMode = 1;
  254. continue;
  255. };
  256. setWM(MDM_FETCH_NEXT_WM);
  257. break;
  258. };
  259. case 1:
  260. {
  261. if (! m_sMMData.call_enabled)
  262. {
  263. setWM(MDM_FETCH_NEXT_WM);
  264. }
  265. nCurrentCallId = -1;
  266. LOG("Start Call");
  267. char CMD[128];
  268. sprintf(CMD, "mmcli -m %d --voice-create-call='number=%s'", m_sMMData.modem_id, tRECORD->number);
  269. LOG(CMD);
  270. FILE * fd = popen(CMD, "r");
  271. if (fd)
  272. {
  273. char tB[1024];
  274. if (fread(tB, 1, 1023, fd) > 0)
  275. {
  276. CSTR tS = strstr(tB, "Call/");
  277. if (tS)
  278. {
  279. nCurrentCallId = atoi(tS + 5);
  280. };
  281. };
  282. pclose(fd);
  283. }
  284. else
  285. {
  286. LOG_ERROR("Cannot Start POPEN 1!");
  287. }
  288. if (nCurrentCallId > -1)
  289. {
  290. sprintf(CMD, "mmcli -m %d --call %d --start", m_sMMData.modem_id, nCurrentCallId);
  291. system(CMD);
  292. m_pDBC->updateModemManagerActiveCall(m_sMMData.id, nCurrentCallId);
  293. lNextWindowAction = getMilliseconds() + m_sMMData.call_hangup_wait * 1000;
  294. // Need to wait till calling
  295. setWM(MDM_MODEM_IS_BUSY_WM);
  296. }
  297. else
  298. {
  299. setWM(MDM_FETCH_NEXT_WM);
  300. };
  301. break;
  302. };
  303. case 2:
  304. {
  305. if (! m_sMMData.sms_enabled)
  306. {
  307. setWM(MDM_FETCH_NEXT_WM);
  308. }
  309. nCurrentCallId = -1;
  310. LOG("Start SMS");
  311. char CMSG[512];
  312. char CMD[1024];
  313. sprintf(CMSG, "Alarm Message %s System at http://%s/", tRECORD->custom_msg, m_cMyWanIP);
  314. sprintf(CMD, "mmcli -m %d --messaging-create-sms=\"text='%s',number='%s'\"", m_sMMData.modem_id, CMSG, tRECORD->number);
  315. LOG(CMD);
  316. FILE * fd = popen(CMD, "r");
  317. if (fd)
  318. {
  319. char tB[1024];
  320. if (fread(tB, 1, 1023, fd) > 0)
  321. {
  322. CSTR tS = strstr(tB, "SMS/");
  323. if (tS)
  324. {
  325. nCurrentCallId = atoi(tS + 4);
  326. };
  327. };
  328. pclose(fd);
  329. }
  330. else
  331. {
  332. LOG_ERROR("Cannot Start POPEN 1!");
  333. }
  334. if (nCurrentCallId > -1)
  335. {
  336. sprintf(CMD, "mmcli -s %d --send", nCurrentCallId);
  337. system(CMD);
  338. m_pDBC->updateModemManagerActiveCall(m_sMMData.id, nCurrentCallId);
  339. lNextWindowAction = getMilliseconds() + m_sMMData.call_hangup_wait * 1000;
  340. // Need to wait till calling
  341. setWM(MDM_MODEM_IS_BUSY_WM);
  342. }
  343. else
  344. {
  345. setWM(MDM_FETCH_NEXT_WM);
  346. };
  347. break;
  348. };
  349. };
  350. } else {
  351. char ttB[65];
  352. sprintf(ttB, "No Phone Book Record [%d]!", nCurrentPhoneBookId);
  353. LOG_ERROR(ttB);
  354. //sessionStarted = false;
  355. setWM(MDM_IDLE_WM);
  356. };
  357. } else {
  358. LOG("Finished Fetching all call rcpt or there no rcpt!");
  359. nCurrentPhoneBookId = 0;
  360. setWM(MDM_IDLE_WM);
  361. };
  362. break;
  363. };
  364. case MDM_MODEM_IS_BUSY_WM:
  365. {
  366. if (m_bCurrentMode == 1)
  367. {
  368. // Finishing Call
  369. char CMD[128];
  370. bool call_is_answered = false;
  371. bool call_is_terminated = false;
  372. bool call_is_finished = false;
  373. sprintf(CMD, "mmcli -m %d --voice-list-calls", m_sMMData.modem_id);
  374. FILE * fd = popen(CMD, "r");
  375. if (fd)
  376. {
  377. char tB[1024];
  378. if (fread(tB, 1, 1023, fd) > 0)
  379. {
  380. CSTR tS = strstr(tB, "(active)");
  381. if (tS)
  382. {
  383. call_is_answered = true;
  384. };
  385. tS = strstr(tB, "(terminated)");
  386. if (tS)
  387. {
  388. call_is_terminated = true;
  389. };
  390. };
  391. pclose(fd);
  392. }
  393. else
  394. {
  395. LOG_ERROR("Cannot Start POPEN 2!");
  396. }
  397. if (call_is_answered || call_is_terminated)
  398. {
  399. if (call_is_answered)
  400. {
  401. LOG("Call is Answered!!");
  402. // Send Voice Message to user
  403. };
  404. call_is_finished = true;
  405. }
  406. else
  407. {
  408. if (lNextWindowAction < getMilliseconds())
  409. {
  410. call_is_finished = true;
  411. }
  412. };
  413. if (call_is_finished)
  414. {
  415. LOG("Hangup Call");
  416. sprintf(CMD, "mmcli -m %d --call %d --hangup", m_sMMData.modem_id, nCurrentCallId);
  417. LOG(CMD);
  418. system(CMD);
  419. sprintf(CMD, "mmcli -m %d --voice-delete-call=%d", m_sMMData.modem_id, nCurrentCallId);
  420. LOG(CMD);
  421. system(CMD);
  422. m_pDBC->updateModemManagerActiveCall(m_sMMData.id, -1);
  423. setWM(MDM_FETCH_NEXT_WM);
  424. };
  425. }
  426. else
  427. {
  428. // Finishing SMS
  429. char CMD[128];
  430. bool sms_is_sent = false;
  431. sprintf(CMD, "mmcli -m %d --messaging-list-sms", m_sMMData.modem_id);
  432. FILE * fd = popen(CMD, "r");
  433. if (fd)
  434. {
  435. char tB[1024];
  436. if (fread(tB, 1, 1023, fd) > 0)
  437. {
  438. CSTR tS = strstr(tB, "(sent)");
  439. if (tS)
  440. {
  441. sms_is_sent = true;
  442. };
  443. };
  444. pclose(fd);
  445. }
  446. else
  447. {
  448. LOG_ERROR("Cannot Start POPEN 2!");
  449. }
  450. if (sms_is_sent)
  451. {
  452. LOG("SMS is Sent!!");
  453. }
  454. else
  455. {
  456. if (lNextWindowAction < getMilliseconds())
  457. {
  458. sms_is_sent = true;
  459. }
  460. };
  461. if (sms_is_sent)
  462. {
  463. sprintf(CMD, "mmcli -m %d --messaging-delete-sms=%d", m_sMMData.modem_id, nCurrentCallId);
  464. LOG(CMD);
  465. system(CMD);
  466. m_pDBC->updateModemManagerActiveCall(m_sMMData.id, -1);
  467. setWM(MDM_FETCH_NEXT_WM);
  468. };
  469. };
  470. break;
  471. };
  472. case MDM_FETCH_NEXT_WM:
  473. {
  474. if (nCurrentPhoneBookId < m_vPhoneBook.size())
  475. {
  476. nCurrentPhoneBookId++;
  477. setWM(MDM_INIT_CALL_WM);
  478. }
  479. else
  480. {
  481. nCurrentPhoneBookId = 0;
  482. m_pDBC->updateModemManagerActivePhoneBookID(m_sMMData.id, 0);
  483. lNextWindowAction = getMilliseconds() + m_sMMData.time_window;
  484. setWM(MDM_WAIT_WINDOW_WM);
  485. };
  486. break;
  487. };
  488. case MDM_WAIT_WINDOW_WM:
  489. {
  490. if (lNextWindowAction < getMilliseconds())
  491. {
  492. sessionStarted = false;
  493. setWM(MDM_IDLE_WM);
  494. };
  495. break;
  496. };
  497. case MDM_STOP_WM:
  498. {
  499. m_bThreadStatus = TH_ENDED;
  500. break;
  501. }
  502. };
  503. SLEEP(DEFAULT_THREAD_SLEEP_TIME);
  504. };
  505. }
  506. bool kernelModuleModemManager::dispatchEvent(EVENT_CONTAINER * Evt){
  507. if (moduleActive){
  508. if (Evt == NULL) return false;
  509. switch (Evt->m_eType){
  510. case EVT_TARGET_1D:
  511. case EVT_TARGET_3D_WHITE:
  512. case EVT_TARGET_3D_BLACK:
  513. case EVT_TARGET_2D_WHITE:
  514. case EVT_TARGET_2D_BLACK:{
  515. if (!sessionStarted) {
  516. //Only Work On Session Start -> No need to follow each detection
  517. sessionStarted = true;
  518. setWM(MDM_INIT_CALL_WM);
  519. };
  520. break;
  521. };
  522. case EVT_LRF_START_SESSION:{
  523. if (!sessionStarted) {
  524. sessionStarted = true;
  525. setWM(MDM_INIT_CALL_WM);
  526. };
  527. break;
  528. };
  529. case EVT_LRF_END_SESSION_TO:
  530. case EVT_LRF_END_SESSION_MA:{
  531. sessionStarted = false;
  532. break;
  533. };
  534. default: break;
  535. };
  536. };
  537. return true;
  538. }
  539. bool kernelModuleModemManager::validate()
  540. {
  541. reloadSettings();
  542. if (moduleActive)
  543. {
  544. if (m_sMMData.sms_enabled)
  545. {
  546. // Get current WAN IP Address
  547. return updateWanIP();
  548. #ifdef DEBUG_EXTRA
  549. }
  550. else
  551. {
  552. LOG("SMS Disabled!");
  553. #endif
  554. };
  555. #ifdef DEBUG_EXTRA
  556. }
  557. else
  558. {
  559. LOG("Module is Disabled");
  560. #endif
  561. };
  562. return true;
  563. }
  564. #define TLOG_ERROR(X) DATA->parent->m_pLog->Log("MOD_MODEM_T", DATA->parent, _LOG_ERROR, X)
  565. void * kernelModuleModemManager::callProc(void * ptr)
  566. {
  567. MDM_CALL_DATA * DATA = (MDM_CALL_DATA *) ptr;
  568. if (DATA)
  569. {
  570. char CMD[128];
  571. uint32_t callID = 0;
  572. sprintf(CMD, "mmcli -m %d --voice-create-call='number=%s'", DATA->modem_id, DATA->target);
  573. /*
  574. Successfully created new call: /org/freedesktop/ModemManager1/Call/2
  575. */
  576. SLOG(CMD);
  577. FILE * fd = popen(CMD, "r");
  578. if (fd)
  579. {
  580. char tB[1024];
  581. if (fread(tB, 1, 1023, fd) > 0)
  582. {
  583. CSTR tS = strstr(tB, "Call/");
  584. if (tS)
  585. {
  586. callID = atoi(tS + 5);
  587. };
  588. };
  589. pclose(fd);
  590. }
  591. else
  592. {
  593. SLOG("Cannot Start POPEN 1!");
  594. };
  595. if (callID)
  596. {
  597. sprintf(CMD, "mmcli -m %d --call %d --start", DATA->modem_id, callID);
  598. SLOG(CMD);
  599. system(CMD);
  600. // Wait X seconds then hang call or play voice message
  601. uint8_t bTO = 60; // 15 seconds
  602. bool call_is_answered = false;
  603. bool call_is_terminated = false;
  604. sprintf(CMD, "mmcli -m %d --voice-list-calls", DATA->modem_id);
  605. while (bTO && ! call_is_answered && ! call_is_terminated)
  606. {
  607. fd = popen(CMD, "r");
  608. if (fd)
  609. {
  610. char tB[1024];
  611. if (fread(tB, 1, 1023, fd) > 0)
  612. {
  613. CSTR tS = strstr(tB, "(active)");
  614. if (tS)
  615. {
  616. call_is_answered = true;
  617. };
  618. tS = strstr(tB, "(terminated)");
  619. if (tS)
  620. {
  621. call_is_terminated = true;
  622. };
  623. };
  624. pclose(fd);
  625. }
  626. else
  627. {
  628. SLOG("Cannot Start POPEN 2!");
  629. }
  630. SLEEP(250);
  631. bTO--;
  632. };
  633. if (bTO && ! call_is_terminated)
  634. {
  635. if (DATA->parent->m_sMMData.voice_sink[0])
  636. {
  637. // Play Wave
  638. // u-law (8000 Hz, 8-bits per sample, mono, 64k)
  639. // play -t raw -r 8000 -c 1 -e u-law -
  640. // SLEEP(DATA->parent->m_sMMData.call_hangup_wait * 1000);
  641. // unlink("/tmp/argus_voice.wav");
  642. };
  643. };
  644. sprintf(CMD, "mmcli -m %d --call %d --hangup", DATA->modem_id, callID);
  645. SLOG(CMD);
  646. system(CMD);
  647. sprintf(CMD, "mmcli -m %d --voice-delete-call=%d", DATA->modem_id, callID);
  648. SLOG(CMD);
  649. system(CMD);
  650. }
  651. else
  652. {
  653. SLOG("Call is not registered at Modem!");
  654. }
  655. };
  656. pthread_exit(NULL);
  657. return NULL;
  658. }
  659. void * kernelModuleModemManager::smsProc(void * ptr)
  660. {
  661. MDM_SMS_DATA * DATA = (MDM_SMS_DATA *) ptr;
  662. if (DATA)
  663. {
  664. char CMD[128];
  665. uint32_t smsID = 0;
  666. sprintf(CMD, "mmcli -m %d --messaging-create-sms=\"text='%s',number='%s'\"", DATA->modem_id, DATA->text, DATA->target);
  667. FILE * fd = popen(CMD, "r");
  668. if (fd)
  669. {
  670. char tB[1024];
  671. if (fread(tB, 1, 1023, fd) > 0)
  672. {
  673. CSTR tS = strstr(tB, "SMS/");
  674. if (tS)
  675. {
  676. smsID = atoi(tS + 4);
  677. };
  678. };
  679. pclose(fd);
  680. };
  681. if (smsID)
  682. {
  683. // Wait X seconds then hang call
  684. // SLEEP( DATA->parent->m_sMMData.call_hangup_wait * 1000 );
  685. sprintf(CMD, "mmcli -s %d --send", smsID);
  686. fd = popen(CMD, "r");
  687. if (fd)
  688. {
  689. pclose(fd);
  690. }
  691. else
  692. {
  693. TLOG_ERROR("Cannot Execute Call Hang Command!");
  694. };
  695. }
  696. else
  697. {
  698. TLOG_ERROR("Call is not registered at Modem!");
  699. }
  700. };
  701. pthread_exit(NULL);
  702. return NULL;
  703. }
  704. uint32_t kernelModuleModemManager::startCall(CSTR number)
  705. {
  706. MDM_CALL_DATA * DATA = (MDM_CALL_DATA *) malloc(sizeof(MDM_CALL_DATA));
  707. if (DATA)
  708. {
  709. LOG(number);
  710. memset(DATA, 0, sizeof(MDM_CALL_DATA));
  711. DATA->modem_id = m_sMMData.modem_id;
  712. DATA->parent = this;
  713. strncpy(DATA->target, number, 64);
  714. int RetVal = pthread_create(&DATA->handler, NULL, callProc, (void *) DATA);
  715. if (RetVal == -1)
  716. {
  717. LOG_ERROR("Cannot start Call Procedure.");
  718. free(DATA);
  719. return 0;
  720. };
  721. // Push Data into vector
  722. m_vUserData.push_back((MDM_USER_DATA *) DATA);
  723. }
  724. else
  725. {
  726. LOG_ERROR("Cannot allocate Call data.");
  727. };
  728. return 0;
  729. }
  730. void kernelModuleModemManager::sendSMS(CSTR number, CSTR text) {
  731. if ( number || text ) LOG("SMSM");
  732. //todo: Make code
  733. }
  734. void kernelModuleModemManager::hangupCall(uint32_t call_id) {
  735. if ( call_id ) call_id = 0;
  736. //todo: Make code
  737. }
  738. bool kernelModuleModemManager::updateWanIP()
  739. {
  740. char CMD[128];
  741. //uint32_t smsID = 0;
  742. bool bDone = false;
  743. sprintf(CMD, "ifconfig");
  744. FILE * fd = popen(CMD, "r");
  745. if (fd)
  746. {
  747. CSTR tB = NULL;
  748. size_t bSize = 0;
  749. bool bIfMeet = false;
  750. while (! feof(fd))
  751. {
  752. ssize_t rv = getline(&tB, &bSize, fd);
  753. if (rv)
  754. {
  755. if (! bDone)
  756. {
  757. if (bIfMeet)
  758. {
  759. CSTR ssp = strstr(tB, "inet ");
  760. if (ssp)
  761. {
  762. CSTR nsp = strstr(tB, "netmask");
  763. int msl = nsp - ssp - 7;
  764. strncpy(m_cMyWanIP, ssp + 5, msl);
  765. m_cMyWanIP[msl] = (char) 0;
  766. bDone = true;
  767. };
  768. }
  769. else
  770. {
  771. if (strstr(tB, "wwan"))
  772. {
  773. bIfMeet = true;
  774. }
  775. if (strstr(tB, "wwx"))
  776. {
  777. bIfMeet = true;
  778. }
  779. };
  780. };
  781. };
  782. if (tB)
  783. {
  784. free(tB);
  785. tB = NULL;
  786. };
  787. };
  788. pclose(fd);
  789. };
  790. #ifdef DEBUG_EXTRA
  791. if (bDone)
  792. {
  793. sprintf(CMD, "WAN IP4: %s", m_cMyWanIP);
  794. LOG(CMD);
  795. }
  796. else
  797. {
  798. LOG_ERROR("Cannot Find WAN IP4 Address!");
  799. };
  800. #endif
  801. return bDone;
  802. }
  803. #undef SLOG
  804. #undef LOG
  805. #undef LOG_ERROR