Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame^] | 1 | #include <osmocom/core/msgb.h> |
| 2 | #include <osmocom/core/utils.h> |
| 3 | |
| 4 | #include <unistd.h> |
| 5 | #include <errno.h> |
| 6 | #include <string.h> |
| 7 | |
| 8 | #include "asn1helpers.h" |
| 9 | |
| 10 | #include "hnbgw.h" |
| 11 | //#include "ranap_common.h" |
| 12 | |
| 13 | #include "ranap/RANAP_RANAP-PDU.h" |
| 14 | #include "ranap/RANAP_ResetAcknowledge.h" |
| 15 | #include "ranap/RANAP_Reset.h" |
| 16 | #include "ranap/RANAP_ProtocolIE-ID.h" |
| 17 | #include "ranap/RANAP_Cause.h" |
| 18 | #include "ranap/RANAP_CN-DomainIndicator.h" |
| 19 | #include "ranap/RANAP_GlobalRNC-ID.h" |
| 20 | #include "ranap/RANAP_CriticalityDiagnostics.h" |
| 21 | |
| 22 | |
| 23 | /*********************************************************************** |
| 24 | * BEGIN auto-generated copy+pasted |
| 25 | ***********************************************************************/ |
| 26 | |
| 27 | /* this is copy+pasted from the asn1tostruct generated code that doesn't |
| 28 | * compile as a whole */ |
| 29 | |
| 30 | #define RANAP_DEBUG(x, args ...) DEBUGP(0, x, ## args) |
| 31 | |
| 32 | extern int asn1_xer_print; |
| 33 | |
| 34 | struct msgb *ranap_generate_successful_outcome( |
| 35 | e_RANAP_ProcedureCode procedureCode, |
| 36 | RANAP_Criticality_t criticality, |
| 37 | asn_TYPE_descriptor_t * td, |
| 38 | void *sptr); |
| 39 | |
| 40 | RANAP_IE_t *ranap_new_ie(RANAP_ProtocolIE_ID_t id, RANAP_Criticality_t criticality, |
| 41 | asn_TYPE_descriptor_t *type, void *sptr); |
| 42 | |
| 43 | #define RESETIES_RANAP_GLOBALRNC_ID_PRESENT (1 << 0) |
| 44 | |
| 45 | typedef struct RANAP_ResetIEs_s { |
| 46 | uint16_t presenceMask; |
| 47 | RANAP_Cause_t cause; |
| 48 | RANAP_CN_DomainIndicator_t cN_DomainIndicator; |
| 49 | RANAP_GlobalRNC_ID_t globalRNC_ID; ///< Optional field |
| 50 | } RANAP_ResetIEs_t; |
| 51 | |
| 52 | #define RESETACKNOWLEDGEIES_RANAP_CRITICALITYDIAGNOSTICS_PRESENT (1 << 0) |
| 53 | #define RESETACKNOWLEDGEIES_RANAP_GLOBALRNC_ID_PRESENT (1 << 1) |
| 54 | |
| 55 | typedef struct RANAP_ResetAcknowledgeIEs_s { |
| 56 | uint16_t presenceMask; |
| 57 | RANAP_CN_DomainIndicator_t cN_DomainIndicator; |
| 58 | RANAP_CriticalityDiagnostics_t criticalityDiagnostics; ///< Optional field |
| 59 | RANAP_GlobalRNC_ID_t globalRNC_ID; ///< Optional field |
| 60 | } RANAP_ResetAcknowledgeIEs_t; |
| 61 | |
| 62 | int ranap_decode_reseties( |
| 63 | RANAP_ResetIEs_t *resetIEs, |
| 64 | ANY_t *any_p) { |
| 65 | |
| 66 | RANAP_Reset_t reset; |
| 67 | RANAP_Reset_t *reset_p = &reset; |
| 68 | int i, decoded = 0; |
| 69 | int tempDecoded = 0; |
| 70 | assert(any_p != NULL); |
| 71 | assert(resetIEs != NULL); |
| 72 | |
| 73 | RANAP_DEBUG("Decoding message RANAP_ResetIEs (%s:%d)\n", __FILE__, __LINE__); |
| 74 | |
| 75 | ANY_to_type_aper(any_p, &asn_DEF_RANAP_Reset, (void**)&reset_p); |
| 76 | |
| 77 | for (i = 0; i < reset_p->reset_ies.list.count; i++) { |
| 78 | RANAP_IE_t *ie_p; |
| 79 | ie_p = reset_p->reset_ies.list.array[i]; |
| 80 | switch(ie_p->id) { |
| 81 | case RANAP_ProtocolIE_ID_id_Cause: |
| 82 | { |
| 83 | RANAP_Cause_t ranaP_Cause; |
| 84 | RANAP_Cause_t *ranaP_Cause_p = &ranaP_Cause; |
| 85 | tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_RANAP_Cause, (void**)&ranaP_Cause_p); |
| 86 | if (tempDecoded < 0) { |
| 87 | RANAP_DEBUG("Decoding of IE cause failed\n"); |
| 88 | return -1; |
| 89 | } |
| 90 | decoded += tempDecoded; |
| 91 | if (asn1_xer_print) |
| 92 | xer_fprint(stdout, &asn_DEF_RANAP_Cause, ranaP_Cause_p); |
| 93 | memcpy(&resetIEs->cause, ranaP_Cause_p, sizeof(RANAP_Cause_t)); |
| 94 | } break; |
| 95 | case RANAP_ProtocolIE_ID_id_CN_DomainIndicator: |
| 96 | { |
| 97 | RANAP_CN_DomainIndicator_t ranaP_CNDomainIndicator; |
| 98 | RANAP_CN_DomainIndicator_t *ranaP_CNDomainIndicator_p = &ranaP_CNDomainIndicator; |
| 99 | tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_RANAP_CN_DomainIndicator, (void**)&ranaP_CNDomainIndicator_p); |
| 100 | if (tempDecoded < 0) { |
| 101 | RANAP_DEBUG("Decoding of IE cN_DomainIndicator failed\n"); |
| 102 | return -1; |
| 103 | } |
| 104 | decoded += tempDecoded; |
| 105 | if (asn1_xer_print) |
| 106 | xer_fprint(stdout, &asn_DEF_RANAP_CN_DomainIndicator, ranaP_CNDomainIndicator_p); |
| 107 | memcpy(&resetIEs->cN_DomainIndicator, ranaP_CNDomainIndicator_p, sizeof(RANAP_CN_DomainIndicator_t)); |
| 108 | } break; |
| 109 | /* Optional field */ |
| 110 | case RANAP_ProtocolIE_ID_id_GlobalRNC_ID: |
| 111 | { |
| 112 | #if 0 |
| 113 | RANAP_GlobalRNC_ID_t ranaP_GlobalRNCID; |
| 114 | RANAP_GlobalRNC_ID_t *ranaP_GlobalRNCID_p = &ranaP_GlobalRNCID; |
| 115 | resetIEs->presenceMask |= RESETIES_RANAP_GLOBALRNC_ID_PRESENT; |
| 116 | tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_RANAP_GlobalRNC_ID, (void**)&ranaP_GlobalRNCID_p); |
| 117 | if (tempDecoded < 0) { |
| 118 | RANAP_DEBUG("Decoding of IE globalRNC_ID failed\n"); |
| 119 | return -1; |
| 120 | } |
| 121 | decoded += tempDecoded; |
| 122 | if (asn1_xer_print) |
| 123 | xer_fprint(stdout, &asn_DEF_RANAP_GlobalRNC_ID, ranaP_GlobalRNCID_p); |
| 124 | memcpy(&resetIEs->globalRNC_ID, ranaP_GlobalRNCID_p, sizeof(RANAP_GlobalRNC_ID_t)); |
| 125 | #endif |
| 126 | } break; |
| 127 | default: |
| 128 | RANAP_DEBUG("Unknown protocol IE id (%d) for message reseties\n", (int)ie_p->id); |
| 129 | return -1; |
| 130 | } |
| 131 | } |
| 132 | return decoded; |
| 133 | } |
| 134 | |
| 135 | int ranap_encode_resetacknowledgeies( |
| 136 | RANAP_ResetAcknowledge_t *resetAcknowledge, |
| 137 | RANAP_ResetAcknowledgeIEs_t *resetAcknowledgeIEs) { |
| 138 | |
| 139 | RANAP_IE_t *ie; |
| 140 | |
| 141 | if ((ie = ranap_new_ie(RANAP_ProtocolIE_ID_id_CN_DomainIndicator, |
| 142 | RANAP_Criticality_reject, |
| 143 | &asn_DEF_RANAP_CN_DomainIndicator, |
| 144 | &resetAcknowledgeIEs->cN_DomainIndicator)) == NULL) { |
| 145 | return -1; |
| 146 | } |
| 147 | ASN_SEQUENCE_ADD(&resetAcknowledge->resetAcknowledge_ies.list, ie); |
| 148 | |
| 149 | /* Optional field */ |
| 150 | if ((resetAcknowledgeIEs->presenceMask & RESETACKNOWLEDGEIES_RANAP_CRITICALITYDIAGNOSTICS_PRESENT) |
| 151 | == RESETACKNOWLEDGEIES_RANAP_CRITICALITYDIAGNOSTICS_PRESENT) { |
| 152 | if ((ie = ranap_new_ie(RANAP_ProtocolIE_ID_id_CriticalityDiagnostics, |
| 153 | RANAP_Criticality_ignore, |
| 154 | &asn_DEF_RANAP_CriticalityDiagnostics, |
| 155 | &resetAcknowledgeIEs->criticalityDiagnostics)) == NULL) { |
| 156 | return -1; |
| 157 | } |
| 158 | ASN_SEQUENCE_ADD(&resetAcknowledge->resetAcknowledge_ies.list, ie); |
| 159 | } |
| 160 | |
| 161 | /* Optional field */ |
| 162 | if ((resetAcknowledgeIEs->presenceMask & RESETACKNOWLEDGEIES_RANAP_GLOBALRNC_ID_PRESENT) |
| 163 | == RESETACKNOWLEDGEIES_RANAP_GLOBALRNC_ID_PRESENT) { |
| 164 | if ((ie = ranap_new_ie(RANAP_ProtocolIE_ID_id_GlobalRNC_ID, |
| 165 | RANAP_Criticality_ignore, |
| 166 | &asn_DEF_RANAP_GlobalRNC_ID, |
| 167 | &resetAcknowledgeIEs->globalRNC_ID)) == NULL) { |
| 168 | return -1; |
| 169 | } |
| 170 | ASN_SEQUENCE_ADD(&resetAcknowledge->resetAcknowledge_ies.list, ie); |
| 171 | } |
| 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | /*********************************************************************** |
| 177 | * END auto-generated copy+pasted |
| 178 | ***********************************************************************/ |
| 179 | |
| 180 | #if 0 |
| 181 | { |
| 182 | RANAP_ResetAcknowledgeIEs_s ies; |
| 183 | |
| 184 | memset(&ies, 0, sizeof(ies)); |
| 185 | ies.cN_DomainIndicator = RANAP_CN_DomainIndicator_cs_domain; |
| 186 | |
| 187 | rc = ranap_encoderesetacknowledgeise(&ies, FIXME); |
| 188 | } |
| 189 | #endif |
| 190 | |
| 191 | static int ranap_rx_init_reset(struct hnb_context *hnb, ANY_t *in) |
| 192 | { |
| 193 | RANAP_ResetIEs_t ies; |
| 194 | int rc; |
| 195 | |
| 196 | rc = ranap_decode_reseties(&ies, in); |
| 197 | if (rc < 0) |
| 198 | return rc; |
| 199 | |
| 200 | DEBUGP(DMAIN, "RESET.req\n"); |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | static int ranap_rx_initiating_msg(struct hnb_context *hnb, RANAP_InitiatingMessage_t *imsg) |
| 206 | { |
| 207 | int rc; |
| 208 | |
| 209 | switch (imsg->procedureCode) { |
| 210 | case RANAP_ProcedureCode_id_Reset: |
| 211 | rc = ranap_rx_init_reset(hnb, &imsg->value); |
| 212 | break; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | static int _hnbgw_ranap_rx(struct hnb_context *hnb, RANAP_RANAP_PDU_t *pdu) |
| 217 | { |
| 218 | int rc; |
| 219 | |
| 220 | switch (pdu->present) { |
| 221 | case RANAP_RANAP_PDU_PR_initiatingMessage: |
| 222 | rc = ranap_rx_initiating_msg(hnb, &pdu->choice.initiatingMessage); |
| 223 | break; |
| 224 | case RANAP_RANAP_PDU_PR_successfulOutcome: |
| 225 | break; |
| 226 | case RANAP_RANAP_PDU_PR_unsuccessfulOutcome: |
| 227 | break; |
| 228 | default: |
| 229 | break; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | |
| 234 | int hnbgw_ranap_rx(struct msgb *msg, uint8_t *data, size_t len) |
| 235 | { |
| 236 | RANAP_RANAP_PDU_t _pdu, *pdu = &_pdu; |
| 237 | asn_dec_rval_t dec_ret; |
| 238 | int rc; |
| 239 | |
| 240 | memset(pdu, 0, sizeof(*pdu)); |
| 241 | dec_ret = aper_decode(NULL,&asn_DEF_RANAP_RANAP_PDU, (void **) &pdu, |
| 242 | data, len, 0, 0); |
| 243 | if (dec_ret.code != RC_OK) { |
| 244 | LOGP(DMAIN, LOGL_ERROR, "Error in RANAP ASN.1 decode\n"); |
| 245 | return rc; |
| 246 | } |
| 247 | |
| 248 | rc = _hnbgw_ranap_rx(msg->dst, pdu); |
| 249 | |
| 250 | return rc; |
| 251 | } |
| 252 | |
| 253 | int hnbgw_ranap_init(void) |
| 254 | { |
| 255 | |
| 256 | } |