laforge has uploaded this change for review.
Introduce umts_cell_id_from_str() as inverse of umts_cell_id_name()
We are about to introduce the stringified UMTS cell identifier to the
VTY, and for that we need to not only print but also parse the related
string.
Related: SYS#6773
Change-Id: I6da947d1f2316241e44e53bb6aaec4221cfaa2c0
---
M include/osmocom/hnbgw/hnbgw.h
M src/osmo-hnbgw/hnbgw.c
2 files changed, 41 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/04/36204/1
diff --git a/include/osmocom/hnbgw/hnbgw.h b/include/osmocom/hnbgw/hnbgw.h
index f4f7dc1..62b548c 100644
--- a/include/osmocom/hnbgw/hnbgw.h
+++ b/include/osmocom/hnbgw/hnbgw.h
@@ -79,6 +79,7 @@
uint32_t cid; /*!< Cell ID */
};
const char *umts_cell_id_name(const struct umts_cell_id *ucid);
+int umts_cell_id_from_str(struct umts_cell_id *ucid, const char *instr);
struct hnbgw_context_map;
diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c
index 8b00ecb..4fc4e3d 100644
--- a/src/osmo-hnbgw/hnbgw.c
+++ b/src/osmo-hnbgw/hnbgw.c
@@ -202,6 +202,32 @@
ucid->sac, ucid->cid);
}
+/* parse a string representation of an umts_cell_id into its decoded representation */
+int umts_cell_id_from_str(struct umts_cell_id *ucid, const char *instr)
+{
+ int rc = sscanf(instr, "%hu-%hu-L%hu-R%hu-S%hu-C%u", &ucid->mcc, &ucid->mnc, &ucid->lac, &ucid->rac, &ucid->sac, &ucid->cid);
+ if (rc < 0)
+ return -errno;
+
+ if (rc != 6)
+ return -EINVAL;
+
+ if (ucid->mcc > 999)
+ return -EINVAL;
+
+ if (ucid->mnc > 999)
+ return -EINVAL;
+
+ if (ucid->lac == 0 || ucid->lac == 0xffff)
+ return -EINVAL;
+
+ /* CellIdentity in the ASN.1 syntax is a bit-string of 28 bits length */
+ if (ucid->cid >= (1 << 28))
+ return -EINVAL;
+
+ return 0;
+}
+
const char *hnb_context_name(struct hnb_context *ctx)
{
char *result;
To view, visit change 36204. To unsubscribe, or for help writing mail filters, visit settings.