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.

233 lines
7.6 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
​
​
​
​
  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. if( checkCmdExists("mmcli") > 0 ){
  15. LOG("ModemManager Present!");
  16. } else {
  17. LOG_ERROR("No ModemManager installed in the System!");
  18. };
  19. };
  20. kernelModuleModemManager::~kernelModuleModemManager(){
  21. //if ( m_vUserData.size() ) {
  22. //for ( VECTOR_MDM_USER_DATA::iterator idx = m_vUserData.begin(); idx < m_vUserData.end(); idx++ ) {
  23. // if ( !(*idx)->finished ) pthread_join( (*idx)->handler, NULL);
  24. //};
  25. //};
  26. };
  27. bool kernelModuleModemManager::reloadSettings(){
  28. LOG("Reload");
  29. //Reload Phonebook
  30. return true;
  31. };
  32. bool kernelModuleModemManager::startService(){
  33. LOG("Start Service");
  34. //Load PhoneBook
  35. setWM( MDM_IDLE_WM );
  36. return moduleActive = init();
  37. };
  38. bool kernelModuleModemManager::stopService( bool force ){
  39. LOG("Stop Service");
  40. setWM( MDM_IDLE_WM );
  41. return moduleActive = !uninit();
  42. };
  43. void kernelModuleModemManager::m_fThreadProc( void ){
  44. uint32_t nCurrentPhoneBookId = 0;
  45. uint32_t nCurrentCallId = 0;
  46. uint64_t lNextWindowAction = 0;
  47. m_bThreadStatus == TH_WORKING;
  48. while ( m_bThreadStatus < TH_ENDED ) {
  49. uint8_t bCWM = getWM();
  50. switch ( bCWM ) {
  51. case MDM_IDLE_WM:{
  52. break;
  53. };
  54. case MDM_INIT_CALL_WM:{
  55. if ( nCurrentPhoneBookId < m_vPhoneBook.size() ) {
  56. DBC_MODEM_PHONEBOOK_RECORD *tRECORD = m_vPhoneBook.at( nCurrentPhoneBookId );
  57. if ( tRECORD ) {
  58. if( tRECORD->call_only ){
  59. LOG("Start Call");
  60. nCurrentCallId = startCall( tRECORD->number );
  61. lNextWindowAction = getMilliseconds() + m_sMMData.call_hangup_wait * 1000;
  62. // Need to wait till calling
  63. setWM( MDM_MODEM_IS_BUSY_WM );
  64. } else {
  65. LOG("Start SMS");
  66. nCurrentCallId = 0;
  67. sendSMS( tRECORD->number, tRECORD->custom_msg );
  68. //No need to wait SMS
  69. setWM( MDM_FETCH_NEXT_WM );
  70. };
  71. } else {
  72. LOG_ERROR("No Phone Book Record!");
  73. sessionStarted = false;
  74. setWM( MDM_IDLE_WM );
  75. };
  76. } else {
  77. LOG_ERROR("Phone Book is Empty!");
  78. sessionStarted = false;
  79. setWM( MDM_IDLE_WM );
  80. };
  81. break;
  82. };
  83. case MDM_MODEM_IS_BUSY_WM:{
  84. if ( lNextWindowAction < getMilliseconds() ){
  85. LOG("Hangup Call");
  86. hangupCall( nCurrentCallId );
  87. setWM( MDM_FETCH_NEXT_WM );
  88. };
  89. break;
  90. };
  91. case MDM_FETCH_NEXT_WM:{
  92. if ( nCurrentPhoneBookId < m_vPhoneBook.size() ) {
  93. nCurrentPhoneBookId++;
  94. setWM( MDM_INIT_CALL_WM );
  95. } else {
  96. nCurrentPhoneBookId = 0;
  97. lNextWindowAction = getMilliseconds() + m_sMMData.time_window;
  98. setWM( MDM_WAIT_WINDOW_WM );
  99. };
  100. break;
  101. };
  102. case MDM_WAIT_WINDOW_WM:{
  103. if ( lNextWindowAction < getMilliseconds() ){
  104. sessionStarted = false;
  105. setWM( MDM_IDLE_WM );
  106. };
  107. break;
  108. };
  109. };
  110. SLEEP(DEFAULT_THREAD_SLEEP_TIME);
  111. };
  112. };
  113. void kernelModuleModemManager::dispatchEvent(EVENT_CONTAINER *Evt){
  114. if ( moduleActive ) {
  115. if ( sessionStarted ) {
  116. // Seek just Close Session EVT
  117. if( Evt->m_eType == EVT_LRF_END_SESSION_TO || Evt->m_eType == EVT_LRF_END_SESSION_MA ){
  118. sessionStarted = false;
  119. };
  120. } else {
  121. // React on All Events.
  122. switch ( Evt->m_eType ) {
  123. case EVT_TARGET_1D:
  124. case EVT_TARGET_3D_WHITE:
  125. case EVT_TARGET_3D_BLACK:
  126. case EVT_TARGET_2D_WHITE:
  127. case EVT_TARGET_2D_BLACK:{
  128. sessionStarted = true;
  129. setWM( MDM_INIT_CALL_WM );
  130. break;
  131. };
  132. };
  133. };
  134. };
  135. };
  136. bool kernelModuleModemManager::validate(){
  137. if ( moduleActive ) {
  138. // Get current WAN IP Address
  139. //
  140. //LOG("Validate");
  141. };
  142. return true;
  143. };
  144. #define TLOG_ERROR( X ) DATA->parent->m_pLog->Log( "MOD_MODEM_T", DATA->parent, _LOG_ERROR, X )
  145. void *kernelModuleModemManager::callProc( void *ptr ){
  146. MDM_CALL_DATA *DATA = (MDM_CALL_DATA *)ptr;
  147. if ( DATA ) {
  148. char CMD[128];
  149. uint32_t callID = 0;
  150. sprintf( CMD, "mmcli -m %d --voice-create-call='number=%s'", DATA->modem_id, DATA->target );
  151. /*
  152. Successfully created new call: /org/freedesktop/ModemManager1/Call/2
  153. */
  154. FILE *fd = popen( CMD, "r");
  155. if ( fd ) {
  156. pclose( fd );
  157. };
  158. if ( callID ) {
  159. // Wait X seconds then hang call
  160. SLEEP( DATA->parent->m_sMMData.call_hangup_wait * 1000 );
  161. sprintf( CMD, "mmcli -m %d --close-call %d", DATA->modem_id, callID );
  162. fd = popen( CMD, "r");
  163. if ( fd ) {
  164. pclose( fd );
  165. } else {
  166. TLOG_ERROR("Cannot Execute Call Hang Command!");
  167. };
  168. } else TLOG_ERROR("Call is not registered at Modem!");
  169. };
  170. pthread_exit( NULL );
  171. return NULL;
  172. };
  173. void *kernelModuleModemManager::smsProc( void *ptr ){
  174. MDM_SMS_DATA *DATA = (MDM_SMS_DATA *)ptr;
  175. if ( DATA ) {
  176. };
  177. pthread_exit( NULL );
  178. return NULL;
  179. };
  180. uint32_t kernelModuleModemManager::startCall( CSTR number ){
  181. MDM_CALL_DATA *DATA = ( MDM_CALL_DATA *) malloc( sizeof( MDM_CALL_DATA ));
  182. if( DATA ) {
  183. memset( DATA, 0 , sizeof( MDM_CALL_DATA ));
  184. DATA->parent = this;
  185. //strncpy( DATA->target, m_sMMData.call_target, 64 );
  186. int RetVal = pthread_create( &DATA->handler, NULL, callProc, ( void * ) DATA );
  187. if( RetVal == -1 ) {
  188. LOG_ERROR("Cannot start Call Procedure.");
  189. free( DATA );
  190. return 0;
  191. };
  192. //Push Data into vector
  193. m_vUserData.push_back( (MDM_USER_DATA*) DATA );
  194. } else {
  195. LOG_ERROR("Cannot allocate Call data.");
  196. };
  197. return 0;
  198. };
  199. void kernelModuleModemManager::sendSMS( CSTR number, CSTR text ){
  200. };
  201. void kernelModuleModemManager::hangupCall( uint32_t call_id ){
  202. };
  203. #undef LOG
  204. #undef LOG_ERROR