laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/22013 )

Change subject: Intoduce Packet Switch CGI
......................................................................

Intoduce Packet Switch CGI

This structure is needed in order to identify a given cell within the
BSS during RIM transactions.
The naming was made up by myself since I couldn't find any naming
reference for this kind of data (RAI + CI).
Since LAI + CI = CGI, then RAI + CI = CGI-PS

osmo_rai_name2 family of functions get a "2" suffix due to already
existing functions handling struct struct gprs_ra_id in gsm48.h

Change-Id: If48f412c32e8e5a3e604a78d12b74787a4786374
---
M include/osmocom/gsm/gsm0808_utils.h
M include/osmocom/gsm/gsm23003.h
M include/osmocom/gsm/protocol/gsm_08_08.h
M src/gsm/gsm0808_utils.c
M src/gsm/gsm23003.c
M src/gsm/libosmogsm.map
6 files changed, 136 insertions(+), 0 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  dexter: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/include/osmocom/gsm/gsm0808_utils.h 
b/include/osmocom/gsm/gsm0808_utils.h
index 59db6ed..76e9064 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -44,6 +44,7 @@
        uint16_t                                ci;
        struct osmo_location_area_id            lai_and_lac;
        uint16_t                                lac;
+       struct osmo_cell_global_id_ps           global_ps;
 };

 /*! Parsed representation of Cell Identifier IE (3GPP TS 48.008 3.2.2.17) */
diff --git a/include/osmocom/gsm/gsm23003.h b/include/osmocom/gsm/gsm23003.h
index 69f00f6..fbe0ca0 100644
--- a/include/osmocom/gsm/gsm23003.h
+++ b/include/osmocom/gsm/gsm23003.h
@@ -30,6 +30,11 @@
        uint16_t cell_identity;
 };

+struct osmo_cell_global_id_ps {
+       struct osmo_routing_area_id rai;
+       uint16_t cell_identity;
+};
+
 /*! Bitmask of items contained in a struct osmo_cell_global_id.
  * See also gsm0808_cell_id_to_cgi().
  */
@@ -37,6 +42,7 @@
        OSMO_CGI_PART_PLMN = 1,
        OSMO_CGI_PART_LAC = 2,
        OSMO_CGI_PART_CI = 4,
+       OSMO_CGI_PART_RAC = 8,
 };

 /* Actually defined in 3GPP TS 48.008 3.2.2.27 Cell Identifier List,
@@ -117,10 +123,17 @@
 const char *osmo_lai_name(const struct osmo_location_area_id *lai);
 char *osmo_lai_name_buf(char *buf, size_t buf_len, const struct 
osmo_location_area_id *lai);
 char *osmo_lai_name_c(const void *ctx, const struct osmo_location_area_id 
*lai);
+const char *osmo_rai_name2(const struct osmo_routing_area_id *rai);
+char *osmo_rai_name2_buf(char *buf, size_t buf_len, const struct 
osmo_routing_area_id *rai);
+char *osmo_rai_name2_c(const void *ctx, const struct osmo_routing_area_id 
*rai);
 const char *osmo_cgi_name(const struct osmo_cell_global_id *cgi);
 const char *osmo_cgi_name2(const struct osmo_cell_global_id *cgi);
 char *osmo_cgi_name_buf(char *buf, size_t buf_len, const struct 
osmo_cell_global_id *cgi);
 char *osmo_cgi_name_c(const void *ctx, const struct osmo_cell_global_id *cgi);
+const char *osmo_cgi_ps_name(const struct osmo_cell_global_id_ps *cgi_ps);
+const char *osmo_cgi_ps_name2(const struct osmo_cell_global_id_ps *cgi_ps);
+char *osmo_cgi_ps_name_buf(char *buf, size_t buf_len, const struct 
osmo_cell_global_id_ps *cgi_ps);
+char *osmo_cgi_ps_name_c(const void *ctx, const struct osmo_cell_global_id_ps 
*cgi_ps);
 const char *osmo_gummei_name(const struct osmo_gummei *gummei);
 char *osmo_gummei_name_buf(char *buf, size_t buf_len, const struct osmo_gummei 
*gummei);
 char *osmo_gummei_name_c(const void *ctx, const struct osmo_gummei *gummei);
diff --git a/include/osmocom/gsm/protocol/gsm_08_08.h 
b/include/osmocom/gsm/protocol/gsm_08_08.h
index 1390f0e..fe7776b 100644
--- a/include/osmocom/gsm/protocol/gsm_08_08.h
+++ b/include/osmocom/gsm/protocol/gsm_08_08.h
@@ -25,6 +25,9 @@
        CELL_IDENT_UTRAN_PLMN_LAC_RNC   = 8,
        CELL_IDENT_UTRAN_RNC            = 9,
        CELL_IDENT_UTRAN_LAC_RNC        = 10,
+
+       /* Not in 03.03 nor 08.08 */
+       CELL_IDENT_WHOLE_GLOBAL_PS      = 11, /* CGI with + RAC */
 };
 /* Keep this misnamed CELL_IDENT for API backwards compatibility (see 
OS#3124). */
 #define CELL_IDENT_LAI_AND_LAC CELL_IDENT_LAI
diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c
index 6bf771f..c1b0a00 100644
--- a/src/gsm/gsm0808_utils.c
+++ b/src/gsm/gsm0808_utils.c
@@ -784,6 +784,8 @@
        case CELL_IDENT_BSS:
        case CELL_IDENT_NO_CELL:
                return 0;
+       case CELL_IDENT_WHOLE_GLOBAL_PS:
+               return 8;
        default:
                return -EINVAL;
        }
@@ -828,6 +830,13 @@
        case CELL_IDENT_NO_CELL:
                /* Does not have any list items */
                break;
+       case CELL_IDENT_WHOLE_GLOBAL_PS:
+               if (len < 8)
+                       return -EINVAL;
+               decode_lai(buf, (struct osmo_location_area_id 
*)&out->global_ps.rai); /* rai contains lai + non-decoded rac */
+               out->global_ps.rai.rac = *(buf + sizeof(struct 
gsm48_loc_area_id));
+               out->global_ps.cell_identity = osmo_load16be(buf + 
sizeof(struct gsm48_loc_area_id) + 1);
+               break;
        default:
                /* Remaining cell identification types are not implemented. */
                return -EINVAL;
@@ -869,6 +878,15 @@
        case CELL_IDENT_NO_CELL:
                /* Does not have any list items */
                break;
+       case CELL_IDENT_WHOLE_GLOBAL_PS: {
+               const struct osmo_cell_global_id_ps *id = &u->global_ps;
+               struct gsm48_loc_area_id lai;
+               gsm48_generate_lai2(&lai, &id->rai.lac);
+               memcpy(msgb_put(msg, sizeof(lai)), &lai, sizeof(lai));
+               memcpy(msgb_put(msg, 1), &id->rai.rac, 1);
+               msgb_put_u16(msg, id->cell_identity);
+               break;
+       }
        default:
                /* Support for other identifier list types is not implemented. 
*/
                OSMO_ASSERT(false);
@@ -1592,6 +1610,8 @@
                return snprintf(buf, buflen, "%s", 
osmo_lai_name(&u->lai_and_lac));
        case CELL_IDENT_WHOLE_GLOBAL:
                return snprintf(buf, buflen, "%s", osmo_cgi_name(&u->global));
+       case CELL_IDENT_WHOLE_GLOBAL_PS:
+               return snprintf(buf, buflen, "%s", 
osmo_cgi_ps_name(&u->global_ps));
        default:
                /* For CELL_IDENT_BSS and CELL_IDENT_NO_CELL, just print the 
discriminator.
                 * Same for kinds we have no string representation of yet. */
@@ -1613,6 +1633,11 @@
                *dst = u->global;
                return;

+       case CELL_IDENT_WHOLE_GLOBAL_PS:
+               dst->lai = u->global_ps.rai.lac;
+               dst->cell_identity = u->global_ps.cell_identity;
+               return;
+
        case CELL_IDENT_LAC_AND_CI:
                dst->lai.lac = u->lac_and_ci.lac;
                dst->cell_identity = u->lac_and_ci.ci;
@@ -1805,6 +1830,11 @@
                *cgi = cid->id.global;
                return OSMO_CGI_PART_PLMN | OSMO_CGI_PART_LAC | 
OSMO_CGI_PART_CI;

+       case CELL_IDENT_WHOLE_GLOBAL_PS:
+               cgi->lai = cid->id.global_ps.rai.lac;
+               cgi->cell_identity = cid->id.global_ps.cell_identity;
+               return OSMO_CGI_PART_PLMN | OSMO_CGI_PART_LAC | 
OSMO_CGI_PART_CI;
+
        case CELL_IDENT_LAC_AND_CI:
                cgi->lai.lac = cid->id.lac_and_ci.lac;
                cgi->cell_identity = cid->id.lac_and_ci.ci;
@@ -1844,6 +1874,7 @@
        { CELL_IDENT_UTRAN_PLMN_LAC_RNC, "UTRAN-PLMN-LAC-RNC" },
        { CELL_IDENT_UTRAN_RNC, "UTRAN-RNC" },
        { CELL_IDENT_UTRAN_LAC_RNC, "UTRAN-LAC-RNC" },
+       { CELL_IDENT_WHOLE_GLOBAL_PS, "CGI-PS"},
        { 0, NULL }
 };

diff --git a/src/gsm/gsm23003.c b/src/gsm/gsm23003.c
index e20afcb..ae498fa 100644
--- a/src/gsm/gsm23003.c
+++ b/src/gsm/gsm23003.c
@@ -247,6 +247,43 @@
        return osmo_lai_name_buf(buf, 32, lai);
 }

