Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 1 | #ifndef _GSM_DATA_H |
| 2 | #define _GSM_DATA_H |
| 3 | |
| 4 | #include <sys/types.h> |
| 5 | |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 6 | #include <openbsc/timer.h> |
Holger Freyther | 1adb4ff | 2009-02-04 00:04:52 +0000 | [diff] [blame] | 7 | #include <openbsc/gsm_04_08.h> |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 8 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 9 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 10 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 11 | #define GSM_MAX_BTS 8 |
| 12 | #define BTS_MAX_TRX 8 |
Harald Welte | 85770c7 | 2009-01-18 17:47:32 +0000 | [diff] [blame] | 13 | #define TRX_NR_TS 8 |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 14 | #define TS_MAX_LCHAN 8 |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 15 | |
| 16 | #define HARDCODED_ARFCN 123 |
| 17 | |
Harald Welte | 8e1e3ee | 2009-02-01 13:32:45 +0000 | [diff] [blame] | 18 | enum gsm_hooks { |
| 19 | GSM_HOOK_NM_SWLOAD, |
| 20 | }; |
| 21 | |
| 22 | struct msgb; |
| 23 | typedef int gsm_cbfn(unsigned int hooknum, |
| 24 | unsigned int event, |
| 25 | struct msgb *msg, |
| 26 | void *data, void *param); |
| 27 | |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 28 | /* |
| 29 | * Use the channel. As side effect the lchannel recycle timer |
| 30 | * will be started. |
| 31 | */ |
| 32 | #define LCHAN_RELEASE_TIMEOUT 4, 0 |
| 33 | #define use_lchan(lchan) \ |
| 34 | do { lchan->use_count++; \ |
| 35 | schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0); |
| 36 | |
| 37 | #define put_lchan(lchan) \ |
| 38 | do { lchan->use_count--; } while(0); |
| 39 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 40 | /* communications link with a BTS */ |
| 41 | struct gsm_bts_link { |
| 42 | struct gsm_bts *bts; |
| 43 | }; |
| 44 | |
Harald Welte | a3d0438 | 2008-12-27 17:02:56 +0000 | [diff] [blame] | 45 | enum gsm_call_type { |
| 46 | GSM_CT_NONE, |
| 47 | GSM_CT_MO, |
| 48 | GSM_CT_MT, |
| 49 | }; |
| 50 | |
| 51 | enum gsm_call_state { |
| 52 | GSM_CSTATE_NULL, |
| 53 | GSM_CSTATE_INITIATED, |
| 54 | GSM_CSTATE_ACTIVE, |
| 55 | GSM_CSTATE_RELEASE_REQ, |
| 56 | }; |
| 57 | |
| 58 | /* One end of a call */ |
| 59 | struct gsm_call { |
| 60 | enum gsm_call_type type; |
| 61 | enum gsm_call_state state; |
| 62 | u_int8_t transaction_id; /* 10.3.2 */ |
| 63 | |
| 64 | /* the 'local' subscriber */ |
| 65 | struct gsm_subscriber *subscr; |
| 66 | }; |
| 67 | |
| 68 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 69 | enum gsm_phys_chan_config { |
| 70 | GSM_PCHAN_NONE, |
| 71 | GSM_PCHAN_CCCH, |
| 72 | GSM_PCHAN_CCCH_SDCCH4, |
| 73 | GSM_PCHAN_TCH_F, |
| 74 | GSM_PCHAN_TCH_H, |
| 75 | GSM_PCHAN_SDCCH8_SACCH8C, |
| 76 | GSM_PCHAN_UNKNOWN, |
| 77 | }; |
| 78 | |
| 79 | enum gsm_chan_t { |
| 80 | GSM_LCHAN_NONE, |
| 81 | GSM_LCHAN_SDCCH, |
| 82 | GSM_LCHAN_TCH_F, |
| 83 | GSM_LCHAN_TCH_H, |
| 84 | GSM_LCHAN_UNKNOWN, |
| 85 | }; |
| 86 | |
Harald Welte | e14a57c | 2008-12-29 04:08:28 +0000 | [diff] [blame] | 87 | |
| 88 | /* Channel Request reason */ |
| 89 | enum gsm_chreq_reason_t { |
| 90 | GSM_CHREQ_REASON_EMERG, |
| 91 | GSM_CHREQ_REASON_PAG, |
| 92 | GSM_CHREQ_REASON_CALL, |
| 93 | GSM_CHREQ_REASON_LOCATION_UPD, |
| 94 | GSM_CHREQ_REASON_OTHER, |
| 95 | }; |
| 96 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 97 | /* |
| 98 | * LOCATION UPDATING REQUEST state |
| 99 | * |
| 100 | * Our current operation is: |
| 101 | * - Get imei/tmsi |
| 102 | * - Accept/Reject according to global policy |
| 103 | */ |
| 104 | struct gsm_loc_updating_operation { |
| 105 | struct timer_list updating_timer; |
| 106 | int waiting_for_imsi : 1; |
| 107 | int waiting_for_imei : 1; |
| 108 | }; |
| 109 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 110 | struct gsm_lchan { |
| 111 | /* The TS that we're part of */ |
| 112 | struct gsm_bts_trx_ts *ts; |
| 113 | /* The logical subslot number in the TS */ |
| 114 | u_int8_t nr; |
| 115 | /* The lotical channel type */ |
| 116 | enum gsm_chan_t type; |
| 117 | /* To whom we are allocated at the moment */ |
| 118 | struct gsm_subscriber *subscr; |
Holger Freyther | c6ea9db | 2008-12-30 19:18:21 +0000 | [diff] [blame] | 119 | |
| 120 | /* Timer started to release the channel */ |
| 121 | struct timer_list release_timer; |
Harald Welte | a3d0438 | 2008-12-27 17:02:56 +0000 | [diff] [blame] | 122 | |
| 123 | /* local end of a call, if any */ |
| 124 | struct gsm_call call; |
Holger Freyther | 3186bf2 | 2008-12-29 06:23:49 +0000 | [diff] [blame] | 125 | |
| 126 | /* temporary user data, to be removed... and merged into gsm_call */ |
| 127 | void *user_data; |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 128 | |
Holger Freyther | 73487a2 | 2008-12-31 18:53:57 +0000 | [diff] [blame] | 129 | /* |
| 130 | * Operations that have a state and might be pending |
| 131 | */ |
| 132 | struct gsm_loc_updating_operation *loc_operation; |
| 133 | |
Holger Freyther | b7193e4 | 2008-12-29 17:44:08 +0000 | [diff] [blame] | 134 | /* use count. how many users use this channel */ |
| 135 | unsigned int use_count; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 136 | }; |
| 137 | |
Harald Welte | 85770c7 | 2009-01-18 17:47:32 +0000 | [diff] [blame] | 138 | struct gsm_e1_subslot { |
| 139 | /* Number of E1 link */ |
| 140 | u_int8_t e1_nr; |
| 141 | /* Number of E1 TS inside E1 link */ |
| 142 | u_int8_t e1_ts; |
| 143 | /* Sub-slot within the E1 TS, 0xff if full TS */ |
| 144 | u_int8_t e1_ts_ss; |
| 145 | }; |
| 146 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 147 | #define BTS_TRX_F_ACTIVATED 0x0001 |
| 148 | /* One Timeslot in a TRX */ |
| 149 | struct gsm_bts_trx_ts { |
| 150 | struct gsm_bts_trx *trx; |
| 151 | /* number of this timeslot at the TRX */ |
| 152 | u_int8_t nr; |
| 153 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 154 | enum gsm_phys_chan_config pchan; |
| 155 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 156 | unsigned int flags; |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 157 | |
Harald Welte | 85770c7 | 2009-01-18 17:47:32 +0000 | [diff] [blame] | 158 | /* To which E1 subslot are we connected */ |
| 159 | struct gsm_e1_subslot e1_link; |
| 160 | |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 161 | struct gsm_lchan lchan[TS_MAX_LCHAN]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | /* One TRX in a BTS */ |
| 165 | struct gsm_bts_trx { |
| 166 | struct gsm_bts *bts; |
| 167 | /* number of this TRX in the BTS */ |
| 168 | u_int8_t nr; |
| 169 | |
| 170 | u_int16_t arfcn; |
Harald Welte | 85770c7 | 2009-01-18 17:47:32 +0000 | [diff] [blame] | 171 | struct gsm_bts_trx_ts ts[TRX_NR_TS]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 172 | }; |
| 173 | |
Harald Welte | 978cb42 | 2009-01-18 17:57:27 +0000 | [diff] [blame] | 174 | enum gsm_bts_type { |
| 175 | GSM_BTS_TYPE_UNKNOWN, |
| 176 | GSM_BTS_TYPE_BS11, |
| 177 | }; |
| 178 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 179 | /* One BTS */ |
| 180 | struct gsm_bts { |
| 181 | struct gsm_network *network; |
| 182 | /* number of ths BTS in network */ |
| 183 | u_int8_t nr; |
| 184 | /* location area code of this BTS */ |
| 185 | u_int8_t location_area_code; |
Harald Welte | 978cb42 | 2009-01-18 17:57:27 +0000 | [diff] [blame] | 186 | /* type of BTS */ |
| 187 | enum gsm_bts_type type; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 188 | |
| 189 | /* Abis network management O&M handle */ |
| 190 | struct abis_nm_h *nmh; |
Harald Welte | 978cb42 | 2009-01-18 17:57:27 +0000 | [diff] [blame] | 191 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 192 | /* number of this BTS on given E1 link */ |
| 193 | u_int8_t bts_nr; |
| 194 | |
Holger Freyther | 1adb4ff | 2009-02-04 00:04:52 +0000 | [diff] [blame] | 195 | struct gsm48_control_channel_descr chan_desc; |
| 196 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 197 | /* CCCH is on C0 */ |
| 198 | struct gsm_bts_trx *c0; |
| 199 | /* transceivers */ |
| 200 | int num_trx; |
| 201 | struct gsm_bts_trx trx[BTS_MAX_TRX+1]; |
| 202 | }; |
| 203 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 204 | struct gsm_network { |
| 205 | /* global parameters */ |
Harald Welte | b84e2f4 | 2008-12-28 23:42:04 +0000 | [diff] [blame] | 206 | u_int16_t country_code; |
| 207 | u_int16_t network_code; |
Harald Welte | c6ba9c2 | 2008-12-30 18:01:02 +0000 | [diff] [blame] | 208 | char *name_long; |
| 209 | char *name_short; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 210 | |
| 211 | unsigned int num_bts; |
| 212 | /* private lists */ |
| 213 | struct gsm_bts bts[GSM_MAX_BTS+1]; |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 214 | }; |
| 215 | |
Harald Welte | b84e2f4 | 2008-12-28 23:42:04 +0000 | [diff] [blame] | 216 | struct gsm_network *gsm_network_init(unsigned int num_bts, u_int16_t country_code, |
| 217 | u_int16_t network_code); |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 218 | |
Harald Welte | a72c98e | 2009-01-04 16:10:38 +0000 | [diff] [blame] | 219 | const char *gsm_pchan_name(enum gsm_phys_chan_config c); |
| 220 | const char *gsm_lchan_name(enum gsm_chan_t c); |
| 221 | const char *gsm_chreq_name(enum gsm_chreq_reason_t c); |
| 222 | |
Harald Welte | ad38464 | 2008-12-26 10:20:07 +0000 | [diff] [blame] | 223 | enum gsm_e1_event { |
| 224 | EVT_E1_NONE, |
| 225 | EVT_E1_OML_UP, |
| 226 | EVT_E1_RSL_UP, |
| 227 | EVT_E1_OML_DN, |
| 228 | EVT_E1_RSL_DN, |
| 229 | }; |
| 230 | |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 231 | #endif |