aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
Diffstat (limited to 'openbsc')
-rw-r--r--openbsc/include/openbsc/gprs_utils.h12
-rw-r--r--openbsc/src/gprs/gprs_gb_parse.c56
-rw-r--r--openbsc/src/gprs/gprs_utils.c61
-rw-r--r--openbsc/src/gprs/oap_messages.c4
-rw-r--r--openbsc/src/gprs/osmo_gsup_messages.c12
5 files changed, 92 insertions, 53 deletions
diff --git a/openbsc/include/openbsc/gprs_utils.h b/openbsc/include/openbsc/gprs_utils.h
index 474eb45da..b5bee2b6a 100644
--- a/openbsc/include/openbsc/gprs_utils.h
+++ b/openbsc/include/openbsc/gprs_utils.h
@@ -42,15 +42,15 @@ int gprs_is_mi_imsi(const uint8_t *value, size_t value_len);
int gprs_parse_mi_tmsi(const uint8_t *value, size_t value_len, uint32_t *tmsi);
void gprs_parse_tmsi(const uint8_t *value, uint32_t *tmsi);
-int gprs_shift_v_fixed(uint8_t **data, size_t *data_len,
+int osmo_shift_v_fixed(uint8_t **data, size_t *data_len,
size_t len, uint8_t **value);
-int gprs_match_tv_fixed(uint8_t **data, size_t *data_len,
- uint8_t tag, size_t len, uint8_t **value);
-int gprs_shift_tlv(uint8_t **data, size_t *data_len,
+int osmo_match_shift_tv_fixed(uint8_t **data, size_t *data_len,
+ uint8_t tag, size_t len, uint8_t **value);
+int osmo_shift_tlv(uint8_t **data, size_t *data_len,
uint8_t *tag, uint8_t **value, size_t *value_len);
-int gprs_match_tlv(uint8_t **data, size_t *data_len,
+int osmo_match_shift_tlv(uint8_t **data, size_t *data_len,
uint8_t tag, uint8_t **value, size_t *value_len);
-int gprs_shift_lv(uint8_t **data, size_t *data_len,
+int osmo_shift_lv(uint8_t **data, size_t *data_len,
uint8_t **value, size_t *value_len);
int gprs_ra_id_equals(const struct gprs_ra_id *id1, const struct gprs_ra_id *id2);
diff --git a/openbsc/src/gprs/gprs_gb_parse.c b/openbsc/src/gprs/gprs_gb_parse.c
index 5ec3cf6ea..f11d93aef 100644
--- a/openbsc/src/gprs/gprs_gb_parse.c
+++ b/openbsc/src/gprs/gprs_gb_parse.c
@@ -38,7 +38,7 @@ static int gprs_gb_parse_gmm_attach_req(uint8_t *data, size_t data_len,
parse_ctx->llc_msg_name = "ATTACH_REQ";
/* Skip MS network capability */
- if (gprs_shift_lv(&data, &data_len, NULL, &value_len) <= 0 ||
+ if (osmo_shift_lv(&data, &data_len, NULL, &value_len) <= 0 ||
value_len < 1 || value_len > 8)
/* invalid */
return 0;
@@ -46,10 +46,10 @@ static int gprs_gb_parse_gmm_attach_req(uint8_t *data, size_t data_len,
/* Skip Attach type */
/* Skip Ciphering key sequence number */
/* Skip DRX parameter */
- gprs_shift_v_fixed(&data, &data_len, 3, NULL);
+ osmo_shift_v_fixed(&data, &data_len, 3, NULL);
/* Get Mobile identity */
- if (gprs_shift_lv(&data, &data_len, &value, &value_len) <= 0 ||
+ if (osmo_shift_lv(&data, &data_len, &value, &value_len) <= 0 ||
value_len < 5 || value_len > 8)
/* invalid */
return 0;
@@ -61,7 +61,7 @@ static int gprs_gb_parse_gmm_attach_req(uint8_t *data, size_t data_len,
parse_ctx->imsi_len = value_len;
}
- if (gprs_shift_v_fixed(&data, &data_len, 6, &value) <= 0)
+ if (osmo_shift_v_fixed(&data, &data_len, 6, &value) <= 0)
return 0;
parse_ctx->old_raid_enc = value;
@@ -82,21 +82,21 @@ static int gprs_gb_parse_gmm_attach_ack(uint8_t *data, size_t data_len,
/* Skip Periodic RA update timer */
/* Skip Radio priority for SMS */
/* Skip Spare half octet */
- gprs_shift_v_fixed(&data, &data_len, 3, NULL);
+ osmo_shift_v_fixed(&data, &data_len, 3, NULL);
- if (gprs_shift_v_fixed(&data, &data_len, 6, &value) <= 0)
+ if (osmo_shift_v_fixed(&data, &data_len, 6, &value) <= 0)
return 0;
parse_ctx->raid_enc = value;
/* Skip P-TMSI signature (P-TMSI signature, opt, TV, length 4) */
- gprs_match_tv_fixed(&data, &data_len, GSM48_IE_GMM_PTMSI_SIG, 3, NULL);
+ osmo_match_shift_tv_fixed(&data, &data_len, GSM48_IE_GMM_PTMSI_SIG, 3, NULL);
/* Skip Negotiated READY timer value (GPRS timer, opt, TV, length 2) */
- gprs_match_tv_fixed(&data, &data_len, GSM48_IE_GMM_TIMER_READY, 1, NULL);
+ osmo_match_shift_tv_fixed(&data, &data_len, GSM48_IE_GMM_TIMER_READY, 1, NULL);
/* Allocated P-TMSI (Mobile identity, opt, TLV, length 7) */
- if (gprs_match_tlv(&data, &data_len, GSM48_IE_GMM_ALLOC_PTMSI,
+ if (osmo_match_shift_tlv(&data, &data_len, GSM48_IE_GMM_ALLOC_PTMSI,
&value, &value_len) > 0 &&
gprs_is_mi_tmsi(value, value_len))
parse_ctx->new_ptmsi_enc = value + 1;
@@ -111,7 +111,7 @@ static int gprs_gb_parse_gmm_attach_rej(uint8_t *data, size_t data_len,
parse_ctx->llc_msg_name = "ATTACH_REJ";
/* GMM cause */
- if (gprs_shift_v_fixed(&data, &data_len, 1, &value) <= 0)
+ if (osmo_shift_v_fixed(&data, &data_len, 1, &value) <= 0)
return 0;
parse_ctx->invalidate_tlli = 1;
@@ -132,7 +132,7 @@ static int gprs_gb_parse_gmm_detach_req(uint8_t *data, size_t data_len,
/* Skip spare half octet */
/* Get Detach type */
- if (gprs_shift_v_fixed(&data, &data_len, 1, &value) <= 0)
+ if (osmo_shift_v_fixed(&data, &data_len, 1, &value) <= 0)
/* invalid */
return 0;
@@ -150,7 +150,7 @@ static int gprs_gb_parse_gmm_detach_req(uint8_t *data, size_t data_len,
parse_ctx->invalidate_tlli = 1;
/* Get P-TMSI (Mobile identity), see GSM 24.008, 9.4.5.2 */
- if (gprs_match_tlv(&data, &data_len,
+ if (osmo_match_shift_tlv(&data, &data_len,
GSM48_IE_GMM_ALLOC_PTMSI, &value, &value_len) > 0)
{
if (gprs_is_mi_tmsi(value, value_len))
@@ -170,9 +170,9 @@ static int gprs_gb_parse_gmm_ra_upd_req(uint8_t *data, size_t data_len,
/* Skip Update type */
/* Skip GPRS ciphering key sequence number */
- gprs_shift_v_fixed(&data, &data_len, 1, NULL);
+ osmo_shift_v_fixed(&data, &data_len, 1, NULL);
- if (gprs_shift_v_fixed(&data, &data_len, 6, &value) <= 0)
+ if (osmo_shift_v_fixed(&data, &data_len, 6, &value) <= 0)
return 0;
parse_ctx->old_raid_enc = value;
@@ -190,14 +190,14 @@ static int gprs_gb_parse_gmm_ra_upd_rej(uint8_t *data, size_t data_len,
parse_ctx->llc_msg_name = "RA_UPD_REJ";
/* GMM cause */
- if (gprs_shift_v_fixed(&data, &data_len, 1, &value) <= 0)
+ if (osmo_shift_v_fixed(&data, &data_len, 1, &value) <= 0)
return 0;
cause = value[0];
/* Force to standby, 1/2 */
/* spare bits, 1/2 */
- if (gprs_shift_v_fixed(&data, &data_len, 1, &value) <= 0)
+ if (osmo_shift_v_fixed(&data, &data_len, 1, &value) <= 0)
return 0;
force_standby = (value[0] & 0x07) == 0x01;
@@ -221,18 +221,18 @@ static int gprs_gb_parse_gmm_ra_upd_ack(uint8_t *data, size_t data_len,
/* Skip Force to standby */
/* Skip Update result */
/* Skip Periodic RA update timer */
- gprs_shift_v_fixed(&data, &data_len, 2, NULL);
+ osmo_shift_v_fixed(&data, &data_len, 2, NULL);
- if (gprs_shift_v_fixed(&data, &data_len, 6, &value) <= 0)
+ if (osmo_shift_v_fixed(&data, &data_len, 6, &value) <= 0)
return 0;
parse_ctx->raid_enc = value;
/* Skip P-TMSI signature (P-TMSI signature, opt, TV, length 4) */
- gprs_match_tv_fixed(&data, &data_len, GSM48_IE_GMM_PTMSI_SIG, 3, NULL);
+ osmo_match_shift_tv_fixed(&data, &data_len, GSM48_IE_GMM_PTMSI_SIG, 3, NULL);
/* Allocated P-TMSI (Mobile identity, opt, TLV, length 7) */
- if (gprs_match_tlv(&data, &data_len, GSM48_IE_GMM_ALLOC_PTMSI,
+ if (osmo_match_shift_tlv(&data, &data_len, GSM48_IE_GMM_ALLOC_PTMSI,
&value, &value_len) > 0 &&
gprs_is_mi_tmsi(value, value_len))
parse_ctx->new_ptmsi_enc = value + 1;
@@ -252,11 +252,11 @@ static int gprs_gb_parse_gmm_ptmsi_reall_cmd(uint8_t *data, size_t data_len,
"Got P-TMSI Reallocation Command which is not covered by unit tests yet.\n");
/* Allocated P-TMSI */
- if (gprs_shift_lv(&data, &data_len, &value, &value_len) > 0 &&
+ if (osmo_shift_lv(&data, &data_len, &value, &value_len) > 0 &&
gprs_is_mi_tmsi(value, value_len))
parse_ctx->new_ptmsi_enc = value + 1;
- if (gprs_shift_v_fixed(&data, &data_len, 6, &value) <= 0)
+ if (osmo_shift_v_fixed(&data, &data_len, 6, &value) <= 0)
return 0;
parse_ctx->raid_enc = value;
@@ -273,7 +273,7 @@ static int gprs_gb_parse_gmm_id_resp(uint8_t *data, size_t data_len,
parse_ctx->llc_msg_name = "ID_RESP";
/* Mobile identity, Mobile identity 10.5.1.4, M LV 2-10 */
- if (gprs_shift_lv(&data, &data_len, &value, &value_len) <= 0 ||
+ if (osmo_shift_lv(&data, &data_len, &value, &value_len) <= 0 ||
value_len < 1 || value_len > 9)
/* invalid */
return 0;
@@ -299,22 +299,22 @@ static int gprs_gb_parse_gsm_act_pdp_req(uint8_t *data, size_t data_len,
/* Skip Requested NSAPI */
/* Skip Requested LLC SAPI */
- gprs_shift_v_fixed(&data, &data_len, 2, NULL);
+ osmo_shift_v_fixed(&data, &data_len, 2, NULL);
/* Skip Requested QoS (support 04.08 and 24.008) */
- if (gprs_shift_lv(&data, &data_len, NULL, &value_len) <= 0 ||
+ if (osmo_shift_lv(&data, &data_len, NULL, &value_len) <= 0 ||
value_len < 4 || value_len > 14)
/* invalid */
return 0;
/* Skip Requested PDP address */
- if (gprs_shift_lv(&data, &data_len, NULL, &value_len) <= 0 ||
+ if (osmo_shift_lv(&data, &data_len, NULL, &value_len) <= 0 ||
value_len < 2 || value_len > 18)
/* invalid */
return 0;
/* Access point name */
- old_len = gprs_match_tlv(&data, &data_len,
+ old_len = osmo_match_shift_tlv(&data, &data_len,
GSM48_IE_GSM_APN, &value, &value_len);
if (old_len > 0 && value_len >=1 && value_len <= 100) {
@@ -332,7 +332,7 @@ int gprs_gb_parse_dtap(uint8_t *data, size_t data_len,
uint8_t pdisc;
uint8_t msg_type;
- if (gprs_shift_v_fixed(&data, &data_len, sizeof(*g48h), (uint8_t **)&g48h) <= 0)
+ if (osmo_shift_v_fixed(&data, &data_len, sizeof(*g48h), (uint8_t **)&g48h) <= 0)
return 0;
parse_ctx->g48_hdr = g48h;
diff --git a/openbsc/src/gprs/gprs_utils.c b/openbsc/src/gprs/gprs_utils.c
index 64bfd743d..7ed8c3f19 100644
--- a/openbsc/src/gprs/gprs_utils.c
+++ b/openbsc/src/gprs/gprs_utils.c
@@ -268,8 +268,15 @@ void gprs_parse_tmsi(const uint8_t *value, uint32_t *tmsi)
/* TODO: Move shift functions to libosmocore */
-int gprs_shift_v_fixed(uint8_t **data, size_t *data_len,
- size_t len, uint8_t **value)
+/*! Advance the data pointer, subtract length and assign value pointer
+ * \param data pointer to the pointer to data
+ * \param data_len pointer to size_t containing \arg data length
+ * \param[in] len the length that we expect the fixed IE to hav
+ * \param[out] value pointer to pointer of value part of IE
+ * \returns length of IE value; negative in case of error
+ */
+int osmo_shift_v_fixed(uint8_t **data, size_t *data_len,
+ size_t len, uint8_t **value)
{
if (len > *data_len)
goto fail;
@@ -288,9 +295,17 @@ fail:
return -1;
}
-int gprs_match_tv_fixed(uint8_t **data, size_t *data_len,
- uint8_t tag, size_t len,
- uint8_t **value)
+/*! Match tag, check length and assign value pointer
+ * \param data pointer to the pointer to data
+ * \param data_len pointer to size_t containing \arg data length
+ * \param[in] tag the tag (IEI) that we expect at \arg data
+ * \param[in] len the length that we expect the fixed IE to have
+ * \param[out] value pointer to pointer of value part of IE
+ * \returns length of IE value; negative in case of error
+ */
+int osmo_match_shift_tv_fixed(uint8_t **data, size_t *data_len,
+ uint8_t tag, size_t len,
+ uint8_t **value)
{
size_t ie_len;
@@ -318,15 +333,24 @@ fail:
return -1;
}
-int gprs_match_tlv(uint8_t **data, size_t *data_len,
- uint8_t expected_tag, uint8_t **value, size_t *value_len)
+/*! Verify TLV header and advance data / subtract length
+ * \param data pointer to the pointer to data
+ * \param data_len pointer to size_t containing \arg data length
+ * \param[in] expected_tag the tag (IEI) that we expect at \arg data
+ * \param[out] value pointer to pointer of value part of IE
+ * \param[out] value_len pointer to length of \arg value
+ * \returns length of IE value; negative in case of error
+ */
+int osmo_match_shift_tlv(uint8_t **data, size_t *data_len,
+ uint8_t expected_tag, uint8_t **value,
+ size_t *value_len)
{
int rc;
uint8_t tag;
uint8_t *old_data = *data;
size_t old_data_len = *data_len;
- rc = gprs_shift_tlv(data, data_len, &tag, value, value_len);
+ rc = osmo_shift_tlv(data, data_len, &tag, value, value_len);
if (rc > 0 && tag != expected_tag) {
*data = old_data;
@@ -337,7 +361,15 @@ int gprs_match_tlv(uint8_t **data, size_t *data_len,
return rc;
}
-int gprs_shift_tlv(uint8_t **data, size_t *data_len,
+/*! Extract TLV and advance data pointer + subtract length
+ * \param data pointer to the pointer to data
+ * \param data_len pointer to size_t containing \arg data lengt
+ * \param[out] tag extract the tag (IEI) at start of \arg data
+ * \param[out] value extracted pointer to value part of TLV
+ * \param[out] value_len extracted length of \arg value
+ * \returns number of bytes subtracted
+ */
+int osmo_shift_tlv(uint8_t **data, size_t *data_len,
uint8_t *tag, uint8_t **value, size_t *value_len)
{
size_t len;
@@ -370,8 +402,15 @@ fail:
return -1;
}
-int gprs_shift_lv(uint8_t **data, size_t *data_len,
- uint8_t **value, size_t *value_len)
+/*! Extract LV and advance data pointer + subtract length
+ * \param data pointer to the pointer to data
+ * \param data_len pointer to size_t containing \arg data lengt
+ * \param[out] value extracted pointer to value part of TLV
+ * \param[out] value_len extracted length of \arg value
+ * \returns number of bytes subtracted
+ */
+int osmo_shift_lv(uint8_t **data, size_t *data_len,
+ uint8_t **value, size_t *value_len)
{
size_t len;
size_t ie_len;
diff --git a/openbsc/src/gprs/oap_messages.c b/openbsc/src/gprs/oap_messages.c
index eb520532a..49b54e439 100644
--- a/openbsc/src/gprs/oap_messages.c
+++ b/openbsc/src/gprs/oap_messages.c
@@ -48,7 +48,7 @@ int oap_decode(const uint8_t *const_data, size_t data_len,
memset(oap_msg, 0, sizeof(*oap_msg));
/* message type */
- rc = gprs_shift_v_fixed(&data, &data_len, 1, &value);
+ rc = osmo_shift_v_fixed(&data, &data_len, 1, &value);
if (rc < 0)
return -GMM_CAUSE_INV_MAND_INFO;
oap_msg->message_type = decode_big_endian(value, 1);
@@ -57,7 +57,7 @@ int oap_decode(const uint8_t *const_data, size_t data_len,
while (data_len > 0) {
enum oap_iei iei;
- rc = gprs_shift_tlv(&data, &data_len, &tag, &value, &value_len);
+ rc = osmo_shift_tlv(&data, &data_len, &tag, &value, &value_len);
if (rc < 0)
return -GMM_CAUSE_PROTO_ERR_UNSPEC;
diff --git a/openbsc/src/gprs/osmo_gsup_messages.c b/openbsc/src/gprs/osmo_gsup_messages.c
index 00ada5b24..94eae35b9 100644
--- a/openbsc/src/gprs/osmo_gsup_messages.c
+++ b/openbsc/src/gprs/osmo_gsup_messages.c
@@ -26,7 +26,7 @@
#include <openbsc/osmo_gsup_messages.h>
#include <openbsc/debug.h>
-//#include <openbsc/gprs_utils.h>
+#include <openbsc/gprs_utils.h>
#include <openbsc/utils.h>
#include <osmocom/gsm/tlv.h>
@@ -47,7 +47,7 @@ static int decode_pdp_info(uint8_t *data, size_t data_len,
while (data_len > 0) {
enum osmo_gsup_iei iei;
- rc = gprs_shift_tlv(&data, &data_len, &tag, &value, &value_len);
+ rc = osmo_shift_tlv(&data, &data_len, &tag, &value, &value_len);
if (rc < 0)
return -GMM_CAUSE_PROTO_ERR_UNSPEC;
@@ -94,7 +94,7 @@ static int decode_auth_info(uint8_t *data, size_t data_len,
/* specific parts */
while (data_len > 0) {
- rc = gprs_shift_tlv(&data, &data_len, &tag, &value, &value_len);
+ rc = osmo_shift_tlv(&data, &data_len, &tag, &value, &value_len);
if (rc < 0)
return -GMM_CAUSE_PROTO_ERR_UNSPEC;
@@ -157,13 +157,13 @@ int osmo_gsup_decode(const uint8_t *const_data, size_t data_len,
*gsup_msg = empty_gsup_message;
/* generic part */
- rc = gprs_shift_v_fixed(&data, &data_len, 1, &value);
+ rc = osmo_shift_v_fixed(&data, &data_len, 1, &value);
if (rc < 0)
return -GMM_CAUSE_INV_MAND_INFO;
gsup_msg->message_type = decode_big_endian(value, 1);
- rc = gprs_match_tlv(&data, &data_len, OSMO_GSUP_IMSI_IE,
+ rc = osmo_match_shift_tlv(&data, &data_len, OSMO_GSUP_IMSI_IE,
&value, &value_len);
if (rc <= 0)
@@ -187,7 +187,7 @@ int osmo_gsup_decode(const uint8_t *const_data, size_t data_len,
struct osmo_gsup_pdp_info pdp_info;
struct osmo_auth_vector auth_info;
- rc = gprs_shift_tlv(&data, &data_len, &tag, &value, &value_len);
+ rc = osmo_shift_tlv(&data, &data_len, &tag, &value, &value_len);
if (rc < 0)
return -GMM_CAUSE_PROTO_ERR_UNSPEC;