blob: 8d9e1c880323b3037bb47175734d2b70294a8760 [file] [log] [blame]
Harald Welteba43de42015-08-29 20:33:16 +02001#include <osmocom/core/msgb.h>
Harald Welteb3dae302015-08-30 12:20:09 +02002#include <osmocom/core/utils.h>
Harald Welteba43de42015-08-29 20:33:16 +02003
Harald Welteb3dae302015-08-30 12:20:09 +02004#include <unistd.h>
5#include <string.h>
6
Harald Welte30afef32015-08-30 12:28:29 +02007#include "asn1helpers.h"
8
Harald Welteb3dae302015-08-30 12:20:09 +02009#include "hnbap.h"
Harald Welteba43de42015-08-29 20:33:16 +020010#include "hnbgw.h"
11#include "hnbap_const.h"
12
Harald Welteb3dae302015-08-30 12:20:09 +020013
Harald Welteba43de42015-08-29 20:33:16 +020014static int hnbgw_hnbap_tx(struct HNBAP_PDU *pdu)
15{
16 /* FIXME */
17}
18
19static int hnbgw_tx_hnb_register_acc()
20{
21 /* FIXME */
22 /* Single required response IE: RNC-ID */
23}
24
25static int hnbgw_tx_ue_register_acc()
26{
27 /* FIXME */
28 /* Single required response IE: RNC-ID */
29}
30
Harald Welteb3dae302015-08-30 12:20:09 +020031#define FIND_IE(cont, id) find_ie((const struct ProtocolIE_Container_1 *)cont, id)
32
33static void *find_ie(const struct ProtocolIE_Container_1 *cont, ProtocolIE_ID id)
Harald Welteba43de42015-08-29 20:33:16 +020034{
Harald Welteb3dae302015-08-30 12:20:09 +020035 int i;
36
Harald Welteba43de42015-08-29 20:33:16 +020037 for (i = 0; i < cont->count; i++) {
Harald Welteb3dae302015-08-30 12:20:09 +020038 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 Welteba43de42015-08-29 20:33:16 +020044 }
45 return NULL;
46}
47
Harald Weltea2e6a7a2015-08-29 21:47:39 +020048static int hnbgw_rx_hnb_register_req(struct hnb_context *ctx, struct HNBRegisterRequest *req)
Harald Welteba43de42015-08-29 20:33:16 +020049{
50 HNB_Identity *identity =
Harald Welteb3dae302015-08-30 12:20:09 +020051 FIND_IE(&req->protocolIEs, HNBAP_IEI_HNB_Identity);
Harald Welteba43de42015-08-29 20:33:16 +020052 HNB_Location_Information *loc =
Harald Welteb3dae302015-08-30 12:20:09 +020053 FIND_IE(&req->protocolIEs, HNBAP_IEI_HNB_Location_Information);
Harald Welteba43de42015-08-29 20:33:16 +020054 PLMNidentity *plmn_id =
Harald Welteb3dae302015-08-30 12:20:09 +020055 FIND_IE(&req->protocolIEs, HNBAP_IEI_PLMNidentity);
Harald Welteba43de42015-08-29 20:33:16 +020056 CellIdentity *cell_id =
Harald Welteb3dae302015-08-30 12:20:09 +020057 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 Welteba43de42015-08-29 20:33:16 +020061 /* Optional: CSG-ID */
62
63 if(!identity || !loc || !plmn_id || !cell_id || !lac || !rac || !sac)
64 return -1;
65
Harald Weltea2e6a7a2015-08-29 21:47:39 +020066 /* copy all identity parameters from the message to ctx */
Harald Welte30afef32015-08-30 12:28:29 +020067 asn1_strncpy(ctx->identity_info, &identity->hNB_Identity_Info,
Harald Welteb3dae302015-08-30 12:20:09 +020068 sizeof(ctx->identity_info));
Harald Weltea2e6a7a2015-08-29 21:47:39 +020069 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 Welteb3dae302015-08-30 12:20:09 +020073 //ctx->id.mcc FIXME
74 //ctx->id.mnc FIXME
Harald Weltea2e6a7a2015-08-29 21:47:39 +020075
Harald Welteba43de42015-08-29 20:33:16 +020076 /* FIXME: Send HNBRegisterAccept */
77}
78
Harald Weltea2e6a7a2015-08-29 21:47:39 +020079static int hnbgw_rx_ue_register_req(struct hnb_context *ctx, struct UERegisterRequest *req)
Harald Welteba43de42015-08-29 20:33:16 +020080{
81 UE_Identity *id =
Harald Welteb3dae302015-08-30 12:20:09 +020082 FIND_IE(&req->protocolIEs, HNBAP_IEI_UE_Identity);
Harald Welteba43de42015-08-29 20:33:16 +020083 Registration_Cause *reg_cause =
Harald Welteb3dae302015-08-30 12:20:09 +020084 FIND_IE(&req->protocolIEs, HNBAP_IEI_RegistrationCause);
Harald Welteba43de42015-08-29 20:33:16 +020085 UE_Capabilities *ue_cap =
Harald Welteb3dae302015-08-30 12:20:09 +020086 FIND_IE(&req->protocolIEs, HNBAP_IEI_UE_Capabilities);
Harald Welteba43de42015-08-29 20:33:16 +020087
88 if (!id || !reg_cause || !ue_cap)
89 return -1;
90
91 /* FIXME: Send UERegisterAccept */
92}
93
Harald Welteb3dae302015-08-30 12:20:09 +020094static int hnbgw_rx_initiating_msg(struct hnb_context *hnb, struct InitiatingMessage *imsg)
Harald Welteba43de42015-08-29 20:33:16 +020095{
96 int rc;
97
Harald Welteb3dae302015-08-30 12:20:09 +020098 switch (imsg->procedureCode) {
Harald Welteba43de42015-08-29 20:33:16 +020099 case HNBAP_PC_HNBRegister: /* 8.2 */
Harald Welteb3dae302015-08-30 12:20:09 +0200100 if (imsg->value.type != asn1_type_HNBRegisterRequest)
Harald Welteba43de42015-08-29 20:33:16 +0200101 return -1;
Harald Welteb3dae302015-08-30 12:20:09 +0200102 rc = hnbgw_rx_hnb_register_req(hnb, imsg->value.u.data);
Harald Welteba43de42015-08-29 20:33:16 +0200103 break;
104 case HNBAP_PC_HNBDe_Register: /* 8.3 */
105 break;
106 case HNBAP_PC_UERegister: /* 8.4 */
Harald Welteb3dae302015-08-30 12:20:09 +0200107 if (imsg->value.type != asn1_type_UERegisterRequest)
Harald Welteba43de42015-08-29 20:33:16 +0200108 return -1;
Harald Welteb3dae302015-08-30 12:20:09 +0200109 rc = hnbgw_rx_ue_register_req(hnb, imsg->value.u.data);
Harald Welteba43de42015-08-29 20:33:16 +0200110 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 Welteb3dae302015-08-30 12:20:09 +0200125static int hnbgw_rx_successful_outcome_msg(struct hnb_context *hnb, struct SuccessfulOutcome *msg)
Harald Welteba43de42015-08-29 20:33:16 +0200126{
127
128}
129
Harald Welteb3dae302015-08-30 12:20:09 +0200130static int hnbgw_rx_unsuccessful_outcome_msg(struct hnb_context *hnb, struct UnsuccessfulOutcome *msg)
Harald Welteba43de42015-08-29 20:33:16 +0200131{
132
133}
134
135
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200136static int _hnbgw_hnbap_rx(struct hnb_context *hnb, struct HNBAP_PDU *pdu)
Harald Welteba43de42015-08-29 20:33:16 +0200137{
Harald Welteb3dae302015-08-30 12:20:09 +0200138 int rc;
139
Harald Welteba43de42015-08-29 20:33:16 +0200140 /* 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 Welteb3dae302015-08-30 12:20:09 +0200144 rc = hnbgw_rx_initiating_msg(hnb, &pdu->u.initiatingMessage);
Harald Welteba43de42015-08-29 20:33:16 +0200145 break;
146 case HNBAP_PDU_successfulOutcome:
Harald Welteb3dae302015-08-30 12:20:09 +0200147 rc = hnbgw_rx_successful_outcome_msg(hnb, &pdu->u.successfulOutcome);
Harald Welteba43de42015-08-29 20:33:16 +0200148 break;
149 case HNBAP_PDU_unsuccessfulOutcome:
Harald Welteb3dae302015-08-30 12:20:09 +0200150 rc = hnbgw_rx_unsuccessful_outcome_msg(hnb, &pdu->u.unsuccessfulOutcome);
Harald Welteba43de42015-08-29 20:33:16 +0200151 break;
152 default:
153 return -1;
154 }
155}
156
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200157int hnbgw_hnbap_rx(struct hnb_context *hnb, struct msgb *msg)
Harald Welteba43de42015-08-29 20:33:16 +0200158{
159 /* FIXME: decode and handle to _hnbgw_hnbap_rx() */
160}
161
162
163int hnbgw_hnbap_init(void)
164{
165
166}