summaryrefslogtreecommitdiff
path: root/src/gsmd/operator_cache.c
diff options
context:
space:
mode:
authorlaforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3>2007-03-10 22:05:17 +0000
committerlaforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3>2007-03-10 22:05:17 +0000
commit3026b93e266558671bd361b6c07546f8174974bc (patch)
treec579158bc0641847851a1369382d3dc250268ebc /src/gsmd/operator_cache.c
parent2797211645d452446cb7b329ee9d3d3a923f8520 (diff)
* include stdio from talloc.h
* add new generic extended-response parser * add operator cache, using ext-resp-parser * add proper detection of supported %CPI modes and select highest available one * add %CTZV to vendor_ti init string git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@1316 99fdad57-331a-0410-800a-d7fa5415bdb3
Diffstat (limited to 'src/gsmd/operator_cache.c')
-rw-r--r--src/gsmd/operator_cache.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/gsmd/operator_cache.c b/src/gsmd/operator_cache.c
new file mode 100644
index 0000000..e680706
--- /dev/null
+++ b/src/gsmd/operator_cache.c
@@ -0,0 +1,99 @@
+/* gsmd cache of operator names
+ *
+ * (C) 2006-2007 by OpenMoko, Inc.
+ * Written by Harald Welte <laforge@openmoko.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include "gsmd.h"
+
+#include <common/linux_list.h>
+#include <gsmd/gsmd.h>
+#include <gsmd/talloc.h>
+
+static void *__opc_ctx;
+
+struct opname {
+ struct llist_head list;
+ struct {
+ u_int16_t mcc; /* mobile country code */
+ u_int8_t mnc; /* mobile network code */
+ } numeric;
+ char alnum_long[16+1];
+ //char alnum_short[8+1];
+};
+
+/* add an entry to the operator name list, overwrite existing entries for
+ * same mcc/mnc */
+static int _opname_add(struct gsmd *g, struct opname *op)
+{
+ struct opname *cur, *cur2;
+
+ llist_for_each_entry_safe(cur, cur2, &g->operators, list) {
+ if (op->numeric.mcc == cur->numeric.mcc &&
+ op->numeric.mnc == cur->numeric.mnc) {
+ llist_del(&cur->list);
+ talloc_free(cur);
+ }
+ }
+ llist_add_tail(&op->list, &g->operators);
+
+ return 0;
+}
+
+int gsmd_opname_add(struct gsmd *g, const char *numeric_bcd_string,
+ const char *alnum_long)
+{
+ struct opname *op;
+ char mcc[3+1];
+ char mnc[2+1];
+
+ if (strlen(numeric_bcd_string) != 5)
+ return -EINVAL;
+
+ op = talloc(__opc_ctx, struct opname);
+ if (!op)
+ return -ENOMEM;
+
+ memset(mcc, 0, sizeof(mcc));
+ memset(mnc, 0, sizeof(mnc));
+
+ strncpy(mcc, numeric_bcd_string, 3);
+ strncpy(mnc, numeric_bcd_string+3, 2);
+
+ strncpy(op->alnum_long, alnum_long, sizeof(op->alnum_long-1));
+ op->numeric.mcc = atoi(mcc);
+ op->numeric.mnc = atoi(mnc);
+
+ return _opname_add(g, op);
+}
+
+int gsmd_opname_init(struct gsmd *g)
+{
+ INIT_LLIST_HEAD(&g->operators);
+
+ __opc_ctx = talloc_named_const(gsmd_tallocs, 1, "operator_cache");
+
+ return 0;
+}
personal git repositories of Harald Welte. Your mileage may vary