Harald Welte | 65dad8e | 2019-05-06 14:48:02 +0200 | [diff] [blame^] | 1 | |
| 2 | #include <string.h> |
| 3 | #include <stdarg.h> |
| 4 | #include "SABP_PDU_Descriptions.hh" |
| 5 | |
| 6 | extern "C" { |
| 7 | #include <fftranscode/transcode.h> |
| 8 | } |
| 9 | |
| 10 | namespace SABP__Types { |
| 11 | |
| 12 | TTCN_Module SABP__EncDec("SABP_EncDec", __DATE__, __TIME__); |
| 13 | |
| 14 | OCTETSTRING enc__SABP__PDU(const SABP__PDU__Descriptions::SABP__PDU &pdu) |
| 15 | { |
| 16 | uint8_t *aper_buf; |
| 17 | int aper_buf_len; |
| 18 | TTCN_Buffer TTCN_buf; |
| 19 | TTCN_buf.clear(); |
| 20 | |
| 21 | /* Encode from abstract data type into BER/DER */ |
| 22 | pdu.encode(SABP__PDU__Descriptions::SABP__PDU_descr_, TTCN_buf, |
| 23 | TTCN_EncDec::CT_BER, BER_ENCODE_DER); |
| 24 | |
| 25 | aper_buf_len = fftranscode_ber2aper(FFTRANSC_T_SABP, &aper_buf, TTCN_buf.get_data(), TTCN_buf.get_len()); |
| 26 | if (aper_buf_len < 0) { |
| 27 | TTCN_error("fftranscode failed."); |
| 28 | } |
| 29 | |
| 30 | /* make octetstring from output buffer */ |
| 31 | OCTETSTRING ret_val(aper_buf_len, aper_buf); |
| 32 | |
| 33 | /* release dynamically-allocated output buffer */ |
| 34 | fftranscode_free(aper_buf); |
| 35 | |
| 36 | return ret_val; |
| 37 | } |
| 38 | |
| 39 | SABP__PDU__Descriptions::SABP__PDU dec__SABP__PDU(const OCTETSTRING &stream) |
| 40 | { |
| 41 | uint8_t *ber_buf; |
| 42 | int ber_buf_len; |
| 43 | |
| 44 | /* First, decode APER + re-encode as BER */ |
| 45 | ber_buf_len = fftranscode_aper2ber(FFTRANSC_T_SABP, &ber_buf, (const unsigned char *)stream, stream.lengthof()); |
| 46 | if (ber_buf_len < 0) { |
| 47 | TTCN_error("fftranscode failed."); |
| 48 | } |
| 49 | |
| 50 | /* Then, re-encode from BER to TITAN representation */ |
| 51 | SABP__PDU__Descriptions::SABP__PDU ret_dcc; |
| 52 | TTCN_Buffer TTCN_buf; |
| 53 | TTCN_buf.clear(); |
| 54 | TTCN_buf.put_s(ber_buf_len, ber_buf); |
| 55 | |
| 56 | ret_dcc.decode(SABP__PDU__Descriptions::SABP__PDU_descr_, TTCN_buf, |
| 57 | TTCN_EncDec::CT_BER, BER_ACCEPT_ALL); |
| 58 | |
| 59 | fftranscode_free(ber_buf); |
| 60 | |
| 61 | return ret_dcc; |
| 62 | } |
| 63 | |
| 64 | } |