Merge commit '1523d7039d9b8c49a2174d93c3673aa8c5a100a9'
[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_SLOT,
26         GSM_SIM_TYPE_TEST
27 };
28
29 struct gsm_subscriber {
30         struct osmocom_ms       *ms;
31
32         /* status */
33         uint8_t                 sim_valid; /* sim inserted and valid */
34         uint8_t                 ustate; /* update status */
35         uint8_t                 imsi_attached; /* attached state */
36
37         /* LAI */
38         uint8_t                 lai_valid;
39         uint16_t                lai_mcc, lai_mnc, lai_lac;
40
41         /* IMSI */
42         char                    imsi[GSM_IMSI_LENGTH];
43
44         /* TMSI */
45         uint8_t                 tmsi_valid;
46         uint32_t                tmsi;
47
48         /* key */
49         uint8_t                 key_seq; /* ciphering key sequence number */
50         uint8_t                 key[32]; /* up to 256 bit */
51
52         /* other */
53         struct llist_head       plmn_list; /* PLMN Selector field */
54         struct llist_head       plmn_na; /* not allowed PLMNs */
55         uint8_t                 t6m_hplmn; /* timer for hplmn search */
56
57         /* special things */
58         uint8_t                 always_search_hplmn;
59                 /* search hplmn in other countries also (for test cards) */
60         char                    sim_name[32]; /* name to load/save sim */
61
62         /* PLMN last registered */
63         uint8_t                 plmn_valid;
64         uint16_t                plmn_mcc, plmn_mnc;
65
66         /* our access */
67         uint8_t                 acc_barr; /* if we may access, if cell barred */
68         uint16_t                acc_class; /* bitmask of what we may access */
69 };
70
71 int gsm_subscr_init(struct osmocom_ms *ms);
72 int gsm_subscr_exit(struct osmocom_ms *ms);
73 int gsm_subscr_testcard(struct osmocom_ms *ms, uint16_t mcc, uint16_t mnc);
74 int gsm_subscr_remove(struct osmocom_ms *ms);
75 void new_sim_ustate(struct gsm_subscriber *subscr, int state);
76 int gsm_subscr_del_forbidden_plmn(struct gsm_subscriber *subscr, uint16_t mcc,
77         uint16_t mnc);
78 int gsm_subscr_add_forbidden_plmn(struct gsm_subscriber *subscr, uint16_t mcc,
79                                         uint16_t mnc, uint8_t cause);
80 int gsm_subscr_is_forbidden_plmn(struct gsm_subscriber *subscr, uint16_t mcc,
81                                         uint16_t mnc);
82 int gsm_subscr_dump_forbidden_plmn(struct osmocom_ms *ms,
83                         void (*print)(void *, const char *, ...), void *priv);
84 void gsm_subscr_dump(struct gsm_subscriber *subscr,
85                         void (*print)(void *, const char *, ...), void *priv);
86 char *gsm_check_imsi(const char *imsi);
87
88 #endif /* _SUBSCRIBER_H */
89