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/logging.h>
28 #include <osmocom/osmocom_data.h>
29 #include <osmocom/networks.h>
31 int gsm_settings_init(struct osmocom_ms *ms)
33 struct gsm_settings *set = &ms->settings;
36 sprintf(set->imei, "000000000000000");
37 sprintf(set->imeisv, "0000000000000000");
40 strcpy(set->test_imsi, "001010000000000");
41 set->test_rplmn_mcc = set->test_rplmn_mnc = 1;
46 char *gsm_check_imei(const char *imei, const char *sv)
50 if (!imei || strlen(imei) != 15)
51 return "IMEI must have 15 digits!";
53 for (i = 0; i < strlen(imei); i++) {
54 if (imei[i] < '0' || imei[i] > '9')
55 return "IMEI must have digits 0 to 9 only!";
58 if (!sv || strlen(sv) != 1)
59 return "Software version must have 1 digit!";
61 if (sv[0] < '0' || sv[0] > '9')
62 return "Software version must have digits 0 to 9 only!";
67 int gsm_random_imei(struct gsm_settings *set)
69 int digits = set->imei_random;
77 sprintf(rand, "%08ld", random() % 100000000);
78 sprintf(rand + 8, "%07ld", random() % 10000000);
80 strcpy(set->imei + 15 - digits, rand + 15 - digits);
81 strncpy(set->imeisv, set->imei, 15);