Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 1 | #include <osmocom/core/msgb.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 2 | #include <osmocom/core/utils.h> |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 3 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 4 | #include <unistd.h> |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 5 | #include <errno.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 6 | #include <string.h> |
| 7 | |
Harald Welte | 30afef3 | 2015-08-30 12:28:29 +0200 | [diff] [blame] | 8 | #include "asn1helpers.h" |
| 9 | |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 10 | #include "hnbgw.h" |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 11 | #include "hnbap_common.h" |
| 12 | #include "hnbap_ies_defs.h" |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 13 | |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 14 | #define IU_MSG_NUM_IES 32 |
| 15 | #define IU_MSG_NUM_EXT_IES 32 |
| 16 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 17 | static int hnbgw_hnbap_tx(struct hnb_context *ctx, struct msgb *msg) |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 18 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 19 | /* FIXME */ |
| 20 | } |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 21 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 22 | static int hnbgw_tx_hnb_register_acc(struct hnb_context *ctx) |
| 23 | { |
| 24 | HNBRegisterAccept_t accept_out; |
| 25 | struct msgb *msg; |
| 26 | int rc; |
| 27 | |
| 28 | /* Single required response IE: RNC-ID */ |
| 29 | HNBRegisterAcceptIEs_t accept = { |
| 30 | .rnc_id = ctx->gw->config.rnc_id |
| 31 | }; |
| 32 | |
| 33 | /* encode the Information Elements */ |
| 34 | rc = hnbap_encode_hnbregisteraccepties(&accept_out, &accept); |
| 35 | if (rc < 0) { |
| 36 | return rc; |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 37 | } |
| 38 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 39 | /* generate a successfull outcome PDU */ |
| 40 | msg = hnbap_generate_successful_outcome(ProcedureCode_id_HNBRegister, |
| 41 | Criticality_reject, |
| 42 | &asn_DEF_HNBRegisterAccept, |
| 43 | &accept_out); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 44 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 45 | return hnbgw_hnbap_tx(ctx, msg); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 49 | static int hnbgw_tx_ue_register_acc(struct ue_context *ue) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 50 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 51 | UERegisterAccept_t accept_out; |
| 52 | UERegisterAcceptIEs_t accept; |
| 53 | struct msgb *msg; |
| 54 | int rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 55 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 56 | /* FIXME accept.uE_Identity; */ |
| 57 | asn1_u32_to_bitstring(&accept.context_ID, &ue->context_id); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 58 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 59 | rc = hnbap_encode_ueregisteraccepties(&accept_out, &accept); |
| 60 | if (rc < 0) { |
| 61 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 62 | } |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 63 | |
| 64 | msg = hnbap_generate_successful_outcome(ProcedureCode_id_UERegister, |
| 65 | Criticality_reject, |
| 66 | &asn_DEF_UERegisterAccept, |
| 67 | &accept_out); |
| 68 | return hnbgw_hnbap_tx(ue->hnb, msg); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 69 | } |
| 70 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 71 | static int hnbgw_rx_hnb_register_req(struct hnb_context *ctx, ANY_t *in) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 72 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 73 | HNBRegisterRequestIEs_t ies; |
| 74 | int rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 75 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 76 | rc = hnbap_decode_hnbregisterrequesties(&ies, in); |
| 77 | if (rc < 0) |
| 78 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 79 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 80 | /* copy all identity parameters from the message to ctx */ |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 81 | asn1_strncpy(ctx->identity_info, &ies.hnB_Identity.hNB_Identity_Info, |
| 82 | sizeof(ctx->identity_info)); |
| 83 | ctx->id.lac = asn1str_to_u16(&ies.lac); |
| 84 | ctx->id.sac = asn1str_to_u16(&ies.sac); |
| 85 | ctx->id.rac = asn1str_to_u8(&ies.rac); |
| 86 | ctx->id.cid = asn1bitstr_to_u32(&ies.cellIdentity); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 87 | //ctx->id.mcc FIXME |
| 88 | //ctx->id.mnc FIXME |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 89 | |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 90 | DEBUGP(DMAIN, "HNB-REGISTER-REQ from %s\n", ctx->identity_info); |
| 91 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 92 | /* Send HNBRegisterAccept */ |
| 93 | return hnbgw_tx_hnb_register_acc(ctx); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 96 | static int hnbgw_rx_ue_register_req(struct hnb_context *ctx, ANY_t *in) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 97 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 98 | UERegisterRequestIEs_t ies; |
| 99 | struct ue_context *ue; |
| 100 | int rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 101 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 102 | rc = hnbap_decode_ueregisterrequesties(&ies, in); |
| 103 | if (rc < 0) |
| 104 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 105 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 106 | DEBUGP(DMAIN, "UE-REGSITER-REQ ID_type=%d cause=%ld\n", |
| 107 | ies.uE_Identity.present, ies.registration_Cause); |
| 108 | |
| 109 | /* FIXME: convert UE identity into a more palatable format */ |
| 110 | |
| 111 | /* Send UERegisterAccept */ |
| 112 | return hnbgw_tx_ue_register_acc(ue); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 113 | } |
| 114 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 115 | static int hnbgw_rx_initiating_msg(struct hnb_context *hnb, InitiatingMessage_t *imsg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 116 | { |
| 117 | int rc; |
| 118 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 119 | switch (imsg->procedureCode) { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 120 | case ProcedureCode_id_HNBRegister: /* 8.2 */ |
| 121 | rc = hnbgw_rx_hnb_register_req(hnb, &imsg->value); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 122 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 123 | case ProcedureCode_id_HNBDe_Register: /* 8.3 */ |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 124 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 125 | case ProcedureCode_id_UERegister: /* 8.4 */ |
| 126 | rc = hnbgw_rx_ue_register_req(hnb, &imsg->value); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 127 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 128 | case ProcedureCode_id_UEDe_Register: /* 8.5 */ |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 129 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 130 | case ProcedureCode_id_ErrorIndication: /* 8.6 */ |
| 131 | case ProcedureCode_id_TNLUpdate: /* 8.9 */ |
| 132 | case ProcedureCode_id_HNBConfigTransfer: /* 8.10 */ |
| 133 | case ProcedureCode_id_RelocationComplete: /* 8.11 */ |
| 134 | case ProcedureCode_id_U_RNTIQuery: /* 8.12 */ |
| 135 | case ProcedureCode_id_privateMessage: |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 136 | break; |
| 137 | default: |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 142 | static int hnbgw_rx_successful_outcome_msg(struct hnb_context *hnb, SuccessfulOutcome_t *msg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 143 | { |
| 144 | |
| 145 | } |
| 146 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 147 | static int hnbgw_rx_unsuccessful_outcome_msg(struct hnb_context *hnb, UnsuccessfulOutcome_t *msg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 148 | { |
| 149 | |
| 150 | } |
| 151 | |
| 152 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 153 | static int _hnbgw_hnbap_rx(struct hnb_context *hnb, HNBAP_PDU_t *pdu) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 154 | { |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 155 | int rc; |
| 156 | |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 157 | /* it's a bit odd that we can't dispatch on procedure code, but |
| 158 | * that's not possible */ |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 159 | switch (pdu->present) { |
| 160 | case HNBAP_PDU_PR_initiatingMessage: |
| 161 | rc = hnbgw_rx_initiating_msg(hnb, &pdu->choice.initiatingMessage); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 162 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 163 | case HNBAP_PDU_PR_successfulOutcome: |
| 164 | rc = hnbgw_rx_successful_outcome_msg(hnb, &pdu->choice.successfulOutcome); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 165 | break; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 166 | case HNBAP_PDU_PR_unsuccessfulOutcome: |
| 167 | rc = hnbgw_rx_unsuccessful_outcome_msg(hnb, &pdu->choice.unsuccessfulOutcome); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 168 | break; |
| 169 | default: |
| 170 | return -1; |
| 171 | } |
| 172 | } |
| 173 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 174 | int hnbgw_hnbap_rx(struct hnb_context *hnb, struct msgb *msg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 175 | { |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 176 | HNBAP_PDU_t _pdu, *pdu = &_pdu; |
| 177 | asn_dec_rval_t dec_ret; |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 178 | int rc; |
| 179 | |
| 180 | /* decode and handle to _hnbgw_hnbap_rx() */ |
| 181 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame^] | 182 | dec_ret = aper_decode(NULL, &asn_DEF_HNBAP_PDU, (void **) &pdu, |
| 183 | msg->data, msgb_length(msg), 0, 0); |
| 184 | if (dec_ret.code != RC_OK) { |
| 185 | LOGP(DMAIN, LOGL_ERROR, "Error in ASN.1 decode\n"); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 186 | return rc; |
| 187 | } |
| 188 | |
| 189 | rc = _hnbgw_hnbap_rx(hnb, pdu); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 190 | |
| 191 | return rc; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | |
| 195 | int hnbgw_hnbap_init(void) |
| 196 | { |
| 197 | |
| 198 | } |