GTP: Replace recently introduced imsi_str2gtp()

Replace with the version from osmo-sgsn, renamed so
as not to collide with that version.

Change-Id: I910d5339a823332277ce7b5854d5c943ed69ea81
This commit is contained in:
Keith Whyte 2020-10-12 15:32:07 +02:00
parent 568ac5ee8e
commit fb2a7298e0
4 changed files with 23 additions and 14 deletions

View File

@ -899,7 +899,7 @@ DEFUN(show_pdpctx_imsi, show_pdpctx_imsi_cmd,
return CMD_WARNING;
}
imsi = imsi_str2gtp(argv[1]);
imsi = gtp_imsi_str2gtp(argv[1]);
if (argc > 2) {
nsapi = atoi(argv[2]);

View File

@ -3493,16 +3493,25 @@ const char *imsi_gtp2str(const uint64_t *imsi)
return buf;
}
/* Encode an IMSI with gtp encoding according to TS 29.060 - the
reverse of imsi_gtp2str(). The hash index used for context
lookups is generated from the IMSI in gtp format. User input
in the vty (for example) needs to be converted to match. */
const uint64_t imsi_str2gtp(const char *imsi)
/* Generate the GTP IMSI IE according to 09.60 Section 7.9.2 */
uint64_t gtp_imsi_str2gtp(const char *str)
{
uint64_t ret = 0xf000000000000000ull;
unsigned int i, imsi_length = strlen(imsi);
uint64_t imsi64 = 0;
unsigned int n;
unsigned int imsi_len = strlen(str);
for (i = 0; i < imsi_length; i++)
ret |= ((uint64_t) (imsi[i] - '0')) << (i * 4);
return ret;
if (imsi_len > 16) {
LOGP(DLGTP, LOGL_NOTICE, "IMSI length > 16 not supported!\n");
return 0;
}
for (n = 0; n < 16; n++) {
uint64_t val;
if (n < imsi_len)
val = (str[n]-'0') & 0xf;
else
val = 0xf;
imsi64 |= (val << (n*4));
}
return imsi64;
}

View File

@ -441,6 +441,6 @@ extern int eua2ipv4(struct in_addr *dst, struct ul66_t *eua);
extern int gsna2in_addr(struct in_addr *dst, struct ul16_t *gsna);
extern int in_addr2gsna(struct ul16_t *gsna, struct in_addr *src);
extern const char *imsi_gtp2str(const uint64_t *imsi);
extern const uint64_t imsi_str2gtp(const char *imsi);
extern uint64_t gtp_imsi_str2gtp(const char *str);
#endif /* !_GTP_H */

View File

@ -497,7 +497,7 @@ static int process_options(int argc, char **argv)
return -1;
}
options.imsi = imsi_str2gtp(args_info.imsi_arg);
options.imsi = gtp_imsi_str2gtp(args_info.imsi_arg);
printf("IMSI is: %s (%#08llx)\n",
args_info.imsi_arg, options.imsi);