Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1 | #ifndef _GSM_SUBSCR_H |
| 2 | #define _GSM_SUBSCR_H |
| 3 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 4 | #include "gsm_data.h" |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 5 | #include <osmocom/core/linuxlist.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 6 | |
Jan Luebbe | fac25fc | 2008-12-27 18:04:34 +0000 | [diff] [blame] | 7 | #define GSM_IMEI_LENGTH 17 |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 8 | #define GSM_IMSI_LENGTH 17 |
Holger Hans Peter Freyther | fa530cd | 2010-07-25 18:10:02 +0800 | [diff] [blame] | 9 | #define GSM_NAME_LENGTH 160 |
Mike Haben | 2449b37 | 2009-10-26 20:36:34 +0100 | [diff] [blame] | 10 | |
| 11 | #define GSM_EXTENSION_LENGTH 15 /* MSISDN can only be 15 digits length */ |
| 12 | #define GSM_MIN_EXTEN 20000 |
| 13 | #define GSM_MAX_EXTEN 49999 |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 14 | |
Jan Luebbe | b0dfc31 | 2009-08-12 10:12:52 +0200 | [diff] [blame] | 15 | #define GSM_SUBSCRIBER_FIRST_CONTACT 0x00000001 |
Holger Hans Peter Freyther | 2223025 | 2009-08-19 12:53:57 +0200 | [diff] [blame] | 16 | #define tmsi_from_string(str) strtoul(str, NULL, 10) |
Jan Luebbe | b0dfc31 | 2009-08-12 10:12:52 +0200 | [diff] [blame] | 17 | |
Holger Hans Peter Freyther | 763b42a | 2010-12-29 11:07:22 +0100 | [diff] [blame] | 18 | struct vty; |
| 19 | |
Harald Welte | c2e302d | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 20 | struct gsm_equipment { |
| 21 | long long unsigned int id; |
| 22 | char imei[GSM_IMEI_LENGTH]; |
| 23 | char name[GSM_NAME_LENGTH]; |
| 24 | |
| 25 | struct gsm48_classmark1 classmark1; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 26 | uint8_t classmark2_len; |
| 27 | uint8_t classmark2[3]; |
| 28 | uint8_t classmark3_len; |
| 29 | uint8_t classmark3[14]; |
Harald Welte | c2e302d | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 30 | }; |
| 31 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 32 | struct gsm_subscriber { |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 33 | struct gsm_network *net; |
Holger Freyther | 213b20b | 2009-06-02 03:24:54 +0000 | [diff] [blame] | 34 | long long unsigned int id; |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 35 | char imsi[GSM_IMSI_LENGTH]; |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 36 | uint32_t tmsi; |
| 37 | uint16_t lac; |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 38 | char name[GSM_NAME_LENGTH]; |
Jan Luebbe | 391d86e | 2008-12-27 22:33:34 +0000 | [diff] [blame] | 39 | char extension[GSM_EXTENSION_LENGTH]; |
Jan Luebbe | 6e2e545 | 2008-12-27 16:47:55 +0000 | [diff] [blame] | 40 | int authorized; |
Holger Freyther | 12aa50d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 41 | |
Jan Luebbe | b0dfc31 | 2009-08-12 10:12:52 +0200 | [diff] [blame] | 42 | /* Temporary field which is not stored in the DB/HLR */ |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 43 | uint32_t flags; |
Jan Luebbe | b0dfc31 | 2009-08-12 10:12:52 +0200 | [diff] [blame] | 44 | |
Harald Welte | c2e302d | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 45 | /* Every user can only have one equipment in use at any given |
| 46 | * point in time */ |
| 47 | struct gsm_equipment equipment; |
| 48 | |
Holger Freyther | 862cfff | 2009-06-04 14:15:33 +0000 | [diff] [blame] | 49 | /* for internal management */ |
Holger Freyther | 12aa50d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 50 | int use_count; |
| 51 | struct llist_head entry; |
Harald Welte | f7c4352 | 2009-06-09 20:24:21 +0000 | [diff] [blame] | 52 | |
Holger Freyther | 04866d4 | 2009-03-31 04:35:19 +0200 | [diff] [blame] | 53 | /* pending requests */ |
Holger Freyther | 85a7b36 | 2009-04-18 13:48:55 +0200 | [diff] [blame] | 54 | int in_callback; |
Holger Freyther | 04866d4 | 2009-03-31 04:35:19 +0200 | [diff] [blame] | 55 | struct llist_head requests; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 58 | enum gsm_subscriber_field { |
| 59 | GSM_SUBSCRIBER_IMSI, |
| 60 | GSM_SUBSCRIBER_TMSI, |
Holger Freyther | 9c564b8 | 2009-02-09 23:39:20 +0000 | [diff] [blame] | 61 | GSM_SUBSCRIBER_EXTENSION, |
Harald Welte | be3e378 | 2009-07-05 14:06:41 +0200 | [diff] [blame] | 62 | GSM_SUBSCRIBER_ID, |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 63 | }; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 64 | |
Holger Freyther | 4a49e77 | 2009-04-12 05:37:29 +0000 | [diff] [blame] | 65 | enum gsm_subscriber_update_reason { |
| 66 | GSM_SUBSCRIBER_UPDATE_ATTACHED, |
| 67 | GSM_SUBSCRIBER_UPDATE_DETACHED, |
Harald Welte | c2e302d | 2009-07-05 14:08:13 +0200 | [diff] [blame] | 68 | GSM_SUBSCRIBER_UPDATE_EQUIPMENT, |
Holger Freyther | 4a49e77 | 2009-04-12 05:37:29 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
Holger Freyther | 12aa50d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 71 | struct gsm_subscriber *subscr_get(struct gsm_subscriber *subscr); |
| 72 | struct gsm_subscriber *subscr_put(struct gsm_subscriber *subscr); |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 73 | struct gsm_subscriber *subscr_get_by_tmsi(struct gsm_network *net, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 74 | uint32_t tmsi); |
Harald Welte | 9176bd4 | 2009-07-23 18:46:00 +0200 | [diff] [blame] | 75 | struct gsm_subscriber *subscr_get_by_imsi(struct gsm_network *net, |
| 76 | const char *imsi); |
| 77 | struct gsm_subscriber *subscr_get_by_extension(struct gsm_network *net, |
| 78 | const char *ext); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 79 | struct gsm_subscriber *subscr_get_by_id(struct gsm_network *net, |
| 80 | unsigned long long id); |
Holger Hans Peter Freyther | d740b68 | 2010-11-15 09:15:01 +0100 | [diff] [blame] | 81 | struct gsm_subscriber *subscr_get_or_create(struct gsm_network *net, |
| 82 | const char *imsi); |
Holger Freyther | 4a49e77 | 2009-04-12 05:37:29 +0000 | [diff] [blame] | 83 | int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts, int reason); |
Holger Hans Peter Freyther | 725966d | 2010-12-27 22:43:28 +0100 | [diff] [blame] | 84 | void subscr_put_channel(struct gsm_subscriber *subscr); |
Holger Freyther | 04866d4 | 2009-03-31 04:35:19 +0200 | [diff] [blame] | 85 | void subscr_get_channel(struct gsm_subscriber *subscr, |
Holger Hans Peter Freyther | e4e8bf4 | 2009-08-20 13:33:51 +0200 | [diff] [blame] | 86 | int type, gsm_cbfn *cbfn, void *param); |
Holger Hans Peter Freyther | 8dfd241 | 2010-11-15 13:32:33 +0100 | [diff] [blame] | 87 | struct gsm_subscriber *subscr_active_by_tmsi(struct gsm_network *net, |
| 88 | uint32_t tmsi); |
| 89 | struct gsm_subscriber *subscr_active_by_imsi(struct gsm_network *net, |
| 90 | const char *imsi); |
Holger Freyther | a471a41 | 2009-01-04 03:47:05 +0000 | [diff] [blame] | 91 | |
Holger Hans Peter Freyther | ebdd3cb | 2010-12-28 22:12:30 +0100 | [diff] [blame] | 92 | int subscr_pending_requests(struct gsm_subscriber *subscr); |
Holger Hans Peter Freyther | fc85741 | 2010-12-28 22:21:55 +0100 | [diff] [blame] | 93 | int subscr_pending_clear(struct gsm_subscriber *subscr); |
Holger Hans Peter Freyther | 763b42a | 2010-12-29 11:07:22 +0100 | [diff] [blame] | 94 | int subscr_pending_dump(struct gsm_subscriber *subscr, struct vty *vty); |
Holger Hans Peter Freyther | 451eb29 | 2010-12-29 13:45:49 +0100 | [diff] [blame] | 95 | int subscr_pending_kick(struct gsm_subscriber *subscr); |
Holger Hans Peter Freyther | ebdd3cb | 2010-12-28 22:12:30 +0100 | [diff] [blame] | 96 | |
Harald Welte | 2e6d468 | 2009-12-24 14:50:24 +0100 | [diff] [blame] | 97 | char *subscr_name(struct gsm_subscriber *subscr); |
| 98 | |
Holger Hans Peter Freyther | f694d5f | 2010-12-22 14:31:34 +0100 | [diff] [blame] | 99 | int subscr_purge_inactive(struct gsm_network *net); |
Holger Hans Peter Freyther | abd0cac | 2010-12-22 18:12:11 +0100 | [diff] [blame] | 100 | void subscr_update_from_db(struct gsm_subscriber *subscr); |
Holger Hans Peter Freyther | f694d5f | 2010-12-22 14:31:34 +0100 | [diff] [blame] | 101 | |
Holger Freyther | a471a41 | 2009-01-04 03:47:05 +0000 | [diff] [blame] | 102 | /* internal */ |
| 103 | struct gsm_subscriber *subscr_alloc(void); |
Harald Welte (local) | 15920de | 2009-08-14 20:27:16 +0200 | [diff] [blame] | 104 | extern struct llist_head active_subscribers; |
Holger Freyther | 12aa50d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 105 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 106 | #endif /* _GSM_SUBSCR_H */ |