test_tpdu.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * Copyright (C) 2009 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. #ifndef _TEST_SMSTPDU_H
  23. #define _TEST_SMSTPDU_H
  24. #define USER_DATA "hellohello"
  25. static uint8_t __pdu_last_mr = 0;
  26. void test_submit()
  27. {
  28. int ret;
  29. tsms_tpdu_submit_t* submit = tsk_null;
  30. tsk_buffer_t* buffer = tsk_null;
  31. char* hex;
  32. const char* smsc = "+331000009";
  33. const char* destination = "+333361234567";
  34. const char* short_message = "hello world";
  35. uint8_t mr = 0xF5;
  36. submit = tsms_tpdu_submit_create(mr, smsc, destination);
  37. /* encode the user data to GSM 7-bit alphabet */
  38. if((buffer = tsms_pack_to_7bit(short_message))) {
  39. ret = tsms_tpdu_submit_set_userdata(submit, buffer, tsms_alpha_7bit);
  40. if((hex = tsms_tpdu_submit_tohexastring(submit))) {
  41. TSK_DEBUG_INFO("SMS-SUBMIT=%s", hex);
  42. TSK_FREE(hex);
  43. }
  44. TSK_OBJECT_SAFE_FREE(buffer);
  45. }
  46. /* receiving */
  47. buffer = tsk_buffer_create_null();
  48. ret = tsms_tpdu_submit_serialize(submit, buffer);
  49. // send(socket, buffer->data, buffer->size);
  50. TSK_OBJECT_SAFE_FREE(submit);
  51. submit = (tsms_tpdu_submit_t*)tsms_tpdu_message_deserialize_mo(buffer->data, buffer->size);
  52. if((hex = tsms_tpdu_submit_tohexastring(submit))) {
  53. TSK_DEBUG_INFO("SMS-SUBMIT=%s", hex);
  54. TSK_FREE(hex);
  55. }
  56. TSK_OBJECT_SAFE_FREE(submit);
  57. TSK_OBJECT_SAFE_FREE(buffer);
  58. printf("==========\n");
  59. }
  60. void test_deliver()
  61. {
  62. int ret;
  63. tsms_tpdu_deliver_t* deliver = tsk_null;
  64. tsk_buffer_t* buffer = tsk_null;
  65. char* hex;
  66. deliver = tsms_tpdu_deliver_create("+27381000015", "+46708251358");
  67. /* sending */
  68. if((buffer = tsms_pack_to_7bit(USER_DATA))) {
  69. ret = tsms_tpdu_deliver_set_userdata(deliver, buffer, tsms_alpha_7bit);
  70. if((hex = tsms_tpdu_deliver_tohexastring(deliver))) {
  71. TSK_DEBUG_INFO("SMS-DELIVER=%s", hex);
  72. TSK_FREE(hex);
  73. }
  74. TSK_OBJECT_SAFE_FREE(buffer);
  75. }
  76. /* receiving */
  77. buffer = tsk_buffer_create_null();
  78. tsms_tpdu_deliver_serialize(deliver, buffer);
  79. TSK_OBJECT_SAFE_FREE(deliver);
  80. //{
  81. // tsms_tpdu_message_t* sms_any = tsms_tpdu_message_deserialize_mt(buffer->data, buffer->size);
  82. // if(sms_any && sms_any->mti == tsms_tpdu_mti_deliver_mt){
  83. // //tsms_tpdu_deliver_t* sms_deliver = TSMS_TPDU_DELIVER(sms_any); ==> Yes we can !
  84. // char* ascii;
  85. // if((ascii = tsms_tpdu_message_get_payload(sms_any))){
  86. // TSK_DEBUG_INFO("Message=%s", ascii);
  87. // TSK_FREE(ascii);
  88. // }
  89. // }
  90. // TSK_OBJECT_SAFE_FREE(sms_any);
  91. //}
  92. deliver = (tsms_tpdu_deliver_t*)tsms_tpdu_message_deserialize_mt(buffer->data, buffer->size);
  93. if((hex = tsms_tpdu_deliver_tohexastring(deliver))) {
  94. TSK_DEBUG_INFO("SMS-DELIVER=%s", hex);
  95. TSK_FREE(hex);
  96. }
  97. TSK_OBJECT_SAFE_FREE(deliver);
  98. TSK_OBJECT_SAFE_FREE(buffer);
  99. printf("==========\n");
  100. }
  101. void test_report()
  102. {
  103. int ret;
  104. tsms_tpdu_report_t* report = tsk_null;
  105. tsk_buffer_t* buffer = tsk_null;
  106. char* hex;
  107. const char* smsc = "+331000009";
  108. tsk_bool_t isSUBMIT = tsk_false;
  109. tsk_bool_t isERROR = tsk_false;
  110. report = tsms_tpdu_report_create(smsc, isSUBMIT, isERROR);
  111. /* sending */
  112. if((buffer = tsms_pack_to_7bit(USER_DATA))) {
  113. ret = tsms_tpdu_deliver_set_userdata(report, buffer, tsms_alpha_7bit);
  114. if((hex = tsms_tpdu_deliver_tohexastring(report))) {
  115. TSK_DEBUG_INFO("SMS-DELIVER-REPORT for RP-ERROR=%s", hex);
  116. TSK_FREE(hex);
  117. }
  118. TSK_OBJECT_SAFE_FREE(buffer);
  119. }
  120. /* receiving */
  121. buffer = tsk_buffer_create_null();
  122. tsms_tpdu_report_serialize(report, buffer);
  123. TSK_OBJECT_SAFE_FREE(report);
  124. report = (tsms_tpdu_report_t*)tsms_tpdu_message_deserialize_mo(buffer->data, buffer->size);
  125. if((hex = tsms_tpdu_report_tohexastring(report))) {
  126. TSK_DEBUG_INFO("SMS-DELIVER-REPORT for RP-ERROR=%s", hex);
  127. TSK_FREE(hex);
  128. }
  129. TSK_OBJECT_SAFE_FREE(report);
  130. TSK_OBJECT_SAFE_FREE(buffer);
  131. printf("==========\n");
  132. }
  133. void test_command()
  134. {
  135. tsms_tpdu_command_t* command = tsk_null;
  136. char* hex;
  137. tsk_buffer_t* buffer = tsk_null;
  138. const char* smsc = "+331000009";
  139. const char* destination = "+333361234567";
  140. uint8_t mr = 0xF5;
  141. uint8_t message_number = 0xF8;
  142. command = tsms_tpdu_command_create(mr, smsc, destination, message_number, tsms_tpdu_cmd_delete);
  143. /*sending*/
  144. if((hex = tsms_tpdu_command_tohexastring(command))) {
  145. TSK_DEBUG_INFO("SMS-COMMAND=%s", hex);
  146. TSK_FREE(hex);
  147. }
  148. /* receiving */
  149. buffer = tsk_buffer_create_null();
  150. tsms_tpdu_command_serialize(command, buffer);
  151. TSK_OBJECT_SAFE_FREE(command);
  152. command = (tsms_tpdu_command_t*)tsms_tpdu_message_deserialize_mo(buffer->data, buffer->size);
  153. if((hex = tsms_tpdu_command_tohexastring(command))) {
  154. TSK_DEBUG_INFO("SMS-COMMAND=%s", hex);
  155. TSK_FREE(hex);
  156. }
  157. TSK_OBJECT_SAFE_FREE(command);
  158. TSK_OBJECT_SAFE_FREE(buffer);
  159. printf("==========\n");
  160. }
  161. void test_sreport()
  162. {
  163. tsms_tpdu_status_report_t* sreport = tsk_null;
  164. char* hex;
  165. tsk_buffer_t* buffer = tsk_null;
  166. sreport = tsms_tpdu_status_report_create(__pdu_last_mr++, "+3310000", "+332666", tsms_tpdu_status_busy, tsk_true);
  167. if((hex = tsms_tpdu_report_tohexastring(sreport))) {
  168. TSK_DEBUG_INFO("SMS-STATUS-REPORT=%s", hex);
  169. TSK_FREE(hex);
  170. }
  171. /* receiving */
  172. buffer = tsk_buffer_create_null();
  173. tsms_tpdu_status_report_serialize(sreport, buffer);
  174. //tsms_tpdu_message_t* sms_any = tsms_tpdu_message_deserialize_mt(buffer->data, buffer->size);
  175. //if(sms_any && sms_any->mti == tsms_tpdu_mti_status_report_mt){
  176. // tsms_tpdu_status_report_t* sms_status_report = TSMS_TPDU_STATUS_REPORT(sms_any);
  177. // switch(sms_status_report->st){
  178. // case tsms_tpdu_status_received:
  179. // case tsms_tpdu_status_forwarded:
  180. // case tsms_tpdu_status_replaced:
  181. // // ...
  182. // default:
  183. // break;
  184. // }
  185. //}
  186. //TSK_OBJECT_SAFE_FREE(sms_any);
  187. TSK_OBJECT_SAFE_FREE(sreport);
  188. sreport = (tsms_tpdu_status_report_t*)tsms_tpdu_message_deserialize_mt(buffer->data, buffer->size);
  189. if((hex = tsms_tpdu_status_report_tohexastring(sreport))) {
  190. TSK_DEBUG_INFO("SMS-STATUS-REPORT=%s", hex);
  191. TSK_FREE(hex);
  192. }
  193. TSK_OBJECT_SAFE_FREE(sreport);
  194. TSK_OBJECT_SAFE_FREE(buffer);
  195. printf("==========\n");
  196. }
  197. void test_tpdu()
  198. {
  199. test_submit();
  200. test_deliver();
  201. test_report();
  202. test_command();
  203. test_sreport();
  204. }
  205. #endif /* _TEST_SMSTPDU_H */