2 * (C) 2010 by Andreas Eversberg <jolly@eversberg.eu>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <osmocore/talloc.h>
27 #include <osmocom/bb/common/logging.h>
28 #include <osmocom/bb/common/osmocom_data.h>
29 #include <osmocom/bb/common/networks.h>
31 static char *layer2_socket_path = "/tmp/osmocom_l2";
32 static char *sap_socket_path = "/tmp/osmocom_sap";
34 int gsm_settings_init(struct osmocom_ms *ms)
36 struct gsm_settings *set = &ms->settings;
37 struct gsm_support *sup = &ms->support;
39 strcpy(set->layer2_socket_path, layer2_socket_path);
40 strcpy(set->sap_socket_path, sap_socket_path);
43 sprintf(set->imei, "000000000000000");
44 sprintf(set->imeisv, "0000000000000000");
47 #warning TODO: Enable after SIM reader is available in master branch.
48 // set->sim_type = SIM_TYPE_READER;
51 strcpy(set->test_imsi, "001010000000000");
52 set->test_rplmn_mcc = set->test_rplmn_mnc = 1;
53 set->test_lac = 0x0000;
54 set->test_tmsi = 0xffffffff;
56 /* set all supported features */
57 set->sms_ptp = sup->sms_ptp;
58 set->a5_1 = sup->a5_1;
59 set->a5_2 = sup->a5_2;
60 set->a5_3 = sup->a5_3;
61 set->a5_4 = sup->a5_4;
62 set->a5_5 = sup->a5_5;
63 set->a5_6 = sup->a5_6;
64 set->a5_7 = sup->a5_7;
65 set->p_gsm = sup->p_gsm;
66 set->e_gsm = sup->e_gsm;
67 set->r_gsm = sup->r_gsm;
69 set->class_900 = sup->class_900;
70 set->class_dcs = sup->class_dcs;
71 set->full_v1 = sup->full_v1;
72 set->full_v2 = sup->full_v2;
73 set->full_v3 = sup->full_v3;
74 set->half_v1 = sup->half_v1;
75 set->half_v3 = sup->half_v3;
76 set->ch_cap = sup->ch_cap;
77 set->min_rxlev_db = sup->min_rxlev_db;
78 set->dsc_max = sup->dsc_max;
80 if (sup->half_v1 || sup->half_v3)
83 /* software features */
86 INIT_LLIST_HEAD(&set->abbrev);
91 int gsm_settings_exit(struct osmocom_ms *ms)
93 struct gsm_settings *set = &ms->settings;
94 struct gsm_settings_abbrev *abbrev;
96 while (!llist_empty(&set->abbrev)) {
97 abbrev = llist_entry(set->abbrev.next,
98 struct gsm_settings_abbrev, list);
99 llist_del(&abbrev->list);
106 char *gsm_check_imei(const char *imei, const char *sv)
110 if (!imei || strlen(imei) != 15)
111 return "IMEI must have 15 digits!";
113 for (i = 0; i < strlen(imei); i++) {
114 if (imei[i] < '0' || imei[i] > '9')
115 return "IMEI must have digits 0 to 9 only!";
118 if (!sv || strlen(sv) != 1)
119 return "Software version must have 1 digit!";
121 if (sv[0] < '0' || sv[0] > '9')
122 return "Software version must have digits 0 to 9 only!";
127 int gsm_random_imei(struct gsm_settings *set)
129 int digits = set->imei_random;
137 sprintf(rand, "%08ld", random() % 100000000);
138 sprintf(rand + 8, "%07ld", random() % 10000000);
140 strcpy(set->imei + 15 - digits, rand + 15 - digits);
141 strncpy(set->imeisv, set->imei, 15);