+/*! Return MCC-MNC-LAC-RAC as string, in caller-provided output buffer.
+ * \param[out] buf caller-allocated output buffer
+ * \param[in] buf_len size of buf in bytes
+ * \param[in] rai  RAI to encode, the rac member is ignored.
+ * \returns buf
+ */
+char *osmo_rai_name2_buf(char *buf, size_t buf_len, const struct 
osmo_routing_area_id *rai)
+{
+       char plmn[16];
+       snprintf(buf, buf_len, "%s-%u-%u", osmo_plmn_name_buf(plmn, 
sizeof(plmn),
+                &rai->lac.plmn), rai->lac.lac, rai->rac);
+       return buf;
+}
+
+/*! Return MCC-MNC-LAC-RAC as string, in a static buffer.
+ * \param[in] rai  RAI to encode, the rac member is ignored.
+ * \returns Static string buffer.
+ */
+const char *osmo_rai_name2(const struct osmo_routing_area_id *rai)
+{
+       static __thread char buf[32];
+       return osmo_rai_name2_buf(buf, sizeof(buf), rai);
+}
+
+/*! Return MCC-MNC-LAC-RAC as string, in a talloc-allocated output buffer.
+ * \param[in] ctx talloc context from which to allocate output buffer
+ * \param[in] rai  RAI to encode, the rac member is ignored.
+ * \returns string representation of lai in dynamically allocated buffer.
+ */
+char *osmo_rai_name2_c(const void *ctx, const struct osmo_routing_area_id *rai)
+{
+       char *buf = talloc_size(ctx, 32);
+       if (!buf)
+               return NULL;
+       return osmo_rai_name2_buf(buf, 32, rai);
+}
+
 /*! Return MCC-MNC-LAC-CI as string, in caller-provided output buffer.
  * \param[out] buf caller-allocated output buffer
  * \param[in] buf_len size of buf in bytes
@@ -291,6 +328,50 @@
        return osmo_cgi_name_buf(buf, 32, cgi);
 }

+/*! Return MCC-MNC-LAC-RAC-CI as string, in caller-provided output buffer.
+ * \param[out] buf caller-allocated output buffer
+ * \param[in] buf_len size of buf in bytes
+ * \param[in] cgi_ps  CGI-PS to encode.
+ * \returns buf
+ */
+char *osmo_cgi_ps_name_buf(char *buf, size_t buf_len, const struct 
osmo_cell_global_id_ps *cgi_ps)
+{
+       snprintf(buf, buf_len, "%s-%u", osmo_rai_name2(&cgi_ps->rai), 
cgi_ps->cell_identity);
+       return buf;
+}
+
+/*! Return MCC-MNC-LAC-RAC-CI as string, in a static buffer.
+ * \param[in] cgi_ps  CGI-PS to encode.
+ * \returns Static string buffer.
+ */
+const char *osmo_cgi_ps_name(const struct osmo_cell_global_id_ps *cgi_ps)
+{
+       static __thread char buf[32];
+       return osmo_cgi_ps_name_buf(buf, sizeof(buf), cgi_ps);
+}
+
+/*! Same as osmo_cgi_ps_name(), but uses a different static buffer.
+ * Useful for printing two distinct CGI-PSs in the same printf format.
+ * \param[in] cgi  CGI-PS to encode.
+ * \returns Static string buffer.
+ */
+const char *osmo_cgi_ps_name2(const struct osmo_cell_global_id_ps *cgi_ps)
+{
+       static __thread char buf[32];
+       return osmo_cgi_ps_name_buf(buf, sizeof(buf), cgi_ps);
+}
+
+/*! Return MCC-MNC-LAC-RAC-CI as string, in a talloc-allocated output buffer.
+ * \param[in] ctx talloc context from which to allocate output buffer
+ * \param[in] cgi_ps  CGI-PS to encode.
+ * \returns string representation of CGI in dynamically-allocated buffer.
+ */
+char *osmo_cgi_ps_name_c(const void *ctx, const struct osmo_cell_global_id_ps 
*cgi_ps)
+{
+       char *buf = talloc_size(ctx, 32);
+       return osmo_cgi_ps_name_buf(buf, 32, cgi_ps);
+}
+
 static void to_bcd(uint8_t *bcd, uint16_t val)
 {
        bcd[2] = val % 10;
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index bcded1c..eceb1c1 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -412,10 +412,17 @@
 osmo_rai_name;
 osmo_rai_name_buf;
 osmo_rai_name_c;
+osmo_rai_name2;
+osmo_rai_name2_buf;
+osmo_rai_name2_c;
 osmo_cgi_name;
 osmo_cgi_name_buf;
 osmo_cgi_name_c;
 osmo_cgi_name2;
+osmo_cgi_ps_name;
+osmo_cgi_ps_name_buf;
+osmo_cgi_ps_name_c;
+osmo_cgi_ps_name2;
 osmo_gummei_name;
 osmo_gummei_name_buf;
 osmo_gummei_name_c;

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/22013
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If48f412c32e8e5a3e604a78d12b74787a4786374
Gerrit-Change-Number: 22013
Gerrit-PatchSet: 7
Gerrit-Owner: pespin <pes...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pma...@sysmocom.de>
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-MessageType: merged

Reply via email to