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