[ip.access] Parse cell global ID as part of BCCH info
diff --git a/openbsc/include/openbsc/abis_nm.h b/openbsc/include/openbsc/abis_nm.h
index a9bfcee..56f8e52 100644
--- a/openbsc/include/openbsc/abis_nm.h
+++ b/openbsc/include/openbsc/abis_nm.h
@@ -684,9 +684,18 @@
 	IPAC_BINF_CELL_ALLOC		= (1 << 2),
 };
 
+struct cell_global_id {
+	u_int16_t mcc;
+	u_int16_t mnc;
+	u_int16_t lac;
+	u_int16_t ci;
+};
+
 /* The BCCH info from an ip.access test, in host byte order
  * and already parsed... */
 struct ipac_bcch_info {
+	struct llist_head list;
+
 	u_int16_t info_type;
 	u_int8_t freq_qual;
 	u_int16_t arfcn;
@@ -696,7 +705,7 @@
 	u_int16_t frame_offset;
 	u_int32_t frame_nr_offset;
 	u_int8_t bsic;
-	u_int8_t cgi[7];
+	struct cell_global_id cgi;
 	u_int8_t ba_list_si2[16];
 	u_int8_t ba_list_si2bis[16];
 	u_int8_t ba_list_si2ter[16];
diff --git a/openbsc/src/abis_nm.c b/openbsc/src/abis_nm.c
index 3f4fabb..63fda92 100755
--- a/openbsc/src/abis_nm.c
+++ b/openbsc/src/abis_nm.c
@@ -2702,6 +2702,25 @@
 	return "unknown";
 }
 
+void ipac_parse_cgi(struct cell_global_id *cid, const u_int8_t *buf)
+{
+	cid->mcc = (buf[0] & 0xf) * 100;
+	cid->mcc += (buf[0] >> 4) *  10;
+	cid->mcc += (buf[1] & 0xf) *  1;
+
+	if (buf[1] >> 4 == 0xf) {
+		cid->mnc = (buf[2] & 0xf) * 10;
+		cid->mnc += (buf[2] >> 4) *  1;
+	} else {
+		cid->mnc = (buf[2] & 0xf) * 100;
+		cid->mnc += (buf[2] >> 4) *  10;
+		cid->mnc += (buf[1] >> 4) *   1;
+	}
+
+	cid->lac = ntohs(buf+3);
+	cid->ci = ntohs(buf+5);
+}
+
 /* parse BCCH information IEI from wire format to struct ipac_bcch_info */
 int ipac_parse_bcch_info(struct ipac_bcch_info *binf, u_int8_t *buf)
 {
@@ -2750,8 +2769,8 @@
 		binf->bsic = *cur++ & 0x3f;
 	cur++;
 
-	memcpy(binf->cgi, cur, sizeof(binf->cgi));
-	cur += sizeof(binf->cgi);
+	ipac_parse_cgi(&binf->cgi, cur);
+	cur += 7;
 
 	if (binf->info_type & IPAC_BINF_NEIGH_BA_SI2) {
 		memcpy(binf->ba_list_si2, cur, sizeof(binf->ba_list_si2));