Untitled


SUBMITTED BY: Guest

DATE: Dec. 2, 2013, 12:07 p.m.

FORMAT: Text only

SIZE: 26.7 kB

HITS: 686

  1. /************************************************************************/
  2. /* SISCO SOFTWARE MODULE HEADER *****************************************/
  3. /************************************************************************/
  4. /* (c) Copyright Systems Integration Specialists Company, Inc., */
  5. /* 1999-2002, All Rights Reserved. */
  6. /* */
  7. /* PROPRIETARY AND CONFIDENTIAL */
  8. /* */
  9. /* MODULE NAME : goose.c */
  10. /* PRODUCT(S) : ASN1DE */
  11. /* */
  12. /* MODULE DESCRIPTION : */
  13. /* */
  14. /* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : */
  15. /* */
  16. /* MODIFICATION LOG : */
  17. /* Date Who Rev Comments */
  18. /* -------- --- ------ ------------------------------------------- */
  19. /* 12/12/03 JRB 09 u_a_unit_data_ind: memset GOOSE_INFO struct */
  20. /* to all 0 at start of decode. */
  21. /* 03/31/03 JRB 08 asn1r_get_bitstr: add max_bits arg. */
  22. /* 12/11/02 JRB 07 Del mvl_acse.h include. */
  23. /* 03/05/02 JRB 06 Del unused proto. Add braces when initializing*/
  24. /* ASN1R_TAG_CTRL_1 structs. */
  25. /* 01/10/02 JRB 05 No longer need bind_id. */
  26. /* Chg args to _goose_decode_mms. */
  27. /* Add gse_uca_decode */
  28. /* 07/25/00 RKR 04 Reconciled changes from BSD */
  29. /* 12/10/99 JRB 03 Fix mmsl_send_goose & _goose_tx_audt_apdu */
  30. /* to properly check return codes. */
  31. /* 09/10/99 JRB 02 Use asn1r_get_u32 for decoding of SqNum, */
  32. /* StNum, HoldTim, & BackTim (encode is OK). */
  33. /* 06/25/99 MDE 01 Created */
  34. /************************************************************************/
  35. #include "glbtypes.h"
  36. #include "sysincs.h"
  37. #include "asn1r.h"
  38. #include "clnp_usr.h"
  39. #include "clnp_sne.h"
  40. #include "clnp.h" /* for clnpl_decode */
  41. #include "goose.h"
  42. /* For loopback testing use this define */
  43. /* #define GOOSE_TEST */
  44. /************************************************************************/
  45. /************************************************************************/
  46. /* Static functions */
  47. static ST_RET _goose_tx_audt_apdu (GOOSE_INFO *gi, ST_UCHAR *goose_mms_pdu,
  48. ST_INT goose_mms_pdu_len);
  49. static ST_RET _goose_encode_mms (ST_UCHAR *asn1_buf, ST_INT asn1_buf_size,
  50. ST_UCHAR **goose_asn1_out, ST_INT *goose_asn1_len_out,
  51. GOOSE_INFO *gi);
  52. static ST_RET _goose_decode_mms (AUDT_APDU *audt_apdu, GOOSE_INFO *gi);
  53. static ST_VOID _goose_unconf_req (ASN1_DEC_CTXT *ac);
  54. static ST_VOID _goose_info_rpt (ASN1_DEC_CTXT *ac);
  55. static ST_VOID _goose_list_of_var (ASN1_DEC_CTXT *ac);
  56. static ST_VOID _goose_seq_of_varspec (ASN1_DEC_CTXT *ac);
  57. static ST_VOID _goose_named (ASN1_DEC_CTXT *ac);
  58. static ST_VOID _goose_vmd_spec (ASN1_DEC_CTXT *ac);
  59. static ST_VOID _goose_named_done (ASN1_DEC_CTXT *ac);
  60. static ST_VOID _goose_seq_of_varspec_done (ASN1_DEC_CTXT *ac);
  61. static ST_VOID _goose_list_of_var_done (ASN1_DEC_CTXT *ac);
  62. static ST_VOID _goose_list_acc_rslt (ASN1_DEC_CTXT *ac);
  63. static ST_VOID _goose_struct (ASN1_DEC_CTXT *ac);
  64. static ST_VOID _goose_get_app_id (ASN1_DEC_CTXT *ac);
  65. static ST_VOID _goose_get_sent_time (ASN1_DEC_CTXT *ac);
  66. static ST_VOID _goose_get_seqnum (ASN1_DEC_CTXT *ac);
  67. static ST_VOID _goose_get_sub_seq (ASN1_DEC_CTXT *ac);
  68. static ST_VOID _goose_get_hold_time (ASN1_DEC_CTXT *ac);
  69. static ST_VOID _goose_get_back_time (ASN1_DEC_CTXT *ac);
  70. static ST_VOID _goose_get_phsid (ASN1_DEC_CTXT *ac);
  71. static ST_VOID _goose_get_dnabits (ASN1_DEC_CTXT *ac);
  72. static ST_VOID _goose_get_usrbits (ASN1_DEC_CTXT *ac);
  73. static ST_VOID _goose_struct_done (ASN1_DEC_CTXT *ac);
  74. static ST_VOID _goose_list_acc_rslt_done (ASN1_DEC_CTXT *ac);
  75. static ST_VOID _goose_info_rpt_done (ASN1_DEC_CTXT *ac);
  76. static ST_VOID _goose_unconf_req_done (ASN1_DEC_CTXT *ac);
  77. static ST_VOID _goose_done_ok (ASN1_DEC_CTXT *ac);
  78. static ST_VOID _goose_done_error (ASN1_DEC_CTXT *ac);
  79. static ST_VOID _goose_error (ASN1_DEC_CTXT *ac, ST_RET err);
  80. /************************************************************************/
  81. /************************************************************************/
  82. /* mmsl_send_goose */
  83. /************************************************************************/
  84. ST_RET mmsl_send_goose (GOOSE_INFO *gi)
  85. {
  86. ST_UCHAR asn1_buf[GOOSE_MAX_PDU_SIZE];
  87. ST_UCHAR *goose_mms_pdu;
  88. ST_INT goose_mms_pdu_len;
  89. ST_RET rc;
  90. #ifdef GOOSE_TEST
  91. GOOSE_INFO goose_rx_info;
  92. #endif
  93. /* Encode the MMS PDU, given the user GOOSE information */
  94. rc = _goose_encode_mms (asn1_buf, GOOSE_MAX_PDU_SIZE,
  95. &goose_mms_pdu, &goose_mms_pdu_len, gi);
  96. /* Finish the a-unit data encoding and transmit the PDU */
  97. if (rc == SD_SUCCESS)
  98. rc = _goose_tx_audt_apdu (gi, goose_mms_pdu, goose_mms_pdu_len);
  99. #ifdef GOOSE_TEST
  100. /* For test, pretend we received it too! */
  101. memset(&goose_rx_info, 0, sizeof (GOOSE_INFO));
  102. memcpy(&goose_rx_info.audtApdu, &gi->audtApdu, sizeof (AUDT_APDU));
  103. rc = _goose_decode_mms (&gi->audtApdu, &goose_rx_info);
  104. if (rc != 0)
  105. printf ("\n Whooops!");
  106. rc = memcmp (gi, &goose_rx_info, sizeof (GOOSE_INFO));
  107. if (rc != 0)
  108. printf ("\n Whoa!");
  109. else
  110. u_mmsl_goose_received (&goose_rx_info);
  111. #endif
  112. return (rc);
  113. }
  114. /************************************************************************/
  115. /* _goose_encode_mms */
  116. /************************************************************************/
  117. static ST_RET _goose_encode_mms (ST_UCHAR *asn1_buf, ST_INT asn1_buf_size,
  118. ST_UCHAR **goose_mms_pdu_out, ST_INT *goose_mms_pdu_len_out,
  119. GOOSE_INFO *gi)
  120. {
  121. ASN1_ENC_CTXT ac;
  122. ST_UCHAR *pdu_start; /* 000725 BSD - Changed from ST_CHAR* to ST_UCHAR* */
  123. ST_INT pdu_len;
  124. asn1r_strt_asn1_bld (&ac, asn1_buf, asn1_buf_size);
  125. asn1r_strt_constr (&ac); /* unconfirmed requests */
  126. asn1r_strt_constr (&ac); /* information report body */
  127. asn1r_strt_constr (&ac); /* access result */
  128. asn1r_strt_constr (&ac); /* GOOSE data is a structure */
  129. asn1r_wr_bitstr (&ac, gi->UserSt, gi->num_usr_bits);
  130. asn1r_fin_prim (&ac, 4, CTX);
  131. asn1r_wr_bitstr (&ac, gi->DNA, gi->num_dna_bits);
  132. asn1r_fin_prim (&ac, 4, CTX);
  133. asn1r_wr_u16 (&ac, gi->PhsID);
  134. asn1r_fin_prim (&ac, 6, CTX);
  135. asn1r_wr_u32 (&ac, gi->BackTim);
  136. asn1r_fin_prim (&ac, 6, CTX);
  137. asn1r_wr_u32 (&ac, gi->HoldTim);
  138. asn1r_fin_prim (&ac, 6, CTX);
  139. asn1r_wr_u32 (&ac, gi->StNum);
  140. asn1r_fin_prim (&ac, 6, CTX);
  141. asn1r_wr_u32 (&ac, gi->SqNum);
  142. asn1r_fin_prim (&ac, 6, CTX);
  143. asn1r_wr_btod (&ac, &gi->t);
  144. asn1r_fin_prim (&ac, 12, CTX);
  145. asn1r_wr_vstr (&ac, gi->SendingIED);
  146. asn1r_fin_prim (&ac, 10, CTX);
  147. asn1r_fin_constr (&ac, 2, CTX, DEF); /* end of GOOSE data struct */
  148. asn1r_fin_constr (&ac, 0, CTX, DEF); /* access result being finished */
  149. asn1r_strt_constr (&ac);
  150. asn1r_strt_constr (&ac); /* variable access specification */
  151. asn1r_strt_constr (&ac); /* object name start */
  152. asn1r_wr_vstr (&ac, "GOOSE");
  153. asn1r_fin_prim (&ac, 0, CTX); /* VMD Specific Name */
  154. asn1r_fin_constr (&ac, 0, CTX, DEF);
  155. asn1r_fin_constr (&ac, SEQ_CODE, UNI, DEF);/* end variable access specification */
  156. asn1r_fin_constr (&ac, 0, CTX, DEF); /* end of information report body */
  157. asn1r_fin_constr (&ac, 0, CTX, DEF);
  158. asn1r_fin_constr (&ac, 3, CTX, DEF); /* end of unconfirmed service */
  159. if (ac.asn1r_encode_overrun) /* Check for encode overrun */
  160. return (SD_FAILURE);
  161. pdu_start = ac.asn1r_field_ptr + 1;
  162. pdu_len = (asn1_buf + asn1_buf_size) - pdu_start;
  163. *goose_mms_pdu_out = pdu_start;
  164. *goose_mms_pdu_len_out = pdu_len;
  165. return (SD_SUCCESS);
  166. }
  167. /************************************************************************/
  168. /* _goose_tx_audt_apdu */
  169. /************************************************************************/
  170. static ST_RET _goose_tx_audt_apdu (GOOSE_INFO *gi, ST_UCHAR *goose_mms_pdu,
  171. ST_INT goose_mms_pdu_len)
  172. {
  173. ST_RET ret;
  174. gi->audtApdu.user_info.ptr = goose_mms_pdu;
  175. gi->audtApdu.user_info.len = goose_mms_pdu_len;
  176. ret = a_unit_data_req (&gi->audtApdu);
  177. return (ret);
  178. }
  179. /************************************************************************/
  180. /************************************************************************/
  181. /* u_a_unit_data_ind */
  182. /* This "user" function processes the A-UNIT-DATA.ind. It is customized */
  183. /* to handle only GOOSE packets. It decodes the GOOSE packet, and then */
  184. /* passes the decoded info to the user by calling "u_mmsl_goose_received.*/
  185. /* If the packet is not a GOOSE, or it can't be decoded, it is ignored. */
  186. /************************************************************************/
  187. ST_VOID u_a_unit_data_ind (AUDT_APDU *audt_apdu)
  188. {
  189. ST_RET rc;
  190. GOOSE_INFO goose_info; /* for u_a_unit_data_ind */
  191. /* Start with clean structure. */
  192. memset (&goose_info, 0, sizeof (goose_info));
  193. /* Decode GOOSE PDU. */
  194. rc = _goose_decode_mms (audt_apdu, &goose_info);
  195. /* Tell the user about the received GOOSE message */
  196. if (rc == SD_SUCCESS)
  197. u_mmsl_goose_received (&goose_info);
  198. else
  199. {
  200. /* SLOGALWAYS0 ("A-UNIT-DATA.ind is not a GOOSE. Ignoring it."); */
  201. }
  202. }
  203. /************************************************************************/
  204. /* _goose_decode_mms */
  205. /************************************************************************/
  206. static ST_RET _goose_decode_mms (AUDT_APDU *audt_apdu, GOOSE_INFO *gi)
  207. {
  208. ASN1_DEC_CTXT asn1_ctxt;
  209. ASN1_DEC_CTXT *ac;
  210. static ASN1R_TAG_CTRL_1 asn1r_tags =
  211. {1, {{ASN1R_TAG_VAL (CTX | CONSTR, 3), _goose_unconf_req}}};
  212. /* Copy AUDT struct to goose_info so user can access all addressing info.*/
  213. memcpy (&gi->audtApdu, audt_apdu, sizeof (AUDT_APDU));
  214. ac = &asn1_ctxt;
  215. memset (ac, 0, sizeof (ASN1_DEC_CTXT));
  216. ac->usr_info[0] = gi;
  217. ac->asn1r_err_fun = _goose_error;
  218. ac->asn1r_decode_done_fun = _goose_done_error;
  219. ac->asn1r_decode_method = ASN1_TABLE_METHOD;
  220. ac->asn1r_tag_table = &asn1r_tags;
  221. asn1r_decode_asn1 (ac, audt_apdu->user_info.ptr, audt_apdu->user_info.len);
  222. if (ac->asn1r_pdu_dec_err != NO_DECODE_ERR)
  223. return (SD_FAILURE);
  224. return (SD_SUCCESS);
  225. }
  226. /************************************************************************/
  227. /* _goose_unconf_req */
  228. /************************************************************************/
  229. static ST_VOID _goose_unconf_req (ASN1_DEC_CTXT *ac)
  230. {
  231. static ASN1R_TAG_CTRL_1 asn1r_tags =
  232. {1, {{ASN1R_TAG_VAL(CTX | CONSTR, 0), _goose_info_rpt}}};
  233. ac->asn1r_tag_table = &asn1r_tags;
  234. }
  235. /************************************************************************/
  236. /* _goose_info_rpt */
  237. /************************************************************************/
  238. static ST_VOID _goose_info_rpt (ASN1_DEC_CTXT *ac)
  239. {
  240. static ASN1R_TAG_CTRL_1 asn1r_tags =
  241. {1, {{ASN1R_TAG_VAL (CTX | CONSTR, 0), _goose_list_of_var}}};
  242. ac->asn1r_tag_table = &asn1r_tags;
  243. }
  244. /************************************************************************/
  245. /* _goose_list_of_var */
  246. /************************************************************************/
  247. static ST_VOID _goose_list_of_var (ASN1_DEC_CTXT *ac)
  248. {
  249. static ASN1R_TAG_CTRL_1 asn1r_tags =
  250. {1, {{ASN1R_TAG_VAL (UNI | CONSTR, SEQ_CODE), _goose_seq_of_varspec}}};
  251. ac->asn1r_tag_table = &asn1r_tags;
  252. }
  253. /************************************************************************/
  254. /* _goose_seq_of_varspec */
  255. /************************************************************************/
  256. static ST_VOID _goose_seq_of_varspec (ASN1_DEC_CTXT *ac)
  257. {
  258. static ASN1R_TAG_CTRL_1 asn1r_tags =
  259. {1, {{ASN1R_TAG_VAL (CTX | CONSTR, 0), _goose_named}}};
  260. ac->asn1r_tag_table = &asn1r_tags;
  261. }
  262. /************************************************************************/
  263. /* _goose_named */
  264. /************************************************************************/
  265. static ST_VOID _goose_named (ASN1_DEC_CTXT *ac)
  266. {
  267. static ASN1R_TAG_CTRL_1 asn1r_tags =
  268. {1, {{ASN1R_TAG_VAL (CTX, 0), _goose_vmd_spec}}};
  269. ac->asn1r_tag_table = &asn1r_tags;
  270. }
  271. /************************************************************************/
  272. /* _goose_vmd_spec */
  273. /************************************************************************/
  274. static ST_VOID _goose_vmd_spec (ASN1_DEC_CTXT *ac)
  275. {
  276. ST_CHAR *data_ptr;
  277. data_ptr = (ST_CHAR *) ac->asn1r_field_ptr-1;
  278. asn1r_get_vstr (ac, data_ptr);
  279. if (strcmp (data_ptr, "GOOSE") != 0)
  280. asn1r_set_dec_err (ac, GOOSE_NAME_MISMATCH);
  281. ac->asn1r_c_done_fun [ac->asn1r_msg_level] = _goose_named_done;
  282. }
  283. /************************************************************************/
  284. /* _goose_named_done */
  285. /************************************************************************/
  286. static ST_VOID _goose_named_done (ASN1_DEC_CTXT *ac)
  287. {
  288. ac->asn1r_c_done_fun [ac->asn1r_msg_level] = _goose_seq_of_varspec_done;
  289. }
  290. /************************************************************************/
  291. /* _goose_seq_of_varspec_done */
  292. /************************************************************************/
  293. static ST_VOID _goose_seq_of_varspec_done (ASN1_DEC_CTXT *ac)
  294. {
  295. ac->asn1r_c_done_fun [ac->asn1r_msg_level] = _goose_list_of_var_done;
  296. }
  297. /************************************************************************/
  298. /* _goose_list_of_var_done */
  299. /************************************************************************/
  300. static ST_VOID _goose_list_of_var_done (ASN1_DEC_CTXT *ac)
  301. {
  302. static ASN1R_TAG_CTRL_1 asn1r_tags =
  303. {1, {{ASN1R_TAG_VAL (CTX | CONSTR, 0), _goose_list_acc_rslt}}};
  304. ac->asn1r_tag_table = &asn1r_tags;
  305. }
  306. /************************************************************************/
  307. /* _goose_list_acc_rslt */
  308. /************************************************************************/
  309. static ST_VOID _goose_list_acc_rslt (ASN1_DEC_CTXT *ac)
  310. {
  311. static ASN1R_TAG_CTRL_1 asn1r_tags =
  312. {1, {{ASN1R_TAG_VAL (CTX | CONSTR, 2), _goose_struct}}};
  313. ac->asn1r_tag_table = &asn1r_tags;
  314. }
  315. /************************************************************************/
  316. /* _goose_struct */
  317. /************************************************************************/
  318. static ST_VOID _goose_struct (ASN1_DEC_CTXT *ac)
  319. {
  320. static ASN1R_TAG_CTRL_1 asn1r_tags =
  321. {1, {{ASN1R_TAG_VAL (CTX, 10), _goose_get_app_id}}};
  322. ac->asn1r_tag_table = &asn1r_tags;
  323. }
  324. /************************************************************************/
  325. /* _goose_get_app_id */
  326. /************************************************************************/
  327. static ST_VOID _goose_get_app_id (ASN1_DEC_CTXT *ac)
  328. {
  329. GOOSE_INFO *_goose_dec_info;
  330. static ASN1R_TAG_CTRL_1 asn1r_tags =
  331. {1, {{ASN1R_TAG_VAL (CTX, 12), _goose_get_sent_time}}};
  332. _goose_dec_info = (GOOSE_INFO *) ac->usr_info[0];
  333. asn1r_get_vstr (ac, _goose_dec_info->SendingIED);
  334. ac->asn1r_tag_table = &asn1r_tags;
  335. }
  336. /************************************************************************/
  337. /* _goose_get_sent_time */
  338. /************************************************************************/
  339. static ST_VOID _goose_get_sent_time (ASN1_DEC_CTXT *ac)
  340. {
  341. GOOSE_INFO *_goose_dec_info;
  342. static ASN1R_TAG_CTRL_1 asn1r_tags =
  343. {1, {{ASN1R_TAG_VAL (CTX, 6), _goose_get_seqnum}}};
  344. _goose_dec_info = (GOOSE_INFO *) ac->usr_info[0];
  345. asn1r_get_btod (ac, &_goose_dec_info->t);
  346. ac->asn1r_tag_table = &asn1r_tags;
  347. }
  348. /************************************************************************/
  349. /* _goose_get_seqnum */
  350. /************************************************************************/
  351. static ST_VOID _goose_get_seqnum (ASN1_DEC_CTXT *ac)
  352. {
  353. GOOSE_INFO *_goose_dec_info;
  354. static ASN1R_TAG_CTRL_1 asn1r_tags =
  355. {1, {{ASN1R_TAG_VAL (CTX, 6), _goose_get_sub_seq}}};
  356. _goose_dec_info = (GOOSE_INFO *) ac->usr_info[0];
  357. asn1r_get_u32 (ac, &_goose_dec_info->SqNum);
  358. ac->asn1r_tag_table = &asn1r_tags;
  359. }
  360. /************************************************************************/
  361. /* _goose_get_sub_seq */
  362. /************************************************************************/
  363. static ST_VOID _goose_get_sub_seq (ASN1_DEC_CTXT *ac)
  364. {
  365. GOOSE_INFO *_goose_dec_info;
  366. static ASN1R_TAG_CTRL_1 asn1r_tags =
  367. {1, {{ASN1R_TAG_VAL (CTX, 6), _goose_get_hold_time}}};
  368. _goose_dec_info = (GOOSE_INFO *) ac->usr_info[0];
  369. asn1r_get_u32 (ac, &_goose_dec_info->StNum);
  370. ac->asn1r_tag_table = &asn1r_tags;
  371. }
  372. /************************************************************************/
  373. /* _goose_get_hold_time */
  374. /************************************************************************/
  375. static ST_VOID _goose_get_hold_time (ASN1_DEC_CTXT *ac)
  376. {
  377. GOOSE_INFO *_goose_dec_info;
  378. static ASN1R_TAG_CTRL_1 asn1r_tags =
  379. {1, {{ASN1R_TAG_VAL (CTX, 6), _goose_get_back_time}}};
  380. _goose_dec_info = (GOOSE_INFO *) ac->usr_info[0];
  381. asn1r_get_u32 (ac, &_goose_dec_info->HoldTim);
  382. ac->asn1r_tag_table = &asn1r_tags;
  383. }
  384. /************************************************************************/
  385. /* _goose_get_back_time */
  386. /************************************************************************/
  387. static ST_VOID _goose_get_back_time (ASN1_DEC_CTXT *ac)
  388. {
  389. GOOSE_INFO *_goose_dec_info;
  390. static ASN1R_TAG_CTRL_1 asn1r_tags =
  391. {1, {{ASN1R_TAG_VAL (CTX, 6), _goose_get_phsid}}};
  392. _goose_dec_info = (GOOSE_INFO *) ac->usr_info[0];
  393. asn1r_get_u32 (ac, &_goose_dec_info->BackTim);
  394. ac->asn1r_tag_table = &asn1r_tags;
  395. }
  396. /************************************************************************/
  397. /* _goose_get_phsid */
  398. /************************************************************************/
  399. static ST_VOID _goose_get_phsid (ASN1_DEC_CTXT *ac)
  400. {
  401. GOOSE_INFO *_goose_dec_info;
  402. static ASN1R_TAG_CTRL_1 asn1r_tags =
  403. {1, {{ASN1R_TAG_VAL (CTX, 4), _goose_get_dnabits}}};
  404. _goose_dec_info = (GOOSE_INFO *) ac->usr_info[0];
  405. asn1r_get_u16 (ac, &_goose_dec_info->PhsID);
  406. ac->asn1r_tag_table = &asn1r_tags;
  407. }
  408. /************************************************************************/
  409. /* _goose_get_dnabits */
  410. /************************************************************************/
  411. static ST_VOID _goose_get_dnabits (ASN1_DEC_CTXT *ac)
  412. {
  413. GOOSE_INFO *_goose_dec_info;
  414. static ASN1R_TAG_CTRL_1 asn1r_tags =
  415. {1, {{ASN1R_TAG_VAL (CTX, 4), _goose_get_usrbits}}};
  416. _goose_dec_info = (GOOSE_INFO *) ac->usr_info[0];
  417. asn1r_get_bitstr (ac, _goose_dec_info->DNA, GOOSE_MAX_NUM_DNA_BITS);
  418. _goose_dec_info->num_dna_bits = ac->asn1r_bitcount;
  419. ac->asn1r_tag_table = &asn1r_tags;
  420. }
  421. /************************************************************************/
  422. /* _goose_get_usrbits */
  423. /************************************************************************/
  424. static ST_VOID _goose_get_usrbits (ASN1_DEC_CTXT *ac)
  425. {
  426. GOOSE_INFO *_goose_dec_info;
  427. _goose_dec_info = (GOOSE_INFO *) ac->usr_info[0];
  428. asn1r_get_bitstr (ac, _goose_dec_info->UserSt, GOOSE_MAX_NUM_USR_BITS);
  429. _goose_dec_info->num_usr_bits = ac->asn1r_bitcount;
  430. ac->asn1r_c_done_fun [ac->asn1r_msg_level] = _goose_struct_done;
  431. }
  432. /************************************************************************/
  433. /* _goose_struct_done */
  434. /************************************************************************/
  435. static ST_VOID _goose_struct_done (ASN1_DEC_CTXT *ac)
  436. {
  437. ac->asn1r_c_done_fun [ac->asn1r_msg_level] = _goose_list_acc_rslt_done;
  438. }
  439. /************************************************************************/
  440. /* _goose_list_acc_rslt_done */
  441. /************************************************************************/
  442. static ST_VOID _goose_list_acc_rslt_done (ASN1_DEC_CTXT *ac)
  443. {
  444. ac->asn1r_c_done_fun [ac->asn1r_msg_level] = _goose_info_rpt_done;
  445. }
  446. /************************************************************************/
  447. /* _goose_info_rpt_done */
  448. /************************************************************************/
  449. static ST_VOID _goose_info_rpt_done (ASN1_DEC_CTXT *ac)
  450. {
  451. ac->asn1r_c_done_fun [ac->asn1r_msg_level] = _goose_unconf_req_done;
  452. }
  453. /************************************************************************/
  454. /* _goose_unconf_req_done */
  455. /************************************************************************/
  456. static ST_VOID _goose_unconf_req_done (ASN1_DEC_CTXT *ac)
  457. {
  458. ac->asn1r_decode_done_fun = _goose_done_ok;
  459. ac->asn1r_decode_done = SD_TRUE;
  460. }
  461. /************************************************************************/
  462. /* _goose_done_ok */
  463. /************************************************************************/
  464. static ST_VOID _goose_done_ok (ASN1_DEC_CTXT *ac)
  465. {
  466. }
  467. /************************************************************************/
  468. /* _goose_done_error */
  469. /************************************************************************/
  470. static ST_VOID _goose_done_error (ASN1_DEC_CTXT *ac)
  471. {
  472. asn1r_set_dec_err (ac, GOOSE_DONE_TOO_SOON);
  473. }
  474. /************************************************************************/
  475. /* _goose_error */
  476. /************************************************************************/
  477. static ST_VOID _goose_error (ASN1_DEC_CTXT *ac, ST_RET err)
  478. {
  479. }
  480. /************************************************************************/
  481. /* gse_uca_decode */
  482. /* This function decodes the subnet packet (sn_udt), and puts the */
  483. /* results in the user structure (goose_info). */
  484. /* First it decodes from SN_UNITDATA to N_UNITDATA. */
  485. /* Then it decodes from N_UNITDATA to AUDT_APDU. */
  486. /* Then it decodes from AUDT_APDU to GOOSE_INFO. */
  487. /************************************************************************/
  488. ST_RET gse_uca_decode (SN_UNITDATA *sn_udt, /* input subnet packet */
  489. GOOSE_INFO *goose_info) /* output GOOSE data */
  490. {
  491. ST_RET rc;
  492. N_UNITDATA *pNudt = NULL; /* intermediate decode result */
  493. AUDT_APDU audt; /* intermediate decode result */
  494. /* Decode from SN_UNITDATA to N_UNITDATA. */
  495. /* clnpl_decode allocs a N_UNITDATA structure if this is a N-Unitdata */
  496. /* packet, and changes the value of pNudt to point to it. */
  497. if ((rc = clnpl_decode (sn_udt, &pNudt)) != SD_SUCCESS)
  498. return (rc);
  499. if (pNudt==NULL)
  500. return (SD_FAILURE); /* does this ever happen? */
  501. /* Decode from N_UNITDATA to AUDT_APDU. */
  502. if ((rc = cltp_decode_nsdu_2 (pNudt, &audt)) != SD_SUCCESS)
  503. return (rc);
  504. /* CRITICAL: DON't free N_UNITDATA here, because AUDT_APDU has pointer into it. */
  505. /* Decode from AUDT_APDU to GOOSE_INFO. */
  506. rc = _goose_decode_mms (&audt, goose_info);
  507. /* Now it is safe to free N_UNITDATA. All data in GOOSE_INFO now. */
  508. clnp_free (pNudt);
  509. return (rc);
  510. }

comments powered by Disqus