<p>Harald Welte <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/13887">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Pau Espin Pedrol: Looks good to me, approved
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">gsm0808_utils: Introduce gsm0808_msgb_put_cell_id_u()<br><br>This function is doing the bulk work of encoding a given Cell<br>ID List item.  gsm0808_enc_cell_id_list2() is modified to be a<br>wrapper / loop around the new function.<br><br>The purpose of this is to expose Cell ID List Entry encoding<br>so that the upcoming CBSP protocol encoder can re-use this code.<br><br>Related: OS#3537<br>Change-Id: I6cc567798e20365e6587e6b2988e834306d8c80c<br>---<br>M include/osmocom/gsm/gsm0808_utils.h<br>M src/gsm/gsm0808_utils.c<br>M src/gsm/libosmogsm.map<br>3 files changed, 44 insertions(+), 41 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/gsm/gsm0808_utils.h b/include/osmocom/gsm/gsm0808_utils.h</span><br><span>index 47c4e95..3a7beb7 100644</span><br><span>--- a/include/osmocom/gsm/gsm0808_utils.h</span><br><span>+++ b/include/osmocom/gsm/gsm0808_utils.h</span><br><span>@@ -93,6 +93,7 @@</span><br><span> void gsm0808_cell_id_from_cgi(struct gsm0808_cell_id *cid, enum CELL_IDENT id_discr,</span><br><span>                             const struct osmo_cell_global_id *cgi);</span><br><span> int gsm0808_cell_id_to_cgi(struct osmo_cell_global_id *cgi, const struct gsm0808_cell_id *cid);</span><br><span style="color: hsl(120, 100%, 40%);">+void gsm0808_msgb_put_cell_id_u(struct msgb *msg, enum CELL_IDENT id_discr, const union gsm0808_cell_id_u *u);</span><br><span> </span><br><span> uint8_t gsm0808_enc_cause(struct msgb *msg, uint16_t cause);</span><br><span> uint8_t gsm0808_enc_aoip_trasp_addr(struct msgb *msg,</span><br><span>diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c</span><br><span>index 99cf188..e825930 100644</span><br><span>--- a/src/gsm/gsm0808_utils.c</span><br><span>+++ b/src/gsm/gsm0808_utils.c</span><br><span>@@ -737,6 +737,46 @@</span><br><span>        return (int)(elem - old_elem);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+void gsm0808_msgb_put_cell_id_u(struct msgb *msg, enum CELL_IDENT id_discr, const union gsm0808_cell_id_u *u)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     switch (id_discr) {</span><br><span style="color: hsl(120, 100%, 40%);">+   case CELL_IDENT_WHOLE_GLOBAL: {</span><br><span style="color: hsl(120, 100%, 40%);">+               const struct osmo_cell_global_id *id = &u->global;</span><br><span style="color: hsl(120, 100%, 40%);">+             struct gsm48_loc_area_id lai;</span><br><span style="color: hsl(120, 100%, 40%);">+         gsm48_generate_lai2(&lai, &id->lai);</span><br><span style="color: hsl(120, 100%, 40%);">+               memcpy(msgb_put(msg, sizeof(lai)), &lai, sizeof(lai));</span><br><span style="color: hsl(120, 100%, 40%);">+            msgb_put_u16(msg, id->cell_identity);</span><br><span style="color: hsl(120, 100%, 40%);">+              break;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+     case CELL_IDENT_LAC_AND_CI: {</span><br><span style="color: hsl(120, 100%, 40%);">+         const struct osmo_lac_and_ci_id *id = &u->lac_and_ci;</span><br><span style="color: hsl(120, 100%, 40%);">+          msgb_put_u16(msg, id->lac);</span><br><span style="color: hsl(120, 100%, 40%);">+                msgb_put_u16(msg, id->ci);</span><br><span style="color: hsl(120, 100%, 40%);">+         break;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+     case CELL_IDENT_CI:</span><br><span style="color: hsl(120, 100%, 40%);">+           msgb_put_u16(msg, u->ci);</span><br><span style="color: hsl(120, 100%, 40%);">+          break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case CELL_IDENT_LAI_AND_LAC: {</span><br><span style="color: hsl(120, 100%, 40%);">+                const struct osmo_location_area_id *id = &u->lai_and_lac;</span><br><span style="color: hsl(120, 100%, 40%);">+              struct gsm48_loc_area_id lai;</span><br><span style="color: hsl(120, 100%, 40%);">+         gsm48_generate_lai2(&lai, id);</span><br><span style="color: hsl(120, 100%, 40%);">+            memcpy(msgb_put(msg, sizeof(lai)), &lai, sizeof(lai));</span><br><span style="color: hsl(120, 100%, 40%);">+            break;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+     case CELL_IDENT_LAC:</span><br><span style="color: hsl(120, 100%, 40%);">+          msgb_put_u16(msg, u->lac);</span><br><span style="color: hsl(120, 100%, 40%);">+         break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case CELL_IDENT_BSS:</span><br><span style="color: hsl(120, 100%, 40%);">+  case CELL_IDENT_NO_CELL:</span><br><span style="color: hsl(120, 100%, 40%);">+              /* Does not have any list items */</span><br><span style="color: hsl(120, 100%, 40%);">+            break;</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              /* Support for other identifier list types is not implemented. */</span><br><span style="color: hsl(120, 100%, 40%);">+             OSMO_ASSERT(false);</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! Encode TS 08.08 Cell Identifier List IE</span><br><span>  *  \param[out] msg Message Buffer to which IE is to be appended</span><br><span>  *  \param[in] cil Cell ID List to be encoded</span><br><span>@@ -758,47 +798,8 @@</span><br><span>    msgb_put_u8(msg, cil->id_discr & 0x0f);</span><br><span> </span><br><span>   OSMO_ASSERT(cil->id_list_len <= GSM0808_CELL_ID_LIST2_MAXLEN)</span><br><span style="color: hsl(0, 100%, 40%);">-     switch (cil->id_discr) {</span><br><span style="color: hsl(0, 100%, 40%);">-     case CELL_IDENT_WHOLE_GLOBAL:</span><br><span style="color: hsl(0, 100%, 40%);">-           for (i = 0; i < cil->id_list_len; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">-                  const struct osmo_cell_global_id *id = &cil->id_list[i].global;</span><br><span style="color: hsl(0, 100%, 40%);">-                  struct gsm48_loc_area_id lai;</span><br><span style="color: hsl(0, 100%, 40%);">-                   gsm48_generate_lai2(&lai, &id->lai);</span><br><span style="color: hsl(0, 100%, 40%);">-                 memcpy(msgb_put(msg, sizeof(lai)), &lai, sizeof(lai));</span><br><span style="color: hsl(0, 100%, 40%);">-                      msgb_put_u16(msg, id->cell_identity);</span><br><span style="color: hsl(0, 100%, 40%);">-                }</span><br><span style="color: hsl(0, 100%, 40%);">-               break;</span><br><span style="color: hsl(0, 100%, 40%);">-  case CELL_IDENT_LAC_AND_CI:</span><br><span style="color: hsl(0, 100%, 40%);">-             for (i = 0; i < cil->id_list_len; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">-                  const struct osmo_lac_and_ci_id *id = &cil->id_list[i].lac_and_ci;</span><br><span style="color: hsl(0, 100%, 40%);">-                       msgb_put_u16(msg, id->lac);</span><br><span style="color: hsl(0, 100%, 40%);">-                  msgb_put_u16(msg, id->ci);</span><br><span style="color: hsl(0, 100%, 40%);">-           }</span><br><span style="color: hsl(0, 100%, 40%);">-               break;</span><br><span style="color: hsl(0, 100%, 40%);">-  case CELL_IDENT_CI:</span><br><span style="color: hsl(0, 100%, 40%);">-             for (i = 0; i < cil->id_list_len; i++)</span><br><span style="color: hsl(0, 100%, 40%);">-                    msgb_put_u16(msg, cil->id_list[i].ci);</span><br><span style="color: hsl(0, 100%, 40%);">-               break;</span><br><span style="color: hsl(0, 100%, 40%);">-  case CELL_IDENT_LAI_AND_LAC:</span><br><span style="color: hsl(0, 100%, 40%);">-            for (i = 0; i < cil->id_list_len; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">-                  const struct osmo_location_area_id *id = &cil->id_list[i].lai_and_lac;</span><br><span style="color: hsl(0, 100%, 40%);">-                   struct gsm48_loc_area_id lai;</span><br><span style="color: hsl(0, 100%, 40%);">-                   gsm48_generate_lai2(&lai, id);</span><br><span style="color: hsl(0, 100%, 40%);">-                      memcpy(msgb_put(msg, sizeof(lai)), &lai, sizeof(lai));</span><br><span style="color: hsl(0, 100%, 40%);">-              }</span><br><span style="color: hsl(0, 100%, 40%);">-               break;</span><br><span style="color: hsl(0, 100%, 40%);">-  case CELL_IDENT_LAC:</span><br><span style="color: hsl(0, 100%, 40%);">-            for (i = 0; i < cil->id_list_len; i++)</span><br><span style="color: hsl(0, 100%, 40%);">-                    msgb_put_u16(msg, cil->id_list[i].lac);</span><br><span style="color: hsl(0, 100%, 40%);">-              break;</span><br><span style="color: hsl(0, 100%, 40%);">-  case CELL_IDENT_BSS:</span><br><span style="color: hsl(0, 100%, 40%);">-    case CELL_IDENT_NO_CELL:</span><br><span style="color: hsl(0, 100%, 40%);">-                /* Does not have any list items */</span><br><span style="color: hsl(0, 100%, 40%);">-              break;</span><br><span style="color: hsl(0, 100%, 40%);">-  default:</span><br><span style="color: hsl(0, 100%, 40%);">-                /* Support for other identifier list types is not implemented. */</span><br><span style="color: hsl(0, 100%, 40%);">-               OSMO_ASSERT(false);</span><br><span style="color: hsl(0, 100%, 40%);">-     }</span><br><span style="color: hsl(120, 100%, 40%);">+     for (i = 0; i < cil->id_list_len; i++)</span><br><span style="color: hsl(120, 100%, 40%);">+          gsm0808_msgb_put_cell_id_u(msg, cil->id_discr, &cil->id_list[i]);</span><br><span> </span><br><span>      *tlv_len = (uint8_t) (msg->tail - old_tail);</span><br><span>      return *tlv_len + 2;</span><br><span>diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map</span><br><span>index adfa096..840bac9 100644</span><br><span>--- a/src/gsm/libosmogsm.map</span><br><span>+++ b/src/gsm/libosmogsm.map</span><br><span>@@ -242,6 +242,7 @@</span><br><span> gsm0808_lcls_status_names;</span><br><span> gsm0808_enc_lcls;</span><br><span> gsm0808_dec_lcls;</span><br><span style="color: hsl(120, 100%, 40%);">+gsm0808_msgb_put_cell_id_u;</span><br><span> </span><br><span> gsm29118_msgb_alloc;</span><br><span> gsm29118_create_alert_req;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/13887">change 13887</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/13887"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I6cc567798e20365e6587e6b2988e834306d8c80c </div>
<div style="display:none"> Gerrit-Change-Number: 13887 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder (1000002) </div>
<div style="display:none"> Gerrit-Reviewer: Pau Espin Pedrol <pespin@sysmocom.de> </div>