Message ID | 1447426657-17954-1-git-send-email-aschultz@tpip.net |
---|---|
State | Accepted |
Headers | show |
On Fri, Nov 13, 2015 at 03:57:37PM +0100, Andreas Schultz wrote: > This converts a literal APN (e.g. Label1.Label2.Label3) to a structured > field (e.g. \006Label1\006Label2\006Label3) thanks, applied to my local tree, will push soon.
Hi, On 13.11.2015 15:57, Andreas Schultz wrote: > >> The APN consists of one or more labels. Each label is coded as a one >> octet length field followed by that number of octets coded as 8 bit >> ASCII characters > > This converts a literal APN (e.g. Label1.Label2.Label3) to a structured > field (e.g. \006Label1\006Label2\006Label3) We already have gprs_apn_to_str and gprs_str_to_apn in openbsc/src/gprs/gprs_utils.c (along with test cases) which are probably good candidates (among other functions in that file) to be moved to libosmocore, which sgsnemu is using already. Nevertheless most of the basic GPRS stuff (e.g. gsm_04_08_gprs.c which is on a similar level) is still in openbsc, so I would like to have more of a concept (gsm, gb, or a new gprs lib? Name prefix?) before starting refactoring. Jacob
Hi Jacob, On Mon, Nov 16, 2015 at 09:46:58AM +0100, Jacob Erlbeck wrote: > Nevertheless most of the basic GPRS stuff (e.g. gsm_04_08_gprs.c which > is on a similar level) is still in openbsc, so I would like to have more > of a concept (gsm, gb, or a new gprs lib? Name prefix?) before starting > refactoring. I would argue to put more things into libosmogsm. We already have plenty of libraries and I think there's not much point to have even more fragmentation. I mean, we're not talking about hundreds of megabyte of boost-enabled C++ code, but some amount of helper functions here. libosmogb should stay related specific to the Gb (NS/BSSGP) interface, I think that's a pretty clean/clear split. In terms of prefixing: libosmogsm uses gsm* where * is for the reduced spec number, and some gprs_* symbols. I think it's hard to come up with a detailed rule, but I'd say as long as it fits within that scheme it is fine. Starting now to prefix eveything with osmo_ seems a bit ridiculous, with all the existing other-prefixed symbols. but let's kepe the nubmer of prefixes limited ;)
Hi Harald, On 16.11.2015 09:59, Harald Welte wrote: > I would argue to put more things into libosmogsm. We already have > plenty of libraries and I think there's not much point to have even more > fragmentation. I mean, we're not talking about hundreds of megabyte of > boost-enabled C++ code, but some amount of helper functions here. > > libosmogb should stay related specific to the Gb (NS/BSSGP) interface, I > think that's a pretty clean/clear split. Agreed. > In terms of prefixing: libosmogsm uses gsm* where * is for the reduced > spec number, and some gprs_* symbols. I think it's hard to come up with > a detailed rule, but I'd say as long as it fits within that scheme it is > fine. > > Starting now to prefix eveything with osmo_ seems a bit ridiculous, with > all the existing other-prefixed symbols. but let's kepe the nubmer of > prefixes limited ;) I just came across gsm/apn.c (which seems to be a sensible place to put the conversion functions) where are currently definitions of osmo_apn_qualify and osmo_apn_qualify_from_imsi. So for the sake of consistency I can move the function there as osmo_apn_from_str/to_str. Jacob
diff --git a/sgsnemu/sgsnemu.c b/sgsnemu/sgsnemu.c index 5b56751..832bd97 100644 --- a/sgsnemu/sgsnemu.c +++ b/sgsnemu/sgsnemu.c @@ -231,6 +231,7 @@ int process_options(int argc, char **argv) char *type; char *mcc; char *mnc; + char *tok, *apn; char *lac; int lac_d; char *rest; @@ -534,10 +535,19 @@ int process_options(int argc, char **argv) printf("Invalid APN\n"); return -1; } - options.apn.l = strlen(args_info.apn_arg); - strncpy((char *)options.apn.v, args_info.apn_arg, - sizeof(options.apn.v)); - options.apn.v[sizeof(options.apn.v) - 1] = 0; + options.apn.l = strlen(args_info.apn_arg) + 1; + + apn = (char *)options.apn.v; + for (tok = strtok(args_info.apn_arg, "."); + tok != NULL; + tok = strtok(NULL, ".")) { + size_t len = strlen(tok); + + *apn++ = (char)len; + strncpy(apn, tok, len); + apn += len; + } + printf("Using APN: %s\n", args_info.apn_arg); /* selmode */