blob: ce4122257b20d3f33a16ba99138be050cc157748 [file] [log] [blame]
Harald Welteba43de42015-08-29 20:33:16 +02001#include <osmocom/core/msgb.h>
2
3#include "hnbgw.h"
4#include "hnbap_const.h"
5
6static int hnbgw_hnbap_tx(struct HNBAP_PDU *pdu)
7{
8 /* FIXME */
9}
10
11static int hnbgw_tx_hnb_register_acc()
12{
13 /* FIXME */
14 /* Single required response IE: RNC-ID */
15}
16
17static int hnbgw_tx_ue_register_acc()
18{
19 /* FIXME */
20 /* Single required response IE: RNC-ID */
21}
22
23struct ProtocolIE_Field_1 *find_ie(const struct ProtocolIE_Container_1 *cont, ProtocolIE_ID id)
24{
25 for (i = 0; i < cont->count; i++) {
26 if (cont->tab[i].id == id)
27 return &cont->tab[i];
28 }
29 return NULL;
30}
31
Harald Weltea2e6a7a2015-08-29 21:47:39 +020032static inline uint16_t asn1str_to_u16(ASN1String *as)
33{
34 if (as->len < 2)
35 return 0;
36 else
37 return *(uint16_t *)as->buf;
38}
39
40static inline uint8_t asn1str_to_u8(ASN1String *as)
41{
42 if (as->len < 1)
43 return 0;
44 else
45 return *(uint8_t *)as->buf;
46}
47
48static inline uint8_t asn1bitstr_to_u32(ASN1BitString *as)
49{
50 if (as->len < 25)
51 return 0;
52 else
53 return *(uint32_t *)as->buf;
54}
55
56static int hnbgw_rx_hnb_register_req(struct hnb_context *ctx, struct HNBRegisterRequest *req)
Harald Welteba43de42015-08-29 20:33:16 +020057{
58 HNB_Identity *identity =
59 FIND_IE(req->protocolIEs, HNBAP_IEI_HNB_Identity);
60 HNB_Location_Information *loc =
61 FIND_IE(req->protocolIEs, HNBAP_IEI_HNB_Location_Information);
62 PLMNidentity *plmn_id =
63 FIND_IE(req->protocolIEs, HNBAP_IEI_PLMNidentity);
64 CellIdentity *cell_id =
65 FIND_IE(req->protocolIEs, HNBAP_IEI_CellIdentity);
66 LAC *lac = FIND_IE(req->protocolIEs, HNBAP_IEI_LAC);
67 RAC *rac = FIND_IE(req->protocolIEs, HNBAP_IEI_RAC);
68 SAC *sac = FIND_IE(req->protocolIEs, HNBAP_IEI_SAC);
69 /* Optional: CSG-ID */
70
71 if(!identity || !loc || !plmn_id || !cell_id || !lac || !rac || !sac)
72 return -1;
73
Harald Weltea2e6a7a2015-08-29 21:47:39 +020074 /* copy all identity parameters from the message to ctx */
75 strncpy(ctx->identity_info, sizeof(ctx->identity_info, identity_info->buf);
76 ctx->id.lac = asn1str_to_u16(lac);
77 ctx->id.sac = asn1str_to_u16(sac);
78 ctx->id.rac = asn1str_to_u8(rac);
79 ctx->id.cid = asn1bitstr_to_u32(cell_id);
80 ctx->id.mcc FIXME
81 ctx->id.mnc FIXME
82
Harald Welteba43de42015-08-29 20:33:16 +020083 /* FIXME: Send HNBRegisterAccept */
84}
85
Harald Weltea2e6a7a2015-08-29 21:47:39 +020086static int hnbgw_rx_ue_register_req(struct hnb_context *ctx, struct UERegisterRequest *req)
Harald Welteba43de42015-08-29 20:33:16 +020087{
88 UE_Identity *id =
89 FIND_IE(req->protocolIEs, HNBAP_IEI_UE_Identity);
90 Registration_Cause *reg_cause =
91 FIND_IE(req->protocolIEs, HNBAP_IEI_RegistrationCause);
92 UE_Capabilities *ue_cap =
93 FIND_IE(req->protocolIEs, HNBAP_IEI_UE_Capabilities);
94
95 if (!id || !reg_cause || !ue_cap)
96 return -1;
97
98 /* FIXME: Send UERegisterAccept */
99}
100
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200101static int hnbgw_rx_initiating_msg(struct hnb_context *hnb, struct InitiatingMessage *msg)
Harald Welteba43de42015-08-29 20:33:16 +0200102{
103 int rc;
104
105 switch (msg->procedureCode) {
106 case HNBAP_PC_HNBRegister: /* 8.2 */
107 if (msg->value.type != asn1_type_HNBRegisterRequest)
108 return -1;
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200109 rc = hnbgw_rx_hnb_register_req(hnb, FIXME);
Harald Welteba43de42015-08-29 20:33:16 +0200110 break;
111 case HNBAP_PC_HNBDe_Register: /* 8.3 */
112 break;
113 case HNBAP_PC_UERegister: /* 8.4 */
114 if (msg->value.type != asn1_type_UERegisterRequest)
115 return -1;
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200116 rc = hnbgw_rx_ue_register_req(hnb, FIXME);
Harald Welteba43de42015-08-29 20:33:16 +0200117 break;
118 case HNBAP_PC_UEDe_Register: /* 8.5 */
119 break;
120 case HNBAP_PC_ErrorIndication: /* 8.6 */
121 case HNBAP_PC_TNLUpdate: /* 8.9 */
122 case HNBAP_PC_HNBConfigTransfer: /* 8.10 */
123 case HNBAP_PC_RelocationComplete: /* 8.11 */
124 case HNBAP_PC_U_RNTIQuery: /* 8.12 */
125 case HNBAP_PC_privateMessage:
126 break;
127 default:
128 break;
129 }
130}
131
132static int hnbgw_rx_successful_outcome_msg(struct SuccessfulOutcome *msg)
133{
134
135}
136
137static int hnbgw_rx_unsuccessful_outcome_msg(struct UnsuccessfulOutcome *msg)
138{
139
140}
141
142
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200143static int _hnbgw_hnbap_rx(struct hnb_context *hnb, struct HNBAP_PDU *pdu)
Harald Welteba43de42015-08-29 20:33:16 +0200144{
145 /* it's a bit odd that we can't dispatch on procedure code, but
146 * that's not possible */
147 switch (pdu->choice) {
148 case HNBAP_PDU_initiatingMessage:
149 rc = hnbgw_rx_initiating_msg(&pdu->u.initiatingMessage);
150 break;
151 case HNBAP_PDU_successfulOutcome:
152 rc = hnbgw_rx_successful_outcome_msg(&pdu->u.successfulOutcome);
153 break;
154 case HNBAP_PDU_unsuccessfulOutcome:
155 rc = hnbgw_rx_unsuccessful_outcome_msg(&pdu->u.unsuccessfulOutcome);
156 break;
157 default:
158 return -1;
159 }
160}
161
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200162int hnbgw_hnbap_rx(struct hnb_context *hnb, struct msgb *msg)
Harald Welteba43de42015-08-29 20:33:16 +0200163{
164 /* FIXME: decode and handle to _hnbgw_hnbap_rx() */
165}
166
167
168int hnbgw_hnbap_init(void)
169{
170
171}