[layer23] Fixed security issue
[osmocom-bb.git] / src / host / layer23 / include / osmocom / bb / mobile / subscriber.h
1 #ifndef _SUBSCRIBER_H
2 #define _SUBSCRIBER_H
3
4 /* GSM 04.08 4.1.2.2 SIM update status */
5 #define GSM_SIM_U0_NULL         0
6 #define GSM_SIM_U1_UPDATED      1
7 #define GSM_SIM_U2_NOT_UPDATED  2
8 #define GSM_SIM_U3_ROAMING_NA   3
9
10 struct gsm_sub_plmn_list {
11         struct llist_head       entry;
12         uint16_t                mcc, mnc;
13 };
14
15 struct gsm_sub_plmn_na {
16         struct llist_head       entry;
17         uint16_t                mcc, mnc;
18         uint8_t                 cause;
19 };
20
21 #define GSM_IMSI_LENGTH         16
22
23 enum {
24         GSM_SIM_TYPE_NONE = 0,
25         GSM_SIM_TYPE_READER,
26         GSM_SIM_TYPE_TEST
27 };
28
29 /* state of reading SIM */
30 enum {
31         SUBSCR_SIM_NULL = 0,
32 };
33
34 struct gsm_subscriber {
35         struct osmocom_ms       *ms;
36
37         /* status */
38         uint8_t                 sim_type; /* type of sim */
39         uint8_t                 sim_valid; /* sim inserted and valid */
40         uint8_t                 ustate; /* update status */
41         uint8_t                 imsi_attached; /* attached state */
42
43         /* IMSI & co */
44         char                    imsi[GSM_IMSI_LENGTH];
45         char                    msisdn[31]; /* may include access codes */
46         char                    iccid[21]; /* 20 + termination */
47
48         /* TMSI / LAI */
49         uint32_t                tmsi; /* invalid tmsi: 0xffffffff */
50         uint16_t                mcc, mnc, lac; /* invalid lac: 0x0000 */
51
52
53         /* key */
54         uint8_t                 key_seq; /* ciphering key sequence number */
55         uint8_t                 key[64]; /* 64 bit */
56
57         /* other */
58         struct llist_head       plmn_list; /* PLMN Selector field */
59         struct llist_head       plmn_na; /* not allowed PLMNs */
60         uint8_t                 t6m_hplmn; /* timer for hplmn search */
61
62         /* special things */
63         uint8_t                 always_search_hplmn;
64                 /* search hplmn in other countries also (for test cards) */
65         char                    sim_name[31]; /* name to load/save sim */
66         char                    sim_spn[17]; /* name of service privider */
67
68         /* PLMN last registered */
69         uint8_t                 plmn_valid;
70         uint16_t                plmn_mcc, plmn_mnc;
71
72         /* our access */
73         uint8_t                 acc_barr; /* if we may access, if cell barred */
74         uint16_t                acc_class; /* bitmask of what we may access */
75
76         /* talk to SIM */
77         uint8_t                 sim_state;
78         uint8_t                 sim_pin_required; /* state: wait for PIN */
79         uint8_t                 sim_file_index;
80         uint32_t                sim_handle_query;
81         uint32_t                sim_handle_update;
82         uint32_t                sim_handle_key;
83 };
84
85 int gsm_subscr_init(struct osmocom_ms *ms);
86 int gsm_subscr_exit(struct osmocom_ms *ms);
87 int gsm_subscr_testcard(struct osmocom_ms *ms, uint16_t mcc, uint16_t mnc);
88 int gsm_subscr_simcard(struct osmocom_ms *ms);
89 void gsm_subscr_sim_pin(struct osmocom_ms *ms, char *pin);
90 int gsm_subscr_write_loci(struct osmocom_ms *ms);
91 int gsm_subscr_generate_kc(struct osmocom_ms *ms, uint8_t key_seq,
92         uint8_t *rand, uint8_t no_sim);
93 int gsm_subscr_remove(struct osmocom_ms *ms);
94 void new_sim_ustate(struct gsm_subscriber *subscr, int state);
95 int gsm_subscr_del_forbidden_plmn(struct gsm_subscriber *subscr, uint16_t mcc,
96         uint16_t mnc);
97 int gsm_subscr_add_forbidden_plmn(struct gsm_subscriber *subscr, uint16_t mcc,
98                                         uint16_t mnc, uint8_t cause);
99 int gsm_subscr_is_forbidden_plmn(struct gsm_subscriber *subscr, uint16_t mcc,
100                                         uint16_t mnc);
101 int gsm_subscr_dump_forbidden_plmn(struct osmocom_ms *ms,
102                         void (*print)(void *, const char *, ...), void *priv);
103 void gsm_subscr_dump(struct gsm_subscriber *subscr,
104                         void (*print)(void *, const char *, ...), void *priv);
105 char *gsm_check_imsi(const char *imsi);
106
107 #endif /* _SUBSCRIBER_H */
108