Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1 | /* pcu_l1_if.cpp |
| 2 | * |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 3 | * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu> |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <unistd.h> |
| 22 | #include <stdlib.h> |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 23 | #include <string.h> |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 24 | #include <errno.h> |
| 25 | #include <assert.h> |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 26 | #include <sys/socket.h> |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 27 | #include <sys/un.h> |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 28 | extern "C" { |
| 29 | #include <osmocom/core/talloc.h> |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 30 | #include <osmocom/core/select.h> |
| 31 | #include <osmocom/core/msgb.h> |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 32 | } |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 33 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 34 | #include <gprs_rlcmac.h> |
| 35 | #include <pcu_l1_if.h> |
| 36 | #include <gprs_debug.h> |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 37 | #include <gprs_bssgp_pcu.h> |
| 38 | #include <pcuif_proto.h> |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 39 | |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 40 | extern void *tall_pcu_ctx; |
| 41 | |
Ivan Kluchnikov | 4277f0c | 2012-04-12 14:24:35 +0400 | [diff] [blame] | 42 | // Variable for storage current FN. |
| 43 | int frame_number; |
| 44 | |
| 45 | int get_current_fn() |
| 46 | { |
| 47 | return frame_number; |
| 48 | } |
| 49 | |
| 50 | void set_current_fn(int fn) |
| 51 | { |
| 52 | frame_number = fn; |
| 53 | } |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 54 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 55 | /* |
| 56 | * PCU messages |
| 57 | */ |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 58 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 59 | struct msgb *pcu_msgb_alloc(uint8_t msg_type, uint8_t bts_nr) |
| 60 | { |
| 61 | struct msgb *msg; |
| 62 | struct gsm_pcu_if *pcu_prim; |
| 63 | |
| 64 | msg = msgb_alloc(sizeof(struct gsm_pcu_if), "pcu_sock_tx"); |
| 65 | if (!msg) |
| 66 | return NULL; |
| 67 | msgb_put(msg, sizeof(struct gsm_pcu_if)); |
| 68 | pcu_prim = (struct gsm_pcu_if *) msg->data; |
| 69 | pcu_prim->msg_type = msg_type; |
| 70 | pcu_prim->bts_nr = bts_nr; |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 71 | |
| 72 | return msg; |
| 73 | } |
| 74 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 75 | static int pcu_tx_act_req(uint8_t trx, uint8_t ts, uint8_t activate) |
Ivan Kluchnikov | 4277f0c | 2012-04-12 14:24:35 +0400 | [diff] [blame] | 76 | { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 77 | struct msgb *msg; |
| 78 | struct gsm_pcu_if *pcu_prim; |
| 79 | struct gsm_pcu_if_act_req *act_req; |
| 80 | |
| 81 | LOGP(DL1IF, LOGL_INFO, "Sending %s request: trx=%d ts=%d\n", |
| 82 | (activate) ? "activate" : "deactivate", trx, ts); |
| 83 | |
| 84 | msg = pcu_msgb_alloc(PCU_IF_MSG_ACT_REQ, 0); |
| 85 | if (!msg) |
| 86 | return -ENOMEM; |
| 87 | pcu_prim = (struct gsm_pcu_if *) msg->data; |
| 88 | act_req = &pcu_prim->u.act_req; |
| 89 | act_req->activate = activate; |
| 90 | act_req->trx_nr = trx; |
| 91 | act_req->ts_nr = ts; |
| 92 | |
| 93 | return pcu_sock_send(msg); |
| 94 | } |
| 95 | |
| 96 | static int pcu_tx_data_req(uint8_t trx, uint8_t ts, uint8_t sapi, |
| 97 | uint16_t arfcn, uint32_t fn, uint8_t block_nr, uint8_t *data, |
| 98 | uint8_t len) |
| 99 | { |
| 100 | struct msgb *msg; |
| 101 | struct gsm_pcu_if *pcu_prim; |
| 102 | struct gsm_pcu_if_data *data_req; |
| 103 | |
| 104 | LOGP(DL1IF, LOGL_DEBUG, "Sending data request: trx=%d ts=%d sapi=%d " |
| 105 | "arfcn=%d fn=%d block=%d data=%s\n", trx, ts, sapi, arfcn, fn, |
| 106 | block_nr, osmo_hexdump(data, len)); |
| 107 | |
| 108 | msg = pcu_msgb_alloc(PCU_IF_MSG_DATA_REQ, 0); |
| 109 | if (!msg) |
| 110 | return -ENOMEM; |
| 111 | pcu_prim = (struct gsm_pcu_if *) msg->data; |
| 112 | data_req = &pcu_prim->u.data_req; |
| 113 | |
| 114 | data_req->sapi = sapi; |
| 115 | data_req->fn = fn; |
| 116 | data_req->arfcn = arfcn; |
| 117 | data_req->trx_nr = trx; |
| 118 | data_req->ts_nr = ts; |
| 119 | data_req->block_nr = block_nr; |
| 120 | memcpy(data_req->data, data, len); |
| 121 | data_req->len = len; |
| 122 | |
| 123 | return pcu_sock_send(msg); |
| 124 | } |
| 125 | |
| 126 | void pcu_l1if_tx_pdtch(msgb *msg, uint8_t trx, uint8_t ts, uint16_t arfcn, |
| 127 | uint32_t fn, uint8_t block_nr) |
| 128 | { |
| 129 | pcu_tx_data_req(trx, ts, PCU_IF_SAPI_PDTCH, arfcn, fn, block_nr, |
| 130 | msg->data, msg->len); |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 131 | msgb_free(msg); |
Ivan Kluchnikov | 4277f0c | 2012-04-12 14:24:35 +0400 | [diff] [blame] | 132 | } |
| 133 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 134 | void pcu_l1if_tx_ptcch(msgb *msg, uint8_t trx, uint8_t ts, uint16_t arfcn, |
| 135 | uint32_t fn, uint8_t block_nr) |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 136 | { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 137 | pcu_tx_data_req(trx, ts, PCU_IF_SAPI_PTCCH, arfcn, fn, block_nr, |
| 138 | msg->data, msg->len); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 139 | msgb_free(msg); |
| 140 | } |
| 141 | |
Andreas Eversberg | 7b04501 | 2012-07-05 07:38:49 +0200 | [diff] [blame] | 142 | void pcu_l1if_tx_agch(bitvec * block, int plen) |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 143 | { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 144 | uint8_t data[23]; /* prefix PLEN */ |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 145 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 146 | /* FIXME: why does OpenBTS has no PLEN and no fill in message? */ |
| 147 | bitvec_pack(block, data + 1); |
| 148 | data[0] = (plen << 2) | 0x01; |
| 149 | pcu_tx_data_req(0, 0, PCU_IF_SAPI_AGCH, 0, 0, 0, data, 23); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 150 | } |
| 151 | |
Andreas Eversberg | e13fa2d | 2012-07-09 17:10:44 +0200 | [diff] [blame] | 152 | void pcu_l1if_tx_pch(bitvec * block, int plen, char *imsi) |
Ivan Kluchnikov | c7e7f68 | 2012-06-29 22:53:15 +0400 | [diff] [blame] | 153 | { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 154 | uint8_t data[23+3]; /* prefix PLEN */ |
| 155 | |
| 156 | /* paging group */ |
| 157 | if (!imsi || strlen(imsi) < 3) |
| 158 | return; |
| 159 | imsi += strlen(imsi) - 3; |
| 160 | data[0] = imsi[0]; |
| 161 | data[1] = imsi[1]; |
| 162 | data[2] = imsi[2]; |
| 163 | |
| 164 | bitvec_pack(block, data + 3+1); |
| 165 | data[3] = (plen << 2) | 0x01; |
| 166 | pcu_tx_data_req(0, 0, PCU_IF_SAPI_PCH, 0, 0, 0, data, 23+3); |
Ivan Kluchnikov | c7e7f68 | 2012-06-29 22:53:15 +0400 | [diff] [blame] | 167 | } |
| 168 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 169 | static void pcu_l1if_tx_bcch(uint8_t *data, int len) |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 170 | { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 171 | pcu_tx_data_req(0, 0, PCU_IF_SAPI_BCCH, 0, 0, 0, data, len); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 172 | } |
| 173 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 174 | static int pcu_rx_data_ind(struct gsm_pcu_if_data *data_ind) |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 175 | { |
| 176 | int rc = 0; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 177 | |
| 178 | LOGP(DL1IF, LOGL_DEBUG, "Data indication received: sapi=%d arfcn=%d " |
| 179 | "block=%d data=%s\n", data_ind->sapi, |
| 180 | data_ind->arfcn, data_ind->block_nr, |
| 181 | osmo_hexdump(data_ind->data, data_ind->len)); |
| 182 | |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 183 | switch (data_ind->sapi) { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 184 | case PCU_IF_SAPI_PDTCH: |
Andreas Eversberg | b0c7ea7 | 2012-07-13 14:46:03 +0200 | [diff] [blame] | 185 | rc = gprs_rlcmac_rcv_block(data_ind->trx_nr, data_ind->ts_nr, |
| 186 | data_ind->data, data_ind->len, data_ind->fn); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 187 | break; |
| 188 | default: |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 189 | LOGP(DL1IF, LOGL_ERROR, "Received PCU data indication with " |
| 190 | "unsupported sapi %d\n", data_ind->sapi); |
| 191 | rc = -EINVAL; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 192 | } |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 193 | |
| 194 | return rc; |
| 195 | } |
| 196 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 197 | static int pcu_rx_rts_req(struct gsm_pcu_if_rts_req *rts_req) |
Ivan Kluchnikov | 5310d45 | 2012-04-17 22:00:31 +0400 | [diff] [blame] | 198 | { |
| 199 | int rc = 0; |
Ivan Kluchnikov | 5310d45 | 2012-04-17 22:00:31 +0400 | [diff] [blame] | 200 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 201 | LOGP(DL1IF, LOGL_DEBUG, "RTS request received: trx=%d ts=%d sapi=%d " |
| 202 | "arfcn=%d fn=%d block=%d\n", rts_req->trx_nr, rts_req->ts_nr, |
| 203 | rts_req->sapi, rts_req->arfcn, rts_req->fn, rts_req->block_nr); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 204 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 205 | switch (rts_req->sapi) { |
| 206 | case PCU_IF_SAPI_PDTCH: |
| 207 | gprs_rlcmac_rcv_rts_block(rts_req->trx_nr, rts_req->ts_nr, |
| 208 | rts_req->arfcn, rts_req->fn, rts_req->block_nr); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 209 | break; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 210 | case PCU_IF_SAPI_PTCCH: |
| 211 | /* FIXME */ |
| 212 | { |
| 213 | struct msgb *msg = msgb_alloc(23, "l1_prim"); |
| 214 | memset(msgb_put(msg, 23), 0x2b, 23); |
| 215 | pcu_l1if_tx_ptcch(msg, rts_req->trx_nr, rts_req->ts_nr, |
| 216 | rts_req->arfcn, rts_req->fn, rts_req->block_nr); |
| 217 | } |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 218 | break; |
| 219 | default: |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 220 | LOGP(DL1IF, LOGL_ERROR, "Received PCU RTS request with " |
| 221 | "unsupported sapi %d\n", rts_req->sapi); |
| 222 | rc = -EINVAL; |
| 223 | } |
| 224 | |
| 225 | return rc; |
| 226 | } |
| 227 | |
| 228 | static int pcu_rx_rach_ind(struct gsm_pcu_if_rach_ind *rach_ind) |
| 229 | { |
| 230 | int rc = 0; |
| 231 | |
| 232 | LOGP(DL1IF, LOGL_INFO, "RACH request received: sapi=%d " |
| 233 | "qta=%d, ra=%d, fn=%d\n", rach_ind->sapi, rach_ind->qta, |
| 234 | rach_ind->ra, rach_ind->fn); |
| 235 | |
| 236 | switch (rach_ind->sapi) { |
| 237 | case PCU_IF_SAPI_RACH: |
| 238 | rc = gprs_rlcmac_rcv_rach(rach_ind->ra, rach_ind->fn, |
| 239 | rach_ind->qta); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 240 | break; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 241 | default: |
| 242 | LOGP(DL1IF, LOGL_ERROR, "Received PCU rach request with " |
| 243 | "unsupported sapi %d\n", rach_ind->sapi); |
| 244 | rc = -EINVAL; |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 245 | } |
| 246 | |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 247 | return rc; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 248 | } |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 249 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 250 | static int pcu_rx_info_ind(struct gsm_pcu_if_info_ind *info_ind) |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 251 | { |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 252 | struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 253 | int rc = 0; |
| 254 | int trx, ts, tfi; |
| 255 | struct gprs_rlcmac_tbf *tbf; |
| 256 | int i; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 257 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 258 | LOGP(DL1IF, LOGL_DEBUG, "Info indication received:\n"); |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 259 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 260 | if (!(info_ind->flags & PCU_IF_FLAG_ACTIVE)) { |
| 261 | LOGP(DL1IF, LOGL_NOTICE, "BTS not available\n"); |
| 262 | bssgp_failed: |
| 263 | /* free all TBF */ |
| 264 | for (trx = 0; trx < 8; trx++) { |
| 265 | bts->trx[trx].arfcn = info_ind->trx[trx].arfcn; |
| 266 | for (ts = 0; ts < 8; ts++) { |
| 267 | for (tfi = 0; tfi < 32; tfi++) { |
Andreas Eversberg | b0c7ea7 | 2012-07-13 14:46:03 +0200 | [diff] [blame] | 268 | tbf = bts->trx[trx].pdch[ts].ul_tbf[tfi]; |
| 269 | if (tbf) |
| 270 | tbf_free(tbf); |
| 271 | tbf = bts->trx[trx].pdch[ts].dl_tbf[tfi]; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 272 | if (tbf) |
| 273 | tbf_free(tbf); |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | gprs_bssgp_destroy(); |
| 278 | return 0; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 279 | } |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 280 | LOGP(DL1IF, LOGL_INFO, "BTS available\n"); |
| 281 | LOGP(DL1IF, LOGL_DEBUG, " mcc=%d\n", info_ind->mcc); |
| 282 | LOGP(DL1IF, LOGL_DEBUG, " mnc=%d\n", info_ind->mnc); |
| 283 | LOGP(DL1IF, LOGL_DEBUG, " lac=%d\n", info_ind->lac); |
| 284 | LOGP(DL1IF, LOGL_DEBUG, " rac=%d\n", info_ind->rac); |
| 285 | LOGP(DL1IF, LOGL_DEBUG, " cell_id=%d\n", info_ind->cell_id); |
| 286 | LOGP(DL1IF, LOGL_DEBUG, " nsei=%d\n", info_ind->nsei); |
| 287 | LOGP(DL1IF, LOGL_DEBUG, " nse_timer=%d %d %d %d %d %d %d\n", |
| 288 | info_ind->nse_timer[0], info_ind->nse_timer[1], |
| 289 | info_ind->nse_timer[2], info_ind->nse_timer[3], |
| 290 | info_ind->nse_timer[4], info_ind->nse_timer[5], |
| 291 | info_ind->nse_timer[6]); |
| 292 | LOGP(DL1IF, LOGL_DEBUG, " cell_timer=%d %d %d %d %d %d %d %d %d %d " |
| 293 | "%d\n", |
| 294 | info_ind->cell_timer[0], info_ind->cell_timer[1], |
| 295 | info_ind->cell_timer[2], info_ind->cell_timer[3], |
| 296 | info_ind->cell_timer[4], info_ind->cell_timer[5], |
| 297 | info_ind->cell_timer[6], info_ind->cell_timer[7], |
| 298 | info_ind->cell_timer[8], info_ind->cell_timer[9], |
| 299 | info_ind->cell_timer[10]); |
| 300 | LOGP(DL1IF, LOGL_DEBUG, " repeat_time=%d\n", info_ind->repeat_time); |
| 301 | LOGP(DL1IF, LOGL_DEBUG, " repeat_count=%d\n", info_ind->repeat_count); |
| 302 | LOGP(DL1IF, LOGL_DEBUG, " bvci=%d\n", info_ind->bvci); |
| 303 | LOGP(DL1IF, LOGL_DEBUG, " t3142=%d\n", info_ind->t3142); |
| 304 | LOGP(DL1IF, LOGL_DEBUG, " t3169=%d\n", info_ind->t3169); |
| 305 | LOGP(DL1IF, LOGL_DEBUG, " t3191=%d\n", info_ind->t3191); |
| 306 | LOGP(DL1IF, LOGL_DEBUG, " t3193=%d (ms)\n", info_ind->t3193_10ms * 10); |
| 307 | LOGP(DL1IF, LOGL_DEBUG, " t3195=%d\n", info_ind->t3195); |
| 308 | LOGP(DL1IF, LOGL_DEBUG, " n3101=%d\n", info_ind->n3101); |
| 309 | LOGP(DL1IF, LOGL_DEBUG, " n3103=%d\n", info_ind->n3103); |
| 310 | LOGP(DL1IF, LOGL_DEBUG, " n3105=%d\n", info_ind->n3105); |
| 311 | LOGP(DL1IF, LOGL_DEBUG, " cv_countdown=%d\n", info_ind->cv_countdown); |
| 312 | LOGP(DL1IF, LOGL_DEBUG, " dl_tbf_ext=%d\n", info_ind->dl_tbf_ext); |
| 313 | LOGP(DL1IF, LOGL_DEBUG, " ul_tbf_ext=%d\n", info_ind->ul_tbf_ext); |
| 314 | for (i = 0; i < 4; i++) { |
| 315 | if ((info_ind->flags & (PCU_IF_FLAG_CS1 << i))) |
| 316 | LOGP(DL1IF, LOGL_DEBUG, " Use CS%d\n", i+1); |
| 317 | } |
| 318 | for (i = 0; i < 9; i++) { |
| 319 | if ((info_ind->flags & (PCU_IF_FLAG_MCS1 << i))) |
| 320 | LOGP(DL1IF, LOGL_DEBUG, " Use MCS%d\n", i+1); |
| 321 | } |
| 322 | LOGP(DL1IF, LOGL_DEBUG, " initial_cs=%d\n", info_ind->initial_cs); |
| 323 | LOGP(DL1IF, LOGL_DEBUG, " initial_mcs=%d\n", info_ind->initial_mcs); |
| 324 | LOGP(DL1IF, LOGL_DEBUG, " nsvci=%d\n", info_ind->nsvci[0]); |
| 325 | LOGP(DL1IF, LOGL_DEBUG, " local_port=%d\n", info_ind->local_port[0]); |
| 326 | LOGP(DL1IF, LOGL_DEBUG, " remote_port=%d\n", info_ind->remote_port[0]); |
| 327 | LOGP(DL1IF, LOGL_DEBUG, " remote_ip=%d\n", info_ind->remote_ip[0]); |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 328 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 329 | rc = gprs_bssgp_create(info_ind->remote_ip[0], info_ind->remote_port[0], |
| 330 | info_ind->nsei, info_ind->nsvci[0], info_ind->bvci, |
| 331 | info_ind->mcc, info_ind->mnc, info_ind->lac, info_ind->rac, |
| 332 | info_ind->cell_id); |
| 333 | if (rc < 0) { |
| 334 | LOGP(DL1IF, LOGL_NOTICE, "SGSN not available\n"); |
| 335 | goto bssgp_failed; |
| 336 | } |
| 337 | |
| 338 | bts->cs1 = !!(info_ind->flags & PCU_IF_FLAG_CS1); |
| 339 | bts->cs2 = !!(info_ind->flags & PCU_IF_FLAG_CS2); |
| 340 | bts->cs3 = !!(info_ind->flags & PCU_IF_FLAG_CS3); |
| 341 | bts->cs4 = !!(info_ind->flags & PCU_IF_FLAG_CS4); |
| 342 | if (!bts->cs1 && !bts->cs2 && !bts->cs3 && !bts->cs4) |
| 343 | bts->cs1 = 1; |
| 344 | if (info_ind->t3142) { /* if timer values are set */ |
| 345 | bts->t3142 = info_ind->t3142; |
| 346 | bts->t3169 = info_ind->t3169; |
| 347 | bts->t3191 = info_ind->t3191; |
| 348 | bts->t3193_msec = info_ind->t3193_10ms * 10; |
| 349 | bts->t3195 = info_ind->t3195; |
| 350 | bts->n3101 = info_ind->n3101; |
| 351 | bts->n3103 = info_ind->n3103; |
| 352 | bts->n3105 = info_ind->n3105; |
| 353 | } |
| 354 | if (info_ind->initial_cs < 1 || info_ind->initial_cs > 4) |
| 355 | bts->initial_cs = 1; |
| 356 | else |
| 357 | bts->initial_cs = info_ind->initial_cs; |
| 358 | |
| 359 | for (trx = 0; trx < 8; trx++) { |
| 360 | bts->trx[trx].arfcn = info_ind->trx[trx].arfcn; |
| 361 | for (ts = 0; ts < 8; ts++) { |
| 362 | if ((info_ind->trx[trx].pdch_mask & (1 << ts))) { |
| 363 | /* FIXME: activate dynamically at RLCMAC */ |
| 364 | if (!bts->trx[trx].pdch[ts].enable) |
| 365 | pcu_tx_act_req(trx, ts, 1); |
| 366 | bts->trx[trx].pdch[ts].enable = 1; |
| 367 | bts->trx[trx].pdch[ts].tsc = |
| 368 | info_ind->trx[trx].tsc[ts]; |
| 369 | LOGP(DL1IF, LOGL_INFO, "PDCH: trx=%d ts=%d\n", |
| 370 | trx, ts); |
| 371 | } else { |
| 372 | if (bts->trx[trx].pdch[ts].enable) |
| 373 | pcu_tx_act_req(trx, ts, 0); |
| 374 | bts->trx[trx].pdch[ts].enable = 0; |
Andreas Eversberg | b0c7ea7 | 2012-07-13 14:46:03 +0200 | [diff] [blame] | 375 | /* kick all TBF on slot */ |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 376 | for (tfi = 0; tfi < 32; tfi++) { |
Andreas Eversberg | b0c7ea7 | 2012-07-13 14:46:03 +0200 | [diff] [blame] | 377 | tbf = bts->trx[trx].pdch[ts].ul_tbf[tfi]; |
| 378 | if (tbf) |
| 379 | tbf_free(tbf); |
| 380 | tbf = bts->trx[trx].pdch[ts].dl_tbf[tfi]; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 381 | if (tbf) |
| 382 | tbf_free(tbf); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 388 | return rc; |
| 389 | } |
| 390 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 391 | static int pcu_rx_time_ind(struct gsm_pcu_if_time_ind *time_ind) |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 392 | { |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 393 | struct gprs_rlcmac_tbf *tbf; |
| 394 | uint32_t elapsed; |
| 395 | uint8_t fn13 = time_ind->fn % 13; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 396 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 397 | /* omit frame numbers not starting at a MAC block */ |
| 398 | if (fn13 != 0 && fn13 != 4 && fn13 != 8) |
| 399 | return 0; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 400 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 401 | LOGP(DL1IF, LOGL_DEBUG, "Time indication received: %d\n", |
| 402 | time_ind->fn % 52); |
| 403 | |
| 404 | set_current_fn(time_ind->fn); |
| 405 | |
| 406 | /* check for poll timeout */ |
Andreas Eversberg | b0c7ea7 | 2012-07-13 14:46:03 +0200 | [diff] [blame] | 407 | llist_for_each_entry(tbf, &gprs_rlcmac_ul_tbfs, list) { |
| 408 | if (tbf->poll_state == GPRS_RLCMAC_POLL_SCHED) { |
| 409 | elapsed = (frame_number - tbf->poll_fn) % 2715648; |
| 410 | if (elapsed >= 20 && elapsed < 200) |
| 411 | gprs_rlcmac_poll_timeout(tbf); |
| 412 | } |
| 413 | } |
| 414 | llist_for_each_entry(tbf, &gprs_rlcmac_dl_tbfs, list) { |
| 415 | if (tbf->poll_state == GPRS_RLCMAC_POLL_SCHED) { |
| 416 | elapsed = (frame_number - tbf->poll_fn) % 2715648; |
| 417 | if (elapsed >= 20 && elapsed < 200) |
| 418 | gprs_rlcmac_poll_timeout(tbf); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 419 | } |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 425 | int pcu_rx(uint8_t msg_type, struct gsm_pcu_if *pcu_prim) |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 426 | { |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 427 | int rc = 0; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 428 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 429 | switch (msg_type) { |
| 430 | case PCU_IF_MSG_DATA_IND: |
| 431 | rc = pcu_rx_data_ind(&pcu_prim->u.data_ind); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 432 | break; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 433 | case PCU_IF_MSG_RTS_REQ: |
| 434 | rc = pcu_rx_rts_req(&pcu_prim->u.rts_req); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 435 | break; |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 436 | case PCU_IF_MSG_RACH_IND: |
| 437 | rc = pcu_rx_rach_ind(&pcu_prim->u.rach_ind); |
| 438 | break; |
| 439 | case PCU_IF_MSG_INFO_IND: |
| 440 | rc = pcu_rx_info_ind(&pcu_prim->u.info_ind); |
| 441 | break; |
| 442 | case PCU_IF_MSG_TIME_IND: |
| 443 | rc = pcu_rx_time_ind(&pcu_prim->u.time_ind); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 444 | break; |
| 445 | default: |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 446 | LOGP(DL1IF, LOGL_ERROR, "Received unknwon PCU msg type %d\n", |
| 447 | msg_type); |
| 448 | rc = -EINVAL; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 449 | } |
| 450 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 451 | return rc; |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 452 | } |