t38_core_tests.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. * SpanDSP - a series of DSP components for telephony
  3. *
  4. * t38_core_tests.c - Tests for the T.38 FoIP core module.
  5. *
  6. * Written by Steve Underwood <steveu@coppice.org>
  7. *
  8. * Copyright (C) 2007 Steve Underwood
  9. *
  10. * All rights reserved.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2, as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*! \file */
  26. /*! \page t38_core_tests_page T.38 core tests
  27. \section t38_core_tests_page_sec_1 What does it do?
  28. These tests exercise the T.38 core ASN.1 processing code.
  29. */
  30. #if defined(HAVE_CONFIG_H)
  31. #include "config.h"
  32. #endif
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35. #include <fcntl.h>
  36. #include <string.h>
  37. #include <assert.h>
  38. #include <errno.h>
  39. #if !defined(WIN32)
  40. #include <unistd.h>
  41. #endif
  42. #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
  43. #include "spandsp.h"
  44. #define MAX_FIELDS 42
  45. #define MAX_FIELD_LEN 8192
  46. static bool succeeded = true;
  47. static int t38_version;
  48. static int ok_indicator_packets;
  49. static int bad_indicator_packets;
  50. static int ok_data_packets;
  51. static int bad_data_packets;
  52. static int missing_packets;
  53. static int skip;
  54. static uint8_t field_body[MAX_FIELDS][MAX_FIELD_LEN];
  55. static int field_len[MAX_FIELDS];
  56. static int seq_no;
  57. static int msg_list[1000000];
  58. static int msg_list_ptr;
  59. static int msg_list_ptr2;
  60. static uint8_t concat[1000000];
  61. static int concat_len;
  62. static int rx_missing_attack_handler(t38_core_state_t *s, void *user_data, int rx_seq_no, int expected_seq_no)
  63. {
  64. //printf("Hit missing\n");
  65. return 0;
  66. }
  67. /*- End of function --------------------------------------------------------*/
  68. static int rx_indicator_attack_handler(t38_core_state_t *s, void *user_data, int indicator)
  69. {
  70. //printf("Hit indicator %d\n", indicator);
  71. return 0;
  72. }
  73. /*- End of function --------------------------------------------------------*/
  74. static int rx_data_attack_handler(t38_core_state_t *s, void *user_data, int data_type, int field_type, const uint8_t *buf, int len)
  75. {
  76. //printf("Hit data %d, field %d\n", data_type, field_type);
  77. return 0;
  78. }
  79. /*- End of function --------------------------------------------------------*/
  80. static int rx_missing_handler(t38_core_state_t *s, void *user_data, int rx_seq_no, int expected_seq_no)
  81. {
  82. missing_packets++;
  83. //printf("Hit missing\n");
  84. return 0;
  85. }
  86. /*- End of function --------------------------------------------------------*/
  87. static int rx_indicator_handler(t38_core_state_t *s, void *user_data, int indicator)
  88. {
  89. if (indicator == msg_list[msg_list_ptr2++])
  90. ok_indicator_packets++;
  91. else
  92. bad_indicator_packets++;
  93. //printf("Hit indicator %d\n", indicator);
  94. return 0;
  95. }
  96. /*- End of function --------------------------------------------------------*/
  97. static int rx_data_handler(t38_core_state_t *s, void *user_data, int data_type, int field_type, const uint8_t *buf, int len)
  98. {
  99. if (data_type == msg_list[msg_list_ptr2] && field_type == msg_list[msg_list_ptr2 + 1])
  100. ok_data_packets++;
  101. else
  102. bad_data_packets++;
  103. msg_list_ptr2 += 2;
  104. //printf("Hit data %d, field %d\n", data_type, field_type);
  105. return 0;
  106. }
  107. /*- End of function --------------------------------------------------------*/
  108. static int tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
  109. {
  110. t38_core_state_t *t;
  111. t = (t38_core_state_t *) user_data;
  112. span_log(t38_core_get_logging_state(s), SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count);
  113. if (t38_core_rx_ifp_packet(t, buf, len, seq_no) < 0)
  114. succeeded = false;
  115. seq_no++;
  116. return 0;
  117. }
  118. /*- End of function --------------------------------------------------------*/
  119. static int tx_concat_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
  120. {
  121. span_log(t38_core_get_logging_state(s), SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count);
  122. memcpy(&concat[concat_len], buf, len);
  123. concat_len += len;
  124. seq_no++;
  125. return 0;
  126. }
  127. /*- End of function --------------------------------------------------------*/
  128. static int encode_decode_tests(t38_core_state_t *a, t38_core_state_t *b)
  129. {
  130. t38_data_field_t field[MAX_FIELDS];
  131. int i;
  132. int j;
  133. ok_indicator_packets = 0;
  134. bad_indicator_packets = 0;
  135. ok_data_packets = 0;
  136. bad_data_packets = 0;
  137. missing_packets = 0;
  138. msg_list_ptr = 0;
  139. msg_list_ptr2 = 0;
  140. /* Try all the indicator types */
  141. for (i = 0; i < 100; i++)
  142. {
  143. msg_list[msg_list_ptr++] = i;
  144. if (t38_core_send_indicator(a, i) < 0)
  145. {
  146. msg_list_ptr--;
  147. break;
  148. }
  149. }
  150. /* Try all the data types, as single field messages with no data */
  151. for (i = 0; i < 100; i++)
  152. {
  153. for (j = 0; j < 100; j++)
  154. {
  155. msg_list[msg_list_ptr++] = i;
  156. msg_list[msg_list_ptr++] = j;
  157. skip = 99;
  158. if (t38_core_send_data(a, i, j, (uint8_t *) "", 0, T38_PACKET_CATEGORY_CONTROL_DATA) < 0)
  159. {
  160. msg_list_ptr -= 2;
  161. break;
  162. }
  163. }
  164. if (j == 0)
  165. break;
  166. }
  167. /* Try all the data types and field types, as single field messages with data */
  168. for (i = 0; i < 100; i++)
  169. {
  170. for (j = 0; j < 100; j++)
  171. {
  172. msg_list[msg_list_ptr++] = i;
  173. msg_list[msg_list_ptr++] = j;
  174. skip = 99;
  175. if (t38_core_send_data(a, i, j, (uint8_t *) "ABCD", 4, T38_PACKET_CATEGORY_CONTROL_DATA) < 0)
  176. {
  177. msg_list_ptr -= 2;
  178. break;
  179. }
  180. }
  181. if (j == 0)
  182. break;
  183. }
  184. /* Try all the data types and field types, as multi-field messages, but with 0 fields */
  185. for (i = 0; i < 100; i++)
  186. {
  187. for (j = 0; j < 100; j++)
  188. {
  189. skip = 1;
  190. if (t38_core_send_data_multi_field(a, i, field, 0, T38_PACKET_CATEGORY_CONTROL_DATA) < 0)
  191. break;
  192. }
  193. if (j == 0)
  194. break;
  195. }
  196. /* Try all the data types and field types, as multi-field messages */
  197. for (i = 0; i < 100; i++)
  198. {
  199. for (j = 0; j < 100; j++)
  200. {
  201. msg_list[msg_list_ptr++] = i;
  202. msg_list[msg_list_ptr++] = j;
  203. msg_list[msg_list_ptr++] = i;
  204. msg_list[msg_list_ptr++] = T38_FIELD_T4_NON_ECM_SIG_END;
  205. skip = 1;
  206. field_len[0] = 444;
  207. field_len[1] = 333;
  208. field[0].field_type = j;
  209. field[0].field = field_body[0];
  210. field[0].field_len = field_len[0];
  211. field[1].field_type = T38_FIELD_T4_NON_ECM_SIG_END;
  212. field[1].field = field_body[1];
  213. field[1].field_len = field_len[1];
  214. if (t38_core_send_data_multi_field(a, i, field, 2, T38_PACKET_CATEGORY_CONTROL_DATA) < 0)
  215. {
  216. msg_list_ptr -= 4;
  217. break;
  218. }
  219. }
  220. if (j == 0)
  221. break;
  222. }
  223. printf("Indicator packets: OK = %d, bad = %d\n", ok_indicator_packets, bad_indicator_packets);
  224. printf("Data packets: OK = %d, bad = %d\n", ok_data_packets, bad_data_packets);
  225. printf("Missing packets = %d\n", missing_packets);
  226. if (t38_version == 0)
  227. {
  228. if (ok_indicator_packets != 16 || bad_indicator_packets != 0)
  229. {
  230. printf("Tests failed\n");
  231. return -1;
  232. }
  233. if (ok_data_packets != 288 || bad_data_packets != 0)
  234. {
  235. printf("Tests failed\n");
  236. return -1;
  237. }
  238. }
  239. else
  240. {
  241. if (ok_indicator_packets != 23 || bad_indicator_packets != 0)
  242. {
  243. printf("Tests failed\n");
  244. return -1;
  245. }
  246. if (ok_data_packets != 720 || bad_data_packets != 0)
  247. {
  248. printf("Tests failed\n");
  249. return -1;
  250. }
  251. }
  252. if (missing_packets > 0)
  253. {
  254. printf("Tests failed\n");
  255. return -1;
  256. }
  257. return 0;
  258. }
  259. /*- End of function --------------------------------------------------------*/
  260. static int encode_then_decode_tests(t38_core_state_t *a, t38_core_state_t *b)
  261. {
  262. t38_data_field_t field[MAX_FIELDS];
  263. int len;
  264. int i;
  265. int j;
  266. ok_indicator_packets = 0;
  267. bad_indicator_packets = 0;
  268. ok_data_packets = 0;
  269. bad_data_packets = 0;
  270. missing_packets = 0;
  271. msg_list_ptr = 0;
  272. msg_list_ptr2 = 0;
  273. /* Try all the indicator types */
  274. for (i = 0; i < 100; i++)
  275. {
  276. msg_list[msg_list_ptr++] = i;
  277. if (t38_core_send_indicator(a, i) < 0)
  278. {
  279. msg_list_ptr--;
  280. break;
  281. }
  282. }
  283. /* Try all the data types, as single field messages with no data */
  284. for (i = 0; i < 100; i++)
  285. {
  286. for (j = 0; j < 100; j++)
  287. {
  288. msg_list[msg_list_ptr++] = i;
  289. msg_list[msg_list_ptr++] = j;
  290. skip = 99;
  291. if (t38_core_send_data(a, i, j, (uint8_t *) "", 0, T38_PACKET_CATEGORY_CONTROL_DATA) < 0)
  292. {
  293. msg_list_ptr -= 2;
  294. break;
  295. }
  296. }
  297. if (j == 0)
  298. break;
  299. }
  300. /* Try all the data types and field types, as single field messages with data */
  301. for (i = 0; i < 100; i++)
  302. {
  303. for (j = 0; j < 100; j++)
  304. {
  305. msg_list[msg_list_ptr++] = i;
  306. msg_list[msg_list_ptr++] = j;
  307. skip = 99;
  308. if (t38_core_send_data(a, i, j, (uint8_t *) "ABCD", 4, T38_PACKET_CATEGORY_CONTROL_DATA) < 0)
  309. {
  310. msg_list_ptr -= 2;
  311. break;
  312. }
  313. }
  314. if (j == 0)
  315. break;
  316. }
  317. /* Try all the data types and field types, as multi-field messages, but with 0 fields */
  318. for (i = 0; i < 100; i++)
  319. {
  320. for (j = 0; j < 100; j++)
  321. {
  322. skip = 1;
  323. if (t38_core_send_data_multi_field(a, i, field, 0, T38_PACKET_CATEGORY_CONTROL_DATA) < 0)
  324. break;
  325. }
  326. if (j == 0)
  327. break;
  328. }
  329. /* Try all the data types and field types, as multi-field messages */
  330. for (i = 0; i < 100; i++)
  331. {
  332. for (j = 0; j < 100; j++)
  333. {
  334. msg_list[msg_list_ptr++] = i;
  335. msg_list[msg_list_ptr++] = j;
  336. msg_list[msg_list_ptr++] = i;
  337. msg_list[msg_list_ptr++] = T38_FIELD_T4_NON_ECM_SIG_END;
  338. skip = 1;
  339. field_len[0] = 444;
  340. field_len[1] = 333;
  341. field[0].field_type = j;
  342. field[0].field = field_body[0];
  343. field[0].field_len = field_len[0];
  344. field[1].field_type = T38_FIELD_T4_NON_ECM_SIG_END;
  345. field[1].field = field_body[1];
  346. field[1].field_len = field_len[1];
  347. if (t38_core_send_data_multi_field(a, i, field, 2, T38_PACKET_CATEGORY_CONTROL_DATA) < 0)
  348. {
  349. msg_list_ptr -= 4;
  350. break;
  351. }
  352. }
  353. if (j == 0)
  354. break;
  355. }
  356. /* Now split up the big concatented block of IFP packets. */
  357. for (i = 0, seq_no = 0; i < concat_len; i += len)
  358. {
  359. if ((len = t38_core_rx_ifp_stream(b, &concat[i], concat_len - i, seq_no)) < 0)
  360. succeeded = false;
  361. seq_no++;
  362. }
  363. printf("Indicator packets: OK = %d, bad = %d\n", ok_indicator_packets, bad_indicator_packets);
  364. printf("Data packets: OK = %d, bad = %d\n", ok_data_packets, bad_data_packets);
  365. printf("Missing packets = %d\n", missing_packets);
  366. if (t38_version == 0)
  367. {
  368. if (ok_indicator_packets != 16 || bad_indicator_packets != 0)
  369. {
  370. printf("Tests failed\n");
  371. return -1;
  372. }
  373. if (ok_data_packets != 288 || bad_data_packets != 0)
  374. {
  375. printf("Tests failed\n");
  376. return -1;
  377. }
  378. }
  379. else
  380. {
  381. if (ok_indicator_packets != 23 || bad_indicator_packets != 0)
  382. {
  383. printf("Tests failed\n");
  384. return -1;
  385. }
  386. if (ok_data_packets != 720 || bad_data_packets != 0)
  387. {
  388. printf("Tests failed\n");
  389. return -1;
  390. }
  391. }
  392. if (missing_packets > 0)
  393. {
  394. printf("Tests failed\n");
  395. return -1;
  396. }
  397. return 0;
  398. }
  399. /*- End of function --------------------------------------------------------*/
  400. static int attack_tests(t38_core_state_t *s, int packets)
  401. {
  402. int i;
  403. int j;
  404. int len;
  405. uint8_t buf[1024];
  406. int seq_no;
  407. srand(1234567);
  408. /* Send lots of random junk, of increasing length. Much of this will decode
  409. as valid IFP frames, but none of it should cause trouble. */
  410. seq_no = 0;
  411. for (len = 1; len < 70; len++)
  412. {
  413. for (i = 0; i < packets; i++)
  414. {
  415. for (j = 0; j < len; j++)
  416. buf[j] = (rand() >> 16) & 0xFF;
  417. t38_core_rx_ifp_packet(s, buf, len, seq_no);
  418. seq_no = (seq_no + 1) & 0xFFFF;
  419. }
  420. }
  421. return 0;
  422. }
  423. /*- End of function --------------------------------------------------------*/
  424. int main(int argc, char *argv[])
  425. {
  426. t38_core_state_t t38_core_ax;
  427. t38_core_state_t t38_core_bx;
  428. t38_core_state_t *t38_core_a;
  429. t38_core_state_t *t38_core_b;
  430. int attack_packets;
  431. int opt;
  432. attack_packets = 100000;
  433. while ((opt = getopt(argc, argv, "a:")) != -1)
  434. {
  435. switch (opt)
  436. {
  437. case 'a':
  438. attack_packets = atoi(optarg);
  439. break;
  440. default:
  441. //usage();
  442. exit(2);
  443. break;
  444. }
  445. }
  446. /* Tests in UDP type mode, for UDPTL and RTP */
  447. for (t38_version = 0; t38_version < 2; t38_version++)
  448. {
  449. seq_no = 0;
  450. printf("Using T.38 version %d\n", t38_version);
  451. if ((t38_core_a = t38_core_init(&t38_core_ax,
  452. rx_indicator_handler,
  453. rx_data_handler,
  454. rx_missing_handler,
  455. &t38_core_bx,
  456. tx_packet_handler,
  457. &t38_core_bx)) == NULL)
  458. {
  459. fprintf(stderr, "Cannot start the T.38 core\n");
  460. exit(2);
  461. }
  462. if ((t38_core_b = t38_core_init(&t38_core_bx,
  463. rx_indicator_handler,
  464. rx_data_handler,
  465. rx_missing_handler,
  466. &t38_core_ax,
  467. tx_packet_handler,
  468. &t38_core_ax)) == NULL)
  469. {
  470. fprintf(stderr, "Cannot start the T.38 core\n");
  471. exit(2);
  472. }
  473. t38_set_t38_version(t38_core_a, t38_version);
  474. t38_set_t38_version(t38_core_b, t38_version);
  475. span_log_set_level(t38_core_get_logging_state(t38_core_a), SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG);
  476. span_log_set_tag(t38_core_get_logging_state(t38_core_a), "T.38-A");
  477. span_log_set_level(t38_core_get_logging_state(t38_core_b), SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG);
  478. span_log_set_tag(t38_core_get_logging_state(t38_core_b), "T.38-B");
  479. /* Encode and decode all possible frame types, one by one */
  480. if (encode_decode_tests(t38_core_a, t38_core_b))
  481. {
  482. printf("Encode/decode tests failed\n");
  483. exit(2);
  484. }
  485. if ((t38_core_a = t38_core_init(&t38_core_ax,
  486. rx_indicator_attack_handler,
  487. rx_data_attack_handler,
  488. rx_missing_attack_handler,
  489. &t38_core_bx,
  490. tx_packet_handler,
  491. &t38_core_bx)) == NULL)
  492. {
  493. fprintf(stderr, "Cannot start the T.38 core\n");
  494. exit(2);
  495. }
  496. t38_set_t38_version(t38_core_a, t38_version);
  497. //span_log_set_level(t38_core_get_logging_state(t38_core_a), SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG);
  498. //span_log_set_tag(t38_core_get_logging_state(t38_core_a), "T.38-A");
  499. if (attack_tests(t38_core_a, attack_packets))
  500. {
  501. printf("Attack tests failed\n");
  502. exit(2);
  503. }
  504. }
  505. /* Tests in TCP without TPKT mode, like T.38 version 0 */
  506. for (t38_version = 0; t38_version < 2; t38_version++)
  507. {
  508. seq_no = 0;
  509. concat_len = 0;
  510. printf("Using T.38 version %d\n", t38_version);
  511. if ((t38_core_a = t38_core_init(&t38_core_ax,
  512. rx_indicator_handler,
  513. rx_data_handler,
  514. rx_missing_handler,
  515. &t38_core_bx,
  516. tx_concat_packet_handler,
  517. &t38_core_bx)) == NULL)
  518. {
  519. fprintf(stderr, "Cannot start the T.38 core\n");
  520. exit(2);
  521. }
  522. if ((t38_core_b = t38_core_init(&t38_core_bx,
  523. rx_indicator_handler,
  524. rx_data_handler,
  525. rx_missing_handler,
  526. &t38_core_ax,
  527. tx_concat_packet_handler,
  528. &t38_core_ax)) == NULL)
  529. {
  530. fprintf(stderr, "Cannot start the T.38 core\n");
  531. exit(2);
  532. }
  533. t38_set_t38_version(t38_core_a, t38_version);
  534. t38_set_t38_version(t38_core_b, t38_version);
  535. t38_set_pace_transmission(t38_core_a, false);
  536. t38_set_pace_transmission(t38_core_b, false);
  537. t38_set_data_transport_protocol(t38_core_a, T38_TRANSPORT_TCP);
  538. t38_set_data_transport_protocol(t38_core_b, T38_TRANSPORT_TCP);
  539. span_log_set_level(t38_core_get_logging_state(t38_core_a), SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG);
  540. span_log_set_tag(t38_core_get_logging_state(t38_core_a), "T.38-A");
  541. span_log_set_level(t38_core_get_logging_state(t38_core_b), SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG);
  542. span_log_set_tag(t38_core_get_logging_state(t38_core_b), "T.38-B");
  543. /* Encode all possible frames types into a large block, and then decode them */
  544. if (encode_then_decode_tests(t38_core_a, t38_core_b))
  545. {
  546. printf("Encode then decode tests failed\n");
  547. exit(2);
  548. }
  549. if ((t38_core_a = t38_core_init(&t38_core_ax,
  550. rx_indicator_attack_handler,
  551. rx_data_attack_handler,
  552. rx_missing_attack_handler,
  553. &t38_core_bx,
  554. tx_packet_handler,
  555. &t38_core_bx)) == NULL)
  556. {
  557. fprintf(stderr, "Cannot start the T.38 core\n");
  558. exit(2);
  559. }
  560. t38_set_t38_version(t38_core_a, t38_version);
  561. t38_set_pace_transmission(t38_core_a, false);
  562. t38_set_data_transport_protocol(t38_core_a, T38_TRANSPORT_TCP);
  563. //span_log_set_level(t38_core_get_logging_state(t38_core_a), SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG);
  564. //span_log_set_tag(t38_core_get_logging_state(t38_core_a), "T.38-A");
  565. if (attack_tests(t38_core_a, attack_packets))
  566. {
  567. printf("Attack tests failed\n");
  568. exit(2);
  569. }
  570. }
  571. /* Tests in TCP with TPKT mode, like T.38 versions >0 */
  572. for (t38_version = 0; t38_version < 2; t38_version++)
  573. {
  574. seq_no = 0;
  575. concat_len = 0;
  576. printf("Using T.38 version %d\n", t38_version);
  577. if ((t38_core_a = t38_core_init(&t38_core_ax,
  578. rx_indicator_handler,
  579. rx_data_handler,
  580. rx_missing_handler,
  581. &t38_core_bx,
  582. tx_concat_packet_handler,
  583. &t38_core_bx)) == NULL)
  584. {
  585. fprintf(stderr, "Cannot start the T.38 core\n");
  586. exit(2);
  587. }
  588. if ((t38_core_b = t38_core_init(&t38_core_bx,
  589. rx_indicator_handler,
  590. rx_data_handler,
  591. rx_missing_handler,
  592. &t38_core_ax,
  593. tx_concat_packet_handler,
  594. &t38_core_ax)) == NULL)
  595. {
  596. fprintf(stderr, "Cannot start the T.38 core\n");
  597. exit(2);
  598. }
  599. t38_set_t38_version(t38_core_a, t38_version);
  600. t38_set_t38_version(t38_core_b, t38_version);
  601. t38_set_pace_transmission(t38_core_a, false);
  602. t38_set_pace_transmission(t38_core_b, false);
  603. t38_set_data_transport_protocol(t38_core_a, T38_TRANSPORT_TCP_TPKT);
  604. t38_set_data_transport_protocol(t38_core_b, T38_TRANSPORT_TCP_TPKT);
  605. span_log_set_level(t38_core_get_logging_state(t38_core_a), SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG);
  606. span_log_set_tag(t38_core_get_logging_state(t38_core_a), "T.38-A");
  607. span_log_set_level(t38_core_get_logging_state(t38_core_b), SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG);
  608. span_log_set_tag(t38_core_get_logging_state(t38_core_b), "T.38-B");
  609. /* Encode all possible frames types into a large block, and then decode them */
  610. if (encode_then_decode_tests(t38_core_a, t38_core_b))
  611. {
  612. printf("Encode then decode tests failed\n");
  613. exit(2);
  614. }
  615. if ((t38_core_a = t38_core_init(&t38_core_ax,
  616. rx_indicator_attack_handler,
  617. rx_data_attack_handler,
  618. rx_missing_attack_handler,
  619. &t38_core_bx,
  620. tx_packet_handler,
  621. &t38_core_bx)) == NULL)
  622. {
  623. fprintf(stderr, "Cannot start the T.38 core\n");
  624. exit(2);
  625. }
  626. t38_set_t38_version(t38_core_a, t38_version);
  627. t38_set_pace_transmission(t38_core_a, false);
  628. t38_set_data_transport_protocol(t38_core_a, T38_TRANSPORT_TCP_TPKT);
  629. //span_log_set_level(t38_core_get_logging_state(t38_core_a), SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG);
  630. //span_log_set_tag(t38_core_get_logging_state(t38_core_a), "T.38-A");
  631. if (attack_tests(t38_core_a, attack_packets))
  632. {
  633. printf("Attack tests failed\n");
  634. exit(2);
  635. }
  636. }
  637. if (!succeeded)
  638. {
  639. printf("Tests failed\n");
  640. exit(2);
  641. }
  642. printf("Tests passed\n");
  643. return 0;
  644. }
  645. /*- End of function --------------------------------------------------------*/
  646. /*- End of file ------------------------------------------------------------*/