[PATCH] osmo-hlr[master]: move creation of insert subscriber data messages to a common...
Hello Neels Hofmeyr, Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/7992 to look at the new patch set (#4). move creation of insert subscriber data messages to a common function Move code to create an Insert Subscriber Data message into a common function which can be shared by hlr.c and luop.c. As a consequence, we always encode gsup.cn_domain in the corresponding msgb and must adjust expected output of the 'gsup' test accordingly. Change-Id: I6a92ca34cdaadca9eacc774bb1ca386c325ba865 Requested-by: neels Related: OS#2785 --- M src/gsup_server.c M src/gsup_server.h M src/hlr.c M src/luop.c M tests/gsup/gsup_test.err 5 files changed, 103 insertions(+), 67 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/92/7992/4 diff --git a/src/gsup_server.c b/src/gsup_server.c index 07d4feb..c525495 100644 --- a/src/gsup_server.c +++ b/src/gsup_server.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "gsup_server.h" @@ -357,3 +358,56 @@ return 0; } + +/** + * Populate a gsup message structure with an Insert Subscriber Data Message. + * All required memory buffers for data pointed to by pointers in struct omso_gsup_message + * must be allocated by the caller and should have the same lifetime as the gsup parameter. + * + * \param[in] gsup The gsup message to populate. + * \param[in] imsi The subscriber's IMSI. + * \param[in] msisdn The subscriber's MSISDN. + * \param[in] msisdn_enc A buffer large enough to store the MSISDN in encoded form. + * \param[in] msisdn_enc_size Size of the buffer (must be >= OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN). + * \param[in] apn_buf A buffer large enough to store an APN (required if cn_domain is OSMO_GSUP_CN_DOMAIN_PS). + * \param[in] apn_buf_size Size of APN buffer (must be >= APN_MAXLEN). + * \param[in] cn_domain The CN Domain of the subscriber connection. + * \returns 0 on success, and negative on error. + */ +int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup, char *imsi, char *msisdn, + uint8_t *msisdn_enc, size_t msisdn_enc_size, + uint8_t *apn_buf, size_t apn_buf_size, + enum osmo_gsup_cn_domain cn_domain) +{ + int len; + + OSMO_ASSERT(gsup); + + gsup->message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST; + osmo_strlcpy(gsup->imsi, imsi, sizeof(gsup->imsi)); + + if (msisdn_enc_size < OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN) + return -ENOSPC; + + OSMO_ASSERT(msisdn_enc); + len = gsm48_encode_bcd_number(msisdn_enc, msisdn_enc_size, 0, msisdn); + if (len < 1) { + LOGP(DLGSUP, LOGL_ERROR, "%s: Error: cannot encode MSISDN '%s'\n", imsi, msisdn); + return -ENOSPC; + } + gsup->msisdn_enc = msisdn_enc; + gsup->msisdn_enc_len = len; + + #pragma message "FIXME: deal with encoding the following data: gsup.hlr_enc" + + gsup->cn_domain = cn_domain; + if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS) { + OSMO_ASSERT(apn_buf_size >= APN_MAXLEN); + OSMO_ASSERT(apn_buf); + /* FIXME: PDP infos - use more fine-grained access control + instead of wildcard APN */ + osmo_gsup_configure_wildcard_apn(gsup, apn_buf, apn_buf_size); + } + + return 0; +} diff --git a/src/gsup_server.h b/src/gsup_server.h index 66c1a9c..a725521 100644 --- a/src/gsup_server.h +++ b/src/gsup_server.h @@ -6,6 +6,10 @@ #include #include +#ifndef OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN +#define OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN 43 /* TS 24.008 10.5.4.7 */ +#endif + struct osmo_gsup_conn; /* Expects message in msg->l2h */ @@ -55,3 +59,7 @@ int osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup, uint8_t *apn_buf, size_t apn_buf_size); +int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup, char *imsi, char *msisdn, + uint8_t *msisdn_enc, size_t msisdn_enc_size, + uint8_t *apn_buf, size_t apn_buf_size, + enum osmo_gsup_cn_domain cn_domain); diff --git a/src/hlr.c b/src/hlr.c index 1c72f45..4da7b9b 100644 --- a/src/hlr.c +++ b/src/hlr.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -62,51 +61,30 @@ return; llist_for_each_entry(co, _hlr->gs->clients, list) { - struct osmo_gsup_message gsup = { - .message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST - }; + struct osmo_gsup_message gsup = { }; + uint8_t msisdn_enc[OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN]; + uint8_t
[PATCH] osmo-hlr[master]: move creation of insert subscriber data messages to a common...
Hello Neels Hofmeyr, Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/7992 to look at the new patch set (#3). move creation of insert subscriber data messages to a common function Move code to create an Insert Subscriber Data message into a common function which can be shared by hlr.c and luop.c. As a consequence, we always encode gsup.cn_domain in the corresponding msgb and must adjust expected output of the 'gsup' test accordingly. Change-Id: I6a92ca34cdaadca9eacc774bb1ca386c325ba865 Requested-by: neels Related: OS#2785 --- M src/gsup_server.c M src/gsup_server.h M src/hlr.c M src/luop.c M tests/gsup/gsup_test.err 5 files changed, 103 insertions(+), 67 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/92/7992/3 diff --git a/src/gsup_server.c b/src/gsup_server.c index 07d4feb..17285c9 100644 --- a/src/gsup_server.c +++ b/src/gsup_server.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "gsup_server.h" @@ -357,3 +358,56 @@ return 0; } + +/** + * Populate a gsup message structure with an Insert Subscriber Data Message. + * All required memory buffers for data pointed to by pointers in struct omso_gsup_message + * must be allocated by the caller and should have the same lifetime as the gsup parameter. + * + * \param[in] gsup The gsup message to populate. + * \param[in] imsi The subscriber's IMSI. + * \param[in] msisdn The subscriber's MSISDN. + * \param[in] msisdn_enc A buffer large enough to store the MSISDN in encoded form. + * \param[in] msisdn_enc_size Size of the buffer (must be >= OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN). + * \param[in] apn_buf A buffer large enough to store an APN (required if cn_domain is OSMO_GSUP_CN_DOMAIN_PS). + * \param[in] apn_buf_size Size of APN buffer (must be >= APN_MAXLEN). + * \param[in] cn_domain The CN Domain of the subscriber connection. + * \returns 0 on success, and negative on error. + */ +int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup, char *imsi, char *msisdn, + uint8_t *msisdn_enc, size_t msisdn_enc_size, + uint8_t *apn_buf, size_t apn_buf_size, + enum osmo_gsup_cn_domain cn_domain) +{ + int len; + + OSMO_ASSERT(gsup); + + gsup->message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST; + osmo_strlcpy(gsup->imsi, imsi, GSM23003_IMSI_MAX_DIGITS + 1); + + if (msisdn_enc_size < OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN) + return -ENOSPC; + + OSMO_ASSERT(msisdn_enc); + len = gsm48_encode_bcd_number(msisdn_enc, msisdn_enc_size, 0, msisdn); + if (len < 1) { + LOGP(DLGSUP, LOGL_ERROR, "%s: Error: cannot encode MSISDN '%s'\n", imsi, msisdn); + return -ENOSPC; + } + gsup->msisdn_enc = msisdn_enc; + gsup->msisdn_enc_len = len; + + #pragma message "FIXME: deal with encoding the following data: gsup.hlr_enc" + + gsup->cn_domain = cn_domain; + if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS) { + OSMO_ASSERT(apn_buf_size >= APN_MAXLEN); + OSMO_ASSERT(apn_buf); + /* FIXME: PDP infos - use more fine-grained access control + instead of wildcard APN */ + osmo_gsup_configure_wildcard_apn(gsup, apn_buf, apn_buf_size); + } + + return 0; +} diff --git a/src/gsup_server.h b/src/gsup_server.h index 66c1a9c..a725521 100644 --- a/src/gsup_server.h +++ b/src/gsup_server.h @@ -6,6 +6,10 @@ #include #include +#ifndef OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN +#define OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN 43 /* TS 24.008 10.5.4.7 */ +#endif + struct osmo_gsup_conn; /* Expects message in msg->l2h */ @@ -55,3 +59,7 @@ int osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup, uint8_t *apn_buf, size_t apn_buf_size); +int osmo_gsup_create_insert_subscriber_data_msg(struct osmo_gsup_message *gsup, char *imsi, char *msisdn, + uint8_t *msisdn_enc, size_t msisdn_enc_size, + uint8_t *apn_buf, size_t apn_buf_size, + enum osmo_gsup_cn_domain cn_domain); diff --git a/src/hlr.c b/src/hlr.c index 1c72f45..4da7b9b 100644 --- a/src/hlr.c +++ b/src/hlr.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -62,51 +61,30 @@ return; llist_for_each_entry(co, _hlr->gs->clients, list) { - struct osmo_gsup_message gsup = { - .message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST - }; + struct osmo_gsup_message gsup = { }; + uint8_t msisdn_enc[OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN]; +
[PATCH] osmo-hlr[master]: move creation of insert subscriber data messages to a common...
Hello Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/7992 to look at the new patch set (#2). move creation of insert subscriber data messages to a common function Move code to create an Insert Subscriber Data message into a common function which can be shared by hlr.c and luop.c. As a consequence, we always encode gsup.cn_domain in the corresponding msgb and must adjust expected output of the 'gsup' test accordingly. Change-Id: I6a92ca34cdaadca9eacc774bb1ca386c325ba865 Requested-by: neels Related: OS#2785 --- M src/gsup_server.c M src/gsup_server.h M src/hlr.c M src/luop.c M tests/gsup/gsup_test.err 5 files changed, 90 insertions(+), 69 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/92/7992/2 diff --git a/src/gsup_server.c b/src/gsup_server.c index 07d4feb..685633e 100644 --- a/src/gsup_server.c +++ b/src/gsup_server.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "gsup_server.h" @@ -357,3 +358,42 @@ return 0; } + +struct osmo_gsup_message * +osmo_gsup_create_insert_subscriber_data_msg(char *imsi, char *msisdn, enum osmo_gsup_cn_domain cn_domain) +{ + struct osmo_gsup_message *gsup; + int len; + uint8_t *msisdn_enc; + + gsup = talloc_zero(NULL, struct osmo_gsup_message); + OSMO_ASSERT(gsup); + + gsup->message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST; + osmo_strlcpy(gsup->imsi, imsi, GSM23003_IMSI_MAX_DIGITS + 1); + + msisdn_enc = talloc_size(gsup, OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN); + OSMO_ASSERT(msisdn_enc); + + len = gsm48_encode_bcd_number(msisdn_enc, OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN, 0, msisdn); + if (len < 1) { + LOGP(DLGSUP, LOGL_ERROR, "%s: Error: cannot encode MSISDN '%s'\n", imsi, msisdn); + talloc_free(gsup); + return NULL; + } + gsup->msisdn_enc = msisdn_enc; + gsup->msisdn_enc_len = len; + + #pragma message "FIXME: deal with encoding the following data: gsup.hlr_enc" + + gsup->cn_domain = cn_domain; + if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS) { + uint8_t *apn = talloc_size(gsup, APN_MAXLEN); + OSMO_ASSERT(apn); + /* FIXME: PDP infos - use more fine-grained access control + instead of wildcard APN */ + osmo_gsup_configure_wildcard_apn(gsup, apn, APN_MAXLEN); + } + + return gsup; +} diff --git a/src/gsup_server.h b/src/gsup_server.h index 66c1a9c..0945d71 100644 --- a/src/gsup_server.h +++ b/src/gsup_server.h @@ -6,6 +6,10 @@ #include #include +#ifndef OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN +#define OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN 43 /* TS 24.008 10.5.4.7 */ +#endif + struct osmo_gsup_conn; /* Expects message in msg->l2h */ @@ -55,3 +59,5 @@ int osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup, uint8_t *apn_buf, size_t apn_buf_size); +struct osmo_gsup_message *osmo_gsup_create_insert_subscriber_data_msg(char *imsi, char *msisdn, + enum osmo_gsup_cn_domain cn_domain); diff --git a/src/hlr.c b/src/hlr.c index 1c72f45..919751c 100644 --- a/src/hlr.c +++ b/src/hlr.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -62,51 +61,28 @@ return; llist_for_each_entry(co, _hlr->gs->clients, list) { - struct osmo_gsup_message gsup = { - .message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST - }; + struct osmo_gsup_message *gsup; + struct msgb *msg_out; uint8_t *peer; int peer_len; - uint8_t msisdn_enc[43]; /* TODO use constant; TS 24.008 10.5.4.7 */ - uint8_t apn[APN_MAXLEN]; - int len; - struct msgb *msg_out; + enum osmo_gsup_cn_domain cn_domain; - peer_len = osmo_gsup_conn_ccm_get(co, , IPAC_IDTAG_SERNR); - if (peer_len < 0) { + if (co->supports_ps) + cn_domain = OSMO_GSUP_CN_DOMAIN_PS; + else if (co->supports_cs) + cn_domain = OSMO_GSUP_CN_DOMAIN_CS; + else { + /* We have not yet received a location update from this subscriber .*/ + continue; + } + + gsup = osmo_gsup_create_insert_subscriber_data_msg(subscr->imsi, subscr->msisdn, cn_domain); + if (gsup == NULL) { LOGP(DMAIN, LOGL_ERROR, - "IMSI='%s': Cannot notify GSUP client, cannot get peer name " + "IMSI='%s': Cannot notify GSUP client; could not allocate gsup message " "for
[PATCH] osmo-hlr[master]: move creation of insert subscriber data messages to a common...
Review at https://gerrit.osmocom.org/7992 move creation of insert subscriber data messages to a common function Move code to create an Insert Subscriber Data message into a common function which can be shared by hlr.c and luop.c. Change-Id: I6a92ca34cdaadca9eacc774bb1ca386c325ba865 Requested-by: neels Related: OS#2785 --- M src/gsup_server.c M src/gsup_server.h M src/hlr.c M src/luop.c 4 files changed, 98 insertions(+), 57 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/92/7992/1 diff --git a/src/gsup_server.c b/src/gsup_server.c index 24ba738..e4329a3 100644 --- a/src/gsup_server.c +++ b/src/gsup_server.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "gsup_server.h" @@ -351,3 +352,47 @@ /* FIXME: use real value: */ gsup->pdp_infos[0].context_id = 1; } + +struct osmo_gsup_message * +osmo_gsup_create_insert_subscriber_data_msg(char *imsi, char *msisdn, enum osmo_gsup_cn_domain cn_domain) +{ + struct osmo_gsup_message *gsup; + int len; + uint8_t *msisdn_enc; + + gsup = talloc_zero(NULL, struct osmo_gsup_message); + if (gsup == NULL) { + LOGP(DLGSUP, LOGL_ERROR, "IMSI='%s': cannot allocate Insert Subscriber Data Message\n", imsi); + return NULL; + } + gsup->message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST; + + osmo_strlcpy(gsup->imsi, imsi, GSM23003_IMSI_MAX_DIGITS + 1); + + msisdn_enc = talloc_size(gsup, OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN); + if (msisdn_enc == NULL) { + LOGP(DLGSUP, LOGL_ERROR, "%s: Error: cannot encode MSISDN '%s'; could not allocate buffer\n", +imsi, msisdn); + talloc_free(gsup); + return NULL; + } + len = gsm48_encode_bcd_number(msisdn_enc, OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN, 0, msisdn); + if (len < 1) { + LOGP(DLGSUP, LOGL_ERROR, "%s: Error: cannot encode MSISDN '%s'\n", imsi, msisdn); + talloc_free(gsup); + return NULL; + } + gsup->msisdn_enc = msisdn_enc; + gsup->msisdn_enc_len = len; + + #pragma message "FIXME: deal with encoding the following data: gsup.hlr_enc" + + gsup->cn_domain = cn_domain; + if (gsup->cn_domain == OSMO_GSUP_CN_DOMAIN_PS) { + /* FIXME: PDP infos - use more fine-grained access control + instead of wildcard APN */ + osmo_gsup_configure_wildcard_apn(gsup); + } + + return gsup; +} diff --git a/src/gsup_server.h b/src/gsup_server.h index 3d36bff..55a8c3e 100644 --- a/src/gsup_server.h +++ b/src/gsup_server.h @@ -6,6 +6,10 @@ #include #include +#ifndef OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN +#define OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN 43 /* TS 24.008 10.5.4.7 */ +#endif + struct osmo_gsup_conn; /* Expects message in msg->l2h */ @@ -54,3 +58,5 @@ void osmo_gsup_server_destroy(struct osmo_gsup_server *gsups); void osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup); +struct osmo_gsup_message *osmo_gsup_create_insert_subscriber_data_msg(char *imsi, char *msisdn, + enum osmo_gsup_cn_domain cn_domain); diff --git a/src/hlr.c b/src/hlr.c index 195e5d2..36aad94 100644 --- a/src/hlr.c +++ b/src/hlr.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -61,46 +60,28 @@ return; llist_for_each_entry(co, _hlr->gs->clients, list) { - struct osmo_gsup_message gsup = { - .message_type = OSMO_GSUP_MSGT_INSERT_DATA_REQUEST - }; + struct osmo_gsup_message *gsup; + struct msgb *msg_out; uint8_t *peer; int peer_len; - uint8_t msisdn_enc[43]; /* TODO use constant; TS 24.008 10.5.4.7 */ - int len; - struct msgb *msg_out; + enum osmo_gsup_cn_domain cn_domain; - peer_len = osmo_gsup_conn_ccm_get(co, , IPAC_IDTAG_SERNR); - if (peer_len < 0) { + if (co->supports_ps) + cn_domain = OSMO_GSUP_CN_DOMAIN_PS; + else if (co->supports_cs) + cn_domain = OSMO_GSUP_CN_DOMAIN_CS; + else { + /* We have not yet received a location update from this subscriber .*/ + continue; + } + + gsup = osmo_gsup_create_insert_subscriber_data_msg(subscr->imsi, subscr->msisdn, cn_domain); + if (gsup == NULL) { LOGP(DMAIN, LOGL_ERROR, - "IMSI='%s': Cannot notify GSUP client, cannot get peer name " + "IMSI='%s': Cannot notify GSUP client; could not allocate gsup message " "for %s:%u\n",