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> |
| 5 | #include <string.h> |
| 6 | |
Harald Welte | 30afef3 | 2015-08-30 12:28:29 +0200 | [diff] [blame^] | 7 | #include "asn1helpers.h" |
| 8 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 9 | #include "hnbap.h" |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 10 | #include "hnbgw.h" |
| 11 | #include "hnbap_const.h" |
| 12 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 13 | |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 14 | static int hnbgw_hnbap_tx(struct HNBAP_PDU *pdu) |
| 15 | { |
| 16 | /* FIXME */ |
| 17 | } |
| 18 | |
| 19 | static int hnbgw_tx_hnb_register_acc() |
| 20 | { |
| 21 | /* FIXME */ |
| 22 | /* Single required response IE: RNC-ID */ |
| 23 | } |
| 24 | |
| 25 | static int hnbgw_tx_ue_register_acc() |
| 26 | { |
| 27 | /* FIXME */ |
| 28 | /* Single required response IE: RNC-ID */ |
| 29 | } |
| 30 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 31 | #define FIND_IE(cont, id) find_ie((const struct ProtocolIE_Container_1 *)cont, id) |
| 32 | |
| 33 | static void *find_ie(const struct ProtocolIE_Container_1 *cont, ProtocolIE_ID id) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 34 | { |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 35 | int i; |
| 36 | |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 37 | for (i = 0; i < cont->count; i++) { |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 38 | ProtocolIE_Field_1 *field = &cont->tab[i]; |
| 39 | if (field->id == id) { |
| 40 | OSMO_ASSERT(field->value.type); |
| 41 | /* FIXME: we shoudl check if it is the correct type, not just any type */ |
| 42 | return field->value.u.data; |
| 43 | } |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 44 | } |
| 45 | return NULL; |
| 46 | } |
| 47 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 48 | static int hnbgw_rx_hnb_register_req(struct hnb_context *ctx, struct HNBRegisterRequest *req) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 49 | { |
| 50 | HNB_Identity *identity = |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 51 | FIND_IE(&req->protocolIEs, HNBAP_IEI_HNB_Identity); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 52 | HNB_Location_Information *loc = |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 53 | FIND_IE(&req->protocolIEs, HNBAP_IEI_HNB_Location_Information); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 54 | PLMNidentity *plmn_id = |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 55 | FIND_IE(&req->protocolIEs, HNBAP_IEI_PLMNidentity); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 56 | CellIdentity *cell_id = |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 57 | FIND_IE(&req->protocolIEs, HNBAP_IEI_CellIdentity); |
| 58 | LAC *lac = FIND_IE(&req->protocolIEs, HNBAP_IEI_LAC); |
| 59 | RAC *rac = FIND_IE(&req->protocolIEs, HNBAP_IEI_RAC); |
| 60 | SAC *sac = FIND_IE(&req->protocolIEs, HNBAP_IEI_SAC); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 61 | /* Optional: CSG-ID */ |
| 62 | |
| 63 | if(!identity || !loc || !plmn_id || !cell_id || !lac || !rac || !sac) |
| 64 | return -1; |
| 65 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 66 | /* copy all identity parameters from the message to ctx */ |
Harald Welte | 30afef3 | 2015-08-30 12:28:29 +0200 | [diff] [blame^] | 67 | asn1_strncpy(ctx->identity_info, &identity->hNB_Identity_Info, |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 68 | sizeof(ctx->identity_info)); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 69 | ctx->id.lac = asn1str_to_u16(lac); |
| 70 | ctx->id.sac = asn1str_to_u16(sac); |
| 71 | ctx->id.rac = asn1str_to_u8(rac); |
| 72 | ctx->id.cid = asn1bitstr_to_u32(cell_id); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 73 | //ctx->id.mcc FIXME |
| 74 | //ctx->id.mnc FIXME |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 75 | |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 76 | /* FIXME: Send HNBRegisterAccept */ |
| 77 | } |
| 78 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 79 | static int hnbgw_rx_ue_register_req(struct hnb_context *ctx, struct UERegisterRequest *req) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 80 | { |
| 81 | UE_Identity *id = |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 82 | FIND_IE(&req->protocolIEs, HNBAP_IEI_UE_Identity); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 83 | Registration_Cause *reg_cause = |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 84 | FIND_IE(&req->protocolIEs, HNBAP_IEI_RegistrationCause); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 85 | UE_Capabilities *ue_cap = |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 86 | FIND_IE(&req->protocolIEs, HNBAP_IEI_UE_Capabilities); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 87 | |
| 88 | if (!id || !reg_cause || !ue_cap) |
| 89 | return -1; |
| 90 | |
| 91 | /* FIXME: Send UERegisterAccept */ |
| 92 | } |
| 93 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 94 | static int hnbgw_rx_initiating_msg(struct hnb_context *hnb, struct InitiatingMessage *imsg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 95 | { |
| 96 | int rc; |
| 97 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 98 | switch (imsg->procedureCode) { |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 99 | case HNBAP_PC_HNBRegister: /* 8.2 */ |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 100 | if (imsg->value.type != asn1_type_HNBRegisterRequest) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 101 | return -1; |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 102 | rc = hnbgw_rx_hnb_register_req(hnb, imsg->value.u.data); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 103 | break; |
| 104 | case HNBAP_PC_HNBDe_Register: /* 8.3 */ |
| 105 | break; |
| 106 | case HNBAP_PC_UERegister: /* 8.4 */ |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 107 | if (imsg->value.type != asn1_type_UERegisterRequest) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 108 | return -1; |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 109 | rc = hnbgw_rx_ue_register_req(hnb, imsg->value.u.data); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 110 | break; |
| 111 | case HNBAP_PC_UEDe_Register: /* 8.5 */ |
| 112 | break; |
| 113 | case HNBAP_PC_ErrorIndication: /* 8.6 */ |
| 114 | case HNBAP_PC_TNLUpdate: /* 8.9 */ |
| 115 | case HNBAP_PC_HNBConfigTransfer: /* 8.10 */ |
| 116 | case HNBAP_PC_RelocationComplete: /* 8.11 */ |
| 117 | case HNBAP_PC_U_RNTIQuery: /* 8.12 */ |
| 118 | case HNBAP_PC_privateMessage: |
| 119 | break; |
| 120 | default: |
| 121 | break; |
| 122 | } |
| 123 | } |
| 124 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 125 | static int hnbgw_rx_successful_outcome_msg(struct hnb_context *hnb, struct SuccessfulOutcome *msg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 126 | { |
| 127 | |
| 128 | } |
| 129 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 130 | static int hnbgw_rx_unsuccessful_outcome_msg(struct hnb_context *hnb, struct UnsuccessfulOutcome *msg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 131 | { |
| 132 | |
| 133 | } |
| 134 | |
| 135 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 136 | static int _hnbgw_hnbap_rx(struct hnb_context *hnb, struct HNBAP_PDU *pdu) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 137 | { |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 138 | int rc; |
| 139 | |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 140 | /* it's a bit odd that we can't dispatch on procedure code, but |
| 141 | * that's not possible */ |
| 142 | switch (pdu->choice) { |
| 143 | case HNBAP_PDU_initiatingMessage: |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 144 | rc = hnbgw_rx_initiating_msg(hnb, &pdu->u.initiatingMessage); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 145 | break; |
| 146 | case HNBAP_PDU_successfulOutcome: |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 147 | rc = hnbgw_rx_successful_outcome_msg(hnb, &pdu->u.successfulOutcome); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 148 | break; |
| 149 | case HNBAP_PDU_unsuccessfulOutcome: |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 150 | rc = hnbgw_rx_unsuccessful_outcome_msg(hnb, &pdu->u.unsuccessfulOutcome); |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 151 | break; |
| 152 | default: |
| 153 | return -1; |
| 154 | } |
| 155 | } |
| 156 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 157 | int hnbgw_hnbap_rx(struct hnb_context *hnb, struct msgb *msg) |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 158 | { |
| 159 | /* FIXME: decode and handle to _hnbgw_hnbap_rx() */ |
| 160 | } |
| 161 | |
| 162 | |
| 163 | int hnbgw_hnbap_init(void) |
| 164 | { |
| 165 | |
| 166 | } |