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.

830 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. }
  351. else
  352. {
  353. char ttB[65];
  354. sprintf(ttB, "No Phone Book Record [%d]!", nCurrentPhoneBookId);
  355. LOG_ERROR(ttB);
  356. sessionStarted = false;
  357. setWM(MDM_IDLE_WM);
  358. };
  359. }
  360. else
  361. {
  362. LOG("Finished Fetching all call rcpt or there no rcpt!");
  363. // sessionStarted = false;
  364. setWM(MDM_IDLE_WM);
  365. };
  366. break;
  367. };
  368. case MDM_MODEM_IS_BUSY_WM:
  369. {
  370. if (m_bCurrentMode == 1)
  371. {
  372. // Finishing Call
  373. char CMD[128];
  374. bool call_is_answered = false;
  375. bool call_is_terminated = false;
  376. bool call_is_finished = false;
  377. sprintf(CMD, "mmcli -m %d --voice-list-calls", m_sMMData.modem_id);
  378. FILE * fd = popen(CMD, "r");
  379. if (fd)
  380. {
  381. char tB[1024];
  382. if (fread(tB, 1, 1023, fd) > 0)
  383. {
  384. CSTR tS = strstr(tB, "(active)");
  385. if (tS)
  386. {
  387. call_is_answered = true;
  388. };
  389. tS = strstr(tB, "(terminated)");
  390. if (tS)
  391. {
  392. call_is_terminated = true;
  393. };
  394. };
  395. pclose(fd);
  396. }
  397. else
  398. {
  399. LOG_ERROR("Cannot Start POPEN 2!");
  400. }
  401. if (call_is_answered || call_is_terminated)
  402. {
  403. if (call_is_answered)
  404. {
  405. LOG("Call is Answered!!");
  406. // Send Voice Message to user
  407. };
  408. call_is_finished = true;
  409. }
  410. else
  411. {
  412. if (lNextWindowAction < getMilliseconds())
  413. {
  414. call_is_finished = true;
  415. }
  416. };
  417. if (call_is_finished)
  418. {
  419. LOG("Hangup Call");
  420. sprintf(CMD, "mmcli -m %d --call %d --hangup", m_sMMData.modem_id, nCurrentCallId);
  421. LOG(CMD);
  422. system(CMD);
  423. sprintf(CMD, "mmcli -m %d --voice-delete-call=%d", m_sMMData.modem_id, nCurrentCallId);
  424. LOG(CMD);
  425. system(CMD);
  426. m_pDBC->updateModemManagerActiveCall(m_sMMData.id, -1);
  427. setWM(MDM_FETCH_NEXT_WM);
  428. };
  429. }
  430. else
  431. {
  432. // Finishing SMS
  433. char CMD[128];
  434. bool sms_is_sent = false;
  435. sprintf(CMD, "mmcli -m %d --messaging-list-sms", m_sMMData.modem_id);
  436. FILE * fd = popen(CMD, "r");
  437. if (fd)
  438. {
  439. char tB[1024];
  440. if (fread(tB, 1, 1023, fd) > 0)
  441. {
  442. CSTR tS = strstr(tB, "(sent)");
  443. if (tS)
  444. {
  445. sms_is_sent = true;
  446. };
  447. };
  448. pclose(fd);
  449. }
  450. else
  451. {
  452. LOG_ERROR("Cannot Start POPEN 2!");
  453. }
  454. if (sms_is_sent)
  455. {
  456. LOG("SMS is Sent!!");
  457. }
  458. else
  459. {
  460. if (lNextWindowAction < getMilliseconds())
  461. {
  462. sms_is_sent = true;
  463. }
  464. };
  465. if (sms_is_sent)
  466. {
  467. sprintf(CMD, "mmcli -m %d --messaging-delete-sms=%d", m_sMMData.modem_id, nCurrentCallId);
  468. LOG(CMD);
  469. system(CMD);
  470. m_pDBC->updateModemManagerActiveCall(m_sMMData.id, -1);
  471. setWM(MDM_FETCH_NEXT_WM);
  472. };
  473. };
  474. break;
  475. };
  476. case MDM_FETCH_NEXT_WM:
  477. {
  478. if (nCurrentPhoneBookId < m_vPhoneBook.size())
  479. {
  480. nCurrentPhoneBookId++;
  481. setWM(MDM_INIT_CALL_WM);
  482. }
  483. else
  484. {
  485. nCurrentPhoneBookId = 0;
  486. m_pDBC->updateModemManagerActivePhoneBookID(m_sMMData.id, 0);
  487. lNextWindowAction = getMilliseconds() + m_sMMData.time_window;
  488. setWM(MDM_WAIT_WINDOW_WM);
  489. };
  490. break;
  491. };
  492. case MDM_WAIT_WINDOW_WM:
  493. {
  494. if (lNextWindowAction < getMilliseconds())
  495. {
  496. sessionStarted = false;
  497. setWM(MDM_IDLE_WM);
  498. };
  499. break;
  500. };
  501. case MDM_STOP_WM:
  502. {
  503. m_bThreadStatus = TH_ENDED;
  504. break;
  505. }
  506. };
  507. SLEEP(DEFAULT_THREAD_SLEEP_TIME);
  508. };
  509. }
  510. bool kernelModuleModemManager::dispatchEvent(EVENT_CONTAINER * Evt){
  511. if (moduleActive){
  512. if (Evt == NULL) return false;
  513. switch (Evt->m_eType){
  514. case EVT_TARGET_1D:
  515. case EVT_TARGET_3D_WHITE:
  516. case EVT_TARGET_3D_BLACK:
  517. case EVT_TARGET_2D_WHITE:
  518. case EVT_TARGET_2D_BLACK:{
  519. if (!sessionStarted) {
  520. //Only Work On Session Start -> No need to follow each detection
  521. sessionStarted = true;
  522. setWM(MDM_INIT_CALL_WM);
  523. };
  524. break;
  525. };
  526. case EVT_LRF_START_SESSION:{
  527. if (!sessionStarted) {
  528. sessionStarted = true;
  529. setWM(MDM_INIT_CALL_WM);
  530. };
  531. break;
  532. };
  533. case EVT_LRF_END_SESSION_TO:
  534. case EVT_LRF_END_SESSION_MA:{
  535. sessionStarted = false;
  536. break;
  537. };
  538. default: break;
  539. };
  540. };
  541. return true;
  542. }
  543. bool kernelModuleModemManager::validate()
  544. {
  545. reloadSettings();
  546. if (moduleActive)
  547. {
  548. if (m_sMMData.sms_enabled)
  549. {
  550. // Get current WAN IP Address
  551. return updateWanIP();
  552. #ifdef DEBUG_EXTRA
  553. }
  554. else
  555. {
  556. LOG("SMS Disabled!");
  557. #endif
  558. };
  559. #ifdef DEBUG_EXTRA
  560. }
  561. else
  562. {
  563. LOG("Module is Disabled");
  564. #endif
  565. };
  566. return true;
  567. }
  568. #define TLOG_ERROR(X) DATA->parent->m_pLog->Log("MOD_MODEM_T", DATA->parent, _LOG_ERROR, X)
  569. void * kernelModuleModemManager::callProc(void * ptr)
  570. {
  571. MDM_CALL_DATA * DATA = (MDM_CALL_DATA *) ptr;
  572. if (DATA)
  573. {
  574. char CMD[128];
  575. uint32_t callID = 0;
  576. sprintf(CMD, "mmcli -m %d --voice-create-call='number=%s'", DATA->modem_id, DATA->target);
  577. /*
  578. Successfully created new call: /org/freedesktop/ModemManager1/Call/2
  579. */
  580. SLOG(CMD);
  581. FILE * fd = popen(CMD, "r");
  582. if (fd)
  583. {
  584. char tB[1024];
  585. if (fread(tB, 1, 1023, fd) > 0)
  586. {
  587. CSTR tS = strstr(tB, "Call/");
  588. if (tS)
  589. {
  590. callID = atoi(tS + 5);
  591. };
  592. };
  593. pclose(fd);
  594. }
  595. else
  596. {
  597. SLOG("Cannot Start POPEN 1!");
  598. };
  599. if (callID)
  600. {
  601. sprintf(CMD, "mmcli -m %d --call %d --start", DATA->modem_id, callID);
  602. SLOG(CMD);
  603. system(CMD);
  604. // Wait X seconds then hang call or play voice message
  605. uint8_t bTO = 60; // 15 seconds
  606. bool call_is_answered = false;
  607. bool call_is_terminated = false;
  608. sprintf(CMD, "mmcli -m %d --voice-list-calls", DATA->modem_id);
  609. while (bTO && ! call_is_answered && ! call_is_terminated)
  610. {
  611. fd = popen(CMD, "r");
  612. if (fd)
  613. {
  614. char tB[1024];
  615. if (fread(tB, 1, 1023, fd) > 0)
  616. {
  617. CSTR tS = strstr(tB, "(active)");
  618. if (tS)
  619. {
  620. call_is_answered = true;
  621. };
  622. tS = strstr(tB, "(terminated)");
  623. if (tS)
  624. {
  625. call_is_terminated = true;
  626. };
  627. };
  628. pclose(fd);
  629. }
  630. else
  631. {
  632. SLOG("Cannot Start POPEN 2!");
  633. }
  634. SLEEP(250);
  635. bTO--;
  636. };
  637. if (bTO && ! call_is_terminated)
  638. {
  639. if (DATA->parent->m_sMMData.voice_sink[0])
  640. {
  641. // Play Wave
  642. // u-law (8000 Hz, 8-bits per sample, mono, 64k)
  643. // play -t raw -r 8000 -c 1 -e u-law -
  644. // SLEEP(DATA->parent->m_sMMData.call_hangup_wait * 1000);
  645. // unlink("/tmp/argus_voice.wav");
  646. };
  647. };
  648. sprintf(CMD, "mmcli -m %d --call %d --hangup", DATA->modem_id, callID);
  649. SLOG(CMD);
  650. system(CMD);
  651. sprintf(CMD, "mmcli -m %d --voice-delete-call=%d", DATA->modem_id, callID);
  652. SLOG(CMD);
  653. system(CMD);
  654. }
  655. else
  656. {
  657. SLOG("Call is not registered at Modem!");
  658. }
  659. };
  660. pthread_exit(NULL);
  661. return NULL;
  662. }
  663. void * kernelModuleModemManager::smsProc(void * ptr)
  664. {
  665. MDM_SMS_DATA * DATA = (MDM_SMS_DATA *) ptr;
  666. if (DATA)
  667. {
  668. char CMD[128];
  669. uint32_t smsID = 0;
  670. sprintf(CMD, "mmcli -m %d --messaging-create-sms=\"text='%s',number='%s'\"", DATA->modem_id, DATA->text, DATA->target);
  671. FILE * fd = popen(CMD, "r");
  672. if (fd)
  673. {
  674. char tB[1024];
  675. if (fread(tB, 1, 1023, fd) > 0)
  676. {
  677. CSTR tS = strstr(tB, "SMS/");
  678. if (tS)
  679. {
  680. smsID = atoi(tS + 4);
  681. };
  682. };
  683. pclose(fd);
  684. };
  685. if (smsID)
  686. {
  687. // Wait X seconds then hang call
  688. // SLEEP( DATA->parent->m_sMMData.call_hangup_wait * 1000 );
  689. sprintf(CMD, "mmcli -s %d --send", smsID);
  690. fd = popen(CMD, "r");
  691. if (fd)
  692. {
  693. pclose(fd);
  694. }
  695. else
  696. {
  697. TLOG_ERROR("Cannot Execute Call Hang Command!");
  698. };
  699. }
  700. else
  701. {
  702. TLOG_ERROR("Call is not registered at Modem!");
  703. }
  704. };
  705. pthread_exit(NULL);
  706. return NULL;
  707. }
  708. uint32_t kernelModuleModemManager::startCall(CSTR number)
  709. {
  710. MDM_CALL_DATA * DATA = (MDM_CALL_DATA *) malloc(sizeof(MDM_CALL_DATA));
  711. if (DATA)
  712. {
  713. LOG(number);
  714. memset(DATA, 0, sizeof(MDM_CALL_DATA));
  715. DATA->modem_id = m_sMMData.modem_id;
  716. DATA->parent = this;
  717. strncpy(DATA->target, number, 64);
  718. int RetVal = pthread_create(&DATA->handler, NULL, callProc, (void *) DATA);
  719. if (RetVal == -1)
  720. {
  721. LOG_ERROR("Cannot start Call Procedure.");
  722. free(DATA);
  723. return 0;
  724. };
  725. // Push Data into vector
  726. m_vUserData.push_back((MDM_USER_DATA *) DATA);
  727. }
  728. else
  729. {
  730. LOG_ERROR("Cannot allocate Call data.");
  731. };
  732. return 0;
  733. }
  734. void kernelModuleModemManager::sendSMS(CSTR number, CSTR text) {
  735. if ( number || text ) LOG("SMSM");
  736. //todo: Make code
  737. }
  738. void kernelModuleModemManager::hangupCall(uint32_t call_id) {
  739. if ( call_id ) call_id = 0;
  740. //todo: Make code
  741. }
  742. bool kernelModuleModemManager::updateWanIP()
  743. {
  744. char CMD[128];
  745. //uint32_t smsID = 0;
  746. bool bDone = false;
  747. sprintf(CMD, "ifconfig");
  748. FILE * fd = popen(CMD, "r");
  749. if (fd)
  750. {
  751. CSTR tB = NULL;
  752. size_t bSize = 0;
  753. bool bIfMeet = false;
  754. while (! feof(fd))
  755. {
  756. ssize_t rv = getline(&tB, &bSize, fd);
  757. if (rv)
  758. {
  759. if (! bDone)
  760. {
  761. if (bIfMeet)
  762. {
  763. CSTR ssp = strstr(tB, "inet ");
  764. if (ssp)
  765. {
  766. CSTR nsp = strstr(tB, "netmask");
  767. int msl = nsp - ssp - 7;
  768. strncpy(m_cMyWanIP, ssp + 5, msl);
  769. m_cMyWanIP[msl] = (char) 0;
  770. bDone = true;
  771. };
  772. }
  773. else
  774. {
  775. if (strstr(tB, "wwan"))
  776. {
  777. bIfMeet = true;
  778. }
  779. if (strstr(tB, "wwx"))
  780. {
  781. bIfMeet = true;
  782. }
  783. };
  784. };
  785. };
  786. if (tB)
  787. {
  788. free(tB);
  789. tB = NULL;
  790. };
  791. };
  792. pclose(fd);
  793. };
  794. #ifdef DEBUG_EXTRA
  795. if (bDone)
  796. {
  797. sprintf(CMD, "WAN IP4: %s", m_cMyWanIP);
  798. LOG(CMD);
  799. }
  800. else
  801. {
  802. LOG_ERROR("Cannot Find WAN IP4 Address!");
  803. };
  804. #endif
  805. return bDone;
  806. }
  807. #undef SLOG
  808. #undef LOG
  809. #undef LOG_ERROR