PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/cmpt471/a2/wireshark/tap-gsm_astat.c

http://cwoodruf-sfu-cmpt.googlecode.com/
C | 353 lines | 260 code | 58 blank | 35 comment | 25 complexity | ddbf5f0e5ca86614ba745e69f7139b5b MD5 | raw file
  1. /* tap-gsm_astat.c
  2. *
  3. * Copyright 2003, Michael Lum <mlum [AT] telostech.com>
  4. * In association with Telos Technology Inc.
  5. *
  6. * $Id: tap-gsm_astat.c 34194 2010-09-23 06:08:19Z morriss $
  7. *
  8. * Wireshark - Network traffic analyzer
  9. * By Gerald Combs <gerald@wireshark.org>
  10. * Copyright 1998 Gerald Combs
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25. */
  26. /*
  27. * This TAP provides statistics for the GSM A Interface:
  28. */
  29. #ifdef HAVE_CONFIG_H
  30. # include "config.h"
  31. #endif
  32. #include <stdio.h>
  33. #ifdef HAVE_SYS_TYPES_H
  34. # include <sys/types.h>
  35. #endif
  36. #include <string.h>
  37. #include "epan/packet_info.h"
  38. #include "epan/value_string.h"
  39. #include <epan/tap.h>
  40. #include <epan/stat_cmd_args.h>
  41. #include <epan/dissectors/packet-bssap.h>
  42. #include <epan/dissectors/packet-gsm_a_common.h>
  43. typedef struct _gsm_a_stat_t {
  44. int bssmap_message_type[0xff];
  45. int dtap_mm_message_type[0xff];
  46. int dtap_rr_message_type[0xff];
  47. int dtap_cc_message_type[0xff];
  48. int dtap_gmm_message_type[0xff];
  49. int dtap_sms_message_type[0xff];
  50. int dtap_sm_message_type[0xff];
  51. int dtap_ss_message_type[0xff];
  52. int dtap_tp_message_type[0xff];
  53. int sacch_rr_message_type[0xff];
  54. } gsm_a_stat_t;
  55. static int
  56. gsm_a_stat_packet(
  57. void *tapdata,
  58. packet_info *pinfo _U_,
  59. epan_dissect_t *edt _U_,
  60. const void *data)
  61. {
  62. gsm_a_stat_t *stat_p = tapdata;
  63. const gsm_a_tap_rec_t *tap_p = data;
  64. switch (tap_p->pdu_type)
  65. {
  66. case BSSAP_PDU_TYPE_BSSMAP:
  67. stat_p->bssmap_message_type[tap_p->message_type]++;
  68. break;
  69. case BSSAP_PDU_TYPE_DTAP:
  70. switch (tap_p->protocol_disc)
  71. {
  72. case PD_CC:
  73. stat_p->dtap_cc_message_type[tap_p->message_type]++;
  74. break;
  75. case PD_MM:
  76. stat_p->dtap_mm_message_type[tap_p->message_type]++;
  77. break;
  78. case PD_RR:
  79. stat_p->dtap_rr_message_type[tap_p->message_type]++;
  80. break;
  81. case PD_GMM:
  82. stat_p->dtap_gmm_message_type[tap_p->message_type]++;
  83. break;
  84. case PD_SMS:
  85. stat_p->dtap_sms_message_type[tap_p->message_type]++;
  86. break;
  87. case PD_SM:
  88. stat_p->dtap_sm_message_type[tap_p->message_type]++;
  89. break;
  90. case PD_SS:
  91. stat_p->dtap_ss_message_type[tap_p->message_type]++;
  92. break;
  93. case PD_TP:
  94. stat_p->dtap_tp_message_type[tap_p->message_type]++;
  95. break;
  96. default:
  97. /*
  98. * unsupported PD
  99. */
  100. return(0);
  101. }
  102. break;
  103. case GSM_A_PDU_TYPE_SACCH:
  104. switch (tap_p->protocol_disc)
  105. {
  106. case 0:
  107. stat_p->sacch_rr_message_type[tap_p->message_type]++;
  108. break;
  109. default:
  110. /* unknown Short PD */
  111. break;
  112. }
  113. break;
  114. default:
  115. /*
  116. * unknown PDU type !!!
  117. */
  118. return(0);
  119. }
  120. return(1);
  121. }
  122. static void
  123. gsm_a_stat_draw(
  124. void *tapdata)
  125. {
  126. gsm_a_stat_t *stat_p = tapdata;
  127. guint8 i;
  128. printf("\n");
  129. printf("=========== GS=M A-i/f Statistics ============================\n");
  130. printf("BSSMAP\n");
  131. printf("Message (ID)Type Number\n");
  132. i = 0;
  133. while (gsm_a_bssmap_msg_strings[i].strptr)
  134. {
  135. if (stat_p->bssmap_message_type[gsm_a_bssmap_msg_strings[i].value] > 0)
  136. {
  137. printf("0x%02x %-50s%d\n",
  138. gsm_a_bssmap_msg_strings[i].value,
  139. gsm_a_bssmap_msg_strings[i].strptr,
  140. stat_p->bssmap_message_type[gsm_a_bssmap_msg_strings[i].value]);
  141. }
  142. i++;
  143. }
  144. printf("\nDTAP %s\n", gsm_a_pd_str[PD_MM]);
  145. printf("Message (ID)Type Number\n");
  146. i = 0;
  147. while (gsm_a_dtap_msg_mm_strings[i].strptr)
  148. {
  149. if (stat_p->dtap_mm_message_type[gsm_a_dtap_msg_mm_strings[i].value] > 0)
  150. {
  151. printf("0x%02x %-50s%d\n",
  152. gsm_a_dtap_msg_mm_strings[i].value,
  153. gsm_a_dtap_msg_mm_strings[i].strptr,
  154. stat_p->dtap_mm_message_type[gsm_a_dtap_msg_mm_strings[i].value]);
  155. }
  156. i++;
  157. }
  158. printf("\nDTAP %s\n", gsm_a_pd_str[PD_RR]);
  159. printf("Message (ID)Type Number\n");
  160. i = 0;
  161. while (gsm_a_dtap_msg_rr_strings[i].strptr)
  162. {
  163. if (stat_p->dtap_rr_message_type[gsm_a_dtap_msg_rr_strings[i].value] > 0)
  164. {
  165. printf("0x%02x %-50s%d\n",
  166. gsm_a_dtap_msg_rr_strings[i].value,
  167. gsm_a_dtap_msg_rr_strings[i].strptr,
  168. stat_p->dtap_rr_message_type[gsm_a_dtap_msg_rr_strings[i].value]);
  169. }
  170. i++;
  171. }
  172. printf("\nDTAP %s\n", gsm_a_pd_str[PD_CC]);
  173. printf("Message (ID)Type Number\n");
  174. i = 0;
  175. while (gsm_a_dtap_msg_cc_strings[i].strptr)
  176. {
  177. if (stat_p->dtap_cc_message_type[gsm_a_dtap_msg_cc_strings[i].value] > 0)
  178. {
  179. printf("0x%02x %-50s%d\n",
  180. gsm_a_dtap_msg_cc_strings[i].value,
  181. gsm_a_dtap_msg_cc_strings[i].strptr,
  182. stat_p->dtap_cc_message_type[gsm_a_dtap_msg_cc_strings[i].value]);
  183. }
  184. i++;
  185. }
  186. printf("\nDTAP %s\n", gsm_a_pd_str[PD_GMM]);
  187. printf("Message (ID)Type Number\n");
  188. i = 0;
  189. while (gsm_a_dtap_msg_gmm_strings[i].strptr)
  190. {
  191. if (stat_p->dtap_gmm_message_type[gsm_a_dtap_msg_gmm_strings[i].value] > 0)
  192. {
  193. printf("0x%02x %-50s%d\n",
  194. gsm_a_dtap_msg_gmm_strings[i].value,
  195. gsm_a_dtap_msg_gmm_strings[i].strptr,
  196. stat_p->dtap_gmm_message_type[gsm_a_dtap_msg_gmm_strings[i].value]);
  197. }
  198. i++;
  199. }
  200. printf("\nDTAP %s\n", gsm_a_pd_str[PD_SMS]);
  201. printf("Message (ID)Type Number\n");
  202. i = 0;
  203. while (gsm_a_dtap_msg_sms_strings[i].strptr)
  204. {
  205. if (stat_p->dtap_sms_message_type[gsm_a_dtap_msg_sms_strings[i].value] > 0)
  206. {
  207. printf("0x%02x %-50s%d\n",
  208. gsm_a_dtap_msg_sms_strings[i].value,
  209. gsm_a_dtap_msg_sms_strings[i].strptr,
  210. stat_p->dtap_sms_message_type[gsm_a_dtap_msg_sms_strings[i].value]);
  211. }
  212. i++;
  213. }
  214. printf("\nDTAP %s\n", gsm_a_pd_str[PD_SM]);
  215. printf("Message (ID)Type Number\n");
  216. i = 0;
  217. while (gsm_a_dtap_msg_sm_strings[i].strptr)
  218. {
  219. if (stat_p->dtap_sm_message_type[gsm_a_dtap_msg_sm_strings[i].value] > 0)
  220. {
  221. printf("0x%02x %-50s%d\n",
  222. gsm_a_dtap_msg_sm_strings[i].value,
  223. gsm_a_dtap_msg_sm_strings[i].strptr,
  224. stat_p->dtap_sm_message_type[gsm_a_dtap_msg_sm_strings[i].value]);
  225. }
  226. i++;
  227. }
  228. printf("\nDTAP %s\n", gsm_a_pd_str[PD_SS]);
  229. printf("Message (ID)Type Number\n");
  230. i = 0;
  231. while (gsm_a_dtap_msg_ss_strings[i].strptr)
  232. {
  233. if (stat_p->dtap_ss_message_type[gsm_a_dtap_msg_ss_strings[i].value] > 0)
  234. {
  235. printf("0x%02x %-50s%d\n",
  236. gsm_a_dtap_msg_ss_strings[i].value,
  237. gsm_a_dtap_msg_ss_strings[i].strptr,
  238. stat_p->dtap_ss_message_type[gsm_a_dtap_msg_ss_strings[i].value]);
  239. }
  240. i++;
  241. }
  242. printf("\nDTAP %s\n", gsm_a_pd_str[PD_TP]);
  243. printf("Message (ID)Type Number\n");
  244. i = 0;
  245. while (gsm_a_dtap_msg_tp_strings[i].strptr)
  246. {
  247. if (stat_p->dtap_tp_message_type[gsm_a_dtap_msg_tp_strings[i].value] > 0)
  248. {
  249. printf("0x%02x %-50s%d\n",
  250. gsm_a_dtap_msg_tp_strings[i].value,
  251. gsm_a_dtap_msg_tp_strings[i].strptr,
  252. stat_p->dtap_tp_message_type[gsm_a_dtap_msg_tp_strings[i].value]);
  253. }
  254. i++;
  255. }
  256. printf("\nSACCH Radio Resources Management messages\n");
  257. printf("Message (ID)Type Number\n");
  258. i = 0;
  259. while (gsm_a_sacch_msg_rr_strings[i].strptr)
  260. {
  261. if (stat_p->sacch_rr_message_type[gsm_a_sacch_msg_rr_strings[i].value] > 0)
  262. {
  263. printf("0x%02x %-50s%d\n",
  264. gsm_a_sacch_msg_rr_strings[i].value,
  265. gsm_a_sacch_msg_rr_strings[i].strptr,
  266. stat_p->sacch_rr_message_type[gsm_a_sacch_msg_rr_strings[i].value]);
  267. }
  268. i++;
  269. }
  270. printf("==============================================================\n");
  271. }
  272. static void
  273. gsm_a_stat_init(const char *optarg _U_,void* userdata _U_)
  274. {
  275. gsm_a_stat_t *stat_p;
  276. GString *err_p;
  277. stat_p = g_malloc(sizeof(gsm_a_stat_t));
  278. memset(stat_p, 0, sizeof(gsm_a_stat_t));
  279. err_p =
  280. register_tap_listener("gsm_a", stat_p, NULL, 0,
  281. NULL,
  282. gsm_a_stat_packet,
  283. gsm_a_stat_draw);
  284. if (err_p != NULL)
  285. {
  286. g_free(stat_p);
  287. g_string_free(err_p, TRUE);
  288. exit(1);
  289. }
  290. }
  291. void
  292. register_tap_listener_gsm_astat(void)
  293. {
  294. register_stat_cmd_arg("gsm_a,", gsm_a_stat_init,NULL);
  295. }