blob: 5100bf549a496a28e74dafe55e68313fb4e49cae [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>
Harald Welteee77cff2015-08-30 16:57:53 +02005#include <errno.h>
Harald Welteb3dae302015-08-30 12:20:09 +02006#include <string.h>
7
Harald Welte30afef32015-08-30 12:28:29 +02008#include "asn1helpers.h"
9
Harald Welteba43de42015-08-29 20:33:16 +020010#include "hnbgw.h"
Harald Welte27f9c4a2015-08-30 22:47:18 +020011#include "hnbap_common.h"
12#include "hnbap_ies_defs.h"
Harald Welteba43de42015-08-29 20:33:16 +020013
Harald Welteee77cff2015-08-30 16:57:53 +020014#define IU_MSG_NUM_IES 32
15#define IU_MSG_NUM_EXT_IES 32
16
Harald Welte27f9c4a2015-08-30 22:47:18 +020017static int hnbgw_hnbap_tx(struct hnb_context *ctx, struct msgb *msg)
Harald Welteee77cff2015-08-30 16:57:53 +020018{
Harald Welte27f9c4a2015-08-30 22:47:18 +020019 /* FIXME */
20}
Harald Welteee77cff2015-08-30 16:57:53 +020021
Harald Welte27f9c4a2015-08-30 22:47:18 +020022static 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 Welteee77cff2015-08-30 16:57:53 +020037 }
38
Harald Welte27f9c4a2015-08-30 22:47:18 +020039 /* 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 Welteee77cff2015-08-30 16:57:53 +020044
Harald Welte27f9c4a2015-08-30 22:47:18 +020045 return hnbgw_hnbap_tx(ctx, msg);
Harald Welteee77cff2015-08-30 16:57:53 +020046}
47
48
Harald Welte27f9c4a2015-08-30 22:47:18 +020049static int hnbgw_tx_ue_register_acc(struct ue_context *ue)
Harald Welteba43de42015-08-29 20:33:16 +020050{
Harald Welte27f9c4a2015-08-30 22:47:18 +020051 UERegisterAccept_t accept_out;
52 UERegisterAcceptIEs_t accept;
53 struct msgb *msg;
54 int rc;
Harald Welteba43de42015-08-29 20:33:16 +020055
Harald Welte27f9c4a2015-08-30 22:47:18 +020056 /* FIXME accept.uE_Identity; */
57 asn1_u32_to_bitstring(&accept.context_ID, &ue->context_id);
Harald Welteba43de42015-08-29 20:33:16 +020058
Harald Welte27f9c4a2015-08-30 22:47:18 +020059 rc = hnbap_encode_ueregisteraccepties(&accept_out, &accept);
60 if (rc < 0) {
61 return rc;
Harald Welteba43de42015-08-29 20:33:16 +020062 }
Harald Welte27f9c4a2015-08-30 22:47:18 +020063
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 Welteba43de42015-08-29 20:33:16 +020069}
70
Harald Welte27f9c4a2015-08-30 22:47:18 +020071static int hnbgw_rx_hnb_register_req(struct hnb_context *ctx, ANY_t *in)
Harald Welteba43de42015-08-29 20:33:16 +020072{
Harald Welte27f9c4a2015-08-30 22:47:18 +020073 HNBRegisterRequestIEs_t ies;
74 int rc;
Harald Welteba43de42015-08-29 20:33:16 +020075
Harald Welte27f9c4a2015-08-30 22:47:18 +020076 rc = hnbap_decode_hnbregisterrequesties(&ies, in);
77 if (rc < 0)
78 return rc;
Harald Welteba43de42015-08-29 20:33:16 +020079
Harald Weltea2e6a7a2015-08-29 21:47:39 +020080 /* copy all identity parameters from the message to ctx */
Harald Welte27f9c4a2015-08-30 22:47:18 +020081 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 Welteb3dae302015-08-30 12:20:09 +020087 //ctx->id.mcc FIXME
88 //ctx->id.mnc FIXME
Harald Weltea2e6a7a2015-08-29 21:47:39 +020089
Harald Welteee77cff2015-08-30 16:57:53 +020090 DEBUGP(DMAIN, "HNB-REGISTER-REQ from %s\n", ctx->identity_info);
91
Harald Welte27f9c4a2015-08-30 22:47:18 +020092 /* Send HNBRegisterAccept */
93 return hnbgw_tx_hnb_register_acc(ctx);
Harald Welteba43de42015-08-29 20:33:16 +020094}
95
Harald Welte27f9c4a2015-08-30 22:47:18 +020096static int hnbgw_rx_ue_register_req(struct hnb_context *ctx, ANY_t *in)
Harald Welteba43de42015-08-29 20:33:16 +020097{
Harald Welte27f9c4a2015-08-30 22:47:18 +020098 UERegisterRequestIEs_t ies;
99 struct ue_context *ue;
100 int rc;
Harald Welteba43de42015-08-29 20:33:16 +0200101
Harald Welte27f9c4a2015-08-30 22:47:18 +0200102 rc = hnbap_decode_ueregisterrequesties(&ies, in);
103 if (rc < 0)
104 return rc;
Harald Welteba43de42015-08-29 20:33:16 +0200105
Harald Welte27f9c4a2015-08-30 22:47:18 +0200106 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 Welteba43de42015-08-29 20:33:16 +0200113}
114
Harald Welte27f9c4a2015-08-30 22:47:18 +0200115static int hnbgw_rx_initiating_msg(struct hnb_context *hnb, InitiatingMessage_t *imsg)
Harald Welteba43de42015-08-29 20:33:16 +0200116{
117 int rc;
118
Harald Welteb3dae302015-08-30 12:20:09 +0200119 switch (imsg->procedureCode) {
Harald Welte27f9c4a2015-08-30 22:47:18 +0200120 case ProcedureCode_id_HNBRegister: /* 8.2 */
121 rc = hnbgw_rx_hnb_register_req(hnb, &imsg->value);
Harald Welteba43de42015-08-29 20:33:16 +0200122 break;
Harald Welte27f9c4a2015-08-30 22:47:18 +0200123 case ProcedureCode_id_HNBDe_Register: /* 8.3 */
Harald Welteba43de42015-08-29 20:33:16 +0200124 break;
Harald Welte27f9c4a2015-08-30 22:47:18 +0200125 case ProcedureCode_id_UERegister: /* 8.4 */
126 rc = hnbgw_rx_ue_register_req(hnb, &imsg->value);
Harald Welteba43de42015-08-29 20:33:16 +0200127 break;
Harald Welte27f9c4a2015-08-30 22:47:18 +0200128 case ProcedureCode_id_UEDe_Register: /* 8.5 */
Harald Welteba43de42015-08-29 20:33:16 +0200129 break;
Harald Welte27f9c4a2015-08-30 22:47:18 +0200130 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 Welteba43de42015-08-29 20:33:16 +0200136 break;
137 default:
138 break;
139 }
140}
141
Harald Welte27f9c4a2015-08-30 22:47:18 +0200142static int hnbgw_rx_successful_outcome_msg(struct hnb_context *hnb, SuccessfulOutcome_t *msg)
Harald Welteba43de42015-08-29 20:33:16 +0200143{
144
145}
146
Harald Welte27f9c4a2015-08-30 22:47:18 +0200147static int hnbgw_rx_unsuccessful_outcome_msg(struct hnb_context *hnb, UnsuccessfulOutcome_t *msg)
Harald Welteba43de42015-08-29 20:33:16 +0200148{
149
150}
151
152
Harald Welte27f9c4a2015-08-30 22:47:18 +0200153static int _hnbgw_hnbap_rx(struct hnb_context *hnb, HNBAP_PDU_t *pdu)
Harald Welteba43de42015-08-29 20:33:16 +0200154{
Harald Welteb3dae302015-08-30 12:20:09 +0200155 int rc;
156
Harald Welteba43de42015-08-29 20:33:16 +0200157 /* it's a bit odd that we can't dispatch on procedure code, but
158 * that's not possible */
Harald Welte27f9c4a2015-08-30 22:47:18 +0200159 switch (pdu->present) {
160 case HNBAP_PDU_PR_initiatingMessage:
161 rc = hnbgw_rx_initiating_msg(hnb, &pdu->choice.initiatingMessage);
Harald Welteba43de42015-08-29 20:33:16 +0200162 break;
Harald Welte27f9c4a2015-08-30 22:47:18 +0200163 case HNBAP_PDU_PR_successfulOutcome:
164 rc = hnbgw_rx_successful_outcome_msg(hnb, &pdu->choice.successfulOutcome);
Harald Welteba43de42015-08-29 20:33:16 +0200165 break;
Harald Welte27f9c4a2015-08-30 22:47:18 +0200166 case HNBAP_PDU_PR_unsuccessfulOutcome:
167 rc = hnbgw_rx_unsuccessful_outcome_msg(hnb, &pdu->choice.unsuccessfulOutcome);
Harald Welteba43de42015-08-29 20:33:16 +0200168 break;
169 default:
170 return -1;
171 }
172}
173
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200174int hnbgw_hnbap_rx(struct hnb_context *hnb, struct msgb *msg)
Harald Welteba43de42015-08-29 20:33:16 +0200175{
Harald Welte27f9c4a2015-08-30 22:47:18 +0200176 HNBAP_PDU_t _pdu, *pdu = &_pdu;
177 asn_dec_rval_t dec_ret;
Harald Welteee77cff2015-08-30 16:57:53 +0200178 int rc;
179
180 /* decode and handle to _hnbgw_hnbap_rx() */
181
Harald Welte27f9c4a2015-08-30 22:47:18 +0200182 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 Welteee77cff2015-08-30 16:57:53 +0200186 return rc;
187 }
188
189 rc = _hnbgw_hnbap_rx(hnb, pdu);
Harald Welteee77cff2015-08-30 16:57:53 +0200190
191 return rc;
Harald Welteba43de42015-08-29 20:33:16 +0200192}
193
194
195int hnbgw_hnbap_init(void)
196{
197
198}