Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 1 | /* Copyright (C) 2015 by Yves Godin <support@nuranwireless.com> |
| 2 | * based on: |
| 3 | * femto_l1_if.c |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | #include "oc2g_l1_if.h" |
| 22 | |
| 23 | #include <string.h> |
| 24 | #include <errno.h> |
| 25 | |
| 26 | #include <nrw/oc2g/oc2g.h> |
| 27 | #include <nrw/oc2g/gsml1prim.h> |
| 28 | #include <nrw/oc2g/gsml1const.h> |
| 29 | #include <nrw/oc2g/gsml1types.h> |
| 30 | |
| 31 | #include <osmocom/core/gsmtap.h> |
| 32 | #include <osmocom/core/talloc.h> |
| 33 | #include <osmocom/core/timer.h> |
Minh-Quang Nguyen | 4a1796f | 2017-09-29 08:54:16 -0400 | [diff] [blame] | 34 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
| 35 | |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 36 | #include <gprs_debug.h> |
| 37 | #include <pcu_l1_if.h> |
Philipp Maier | 84ece23 | 2023-02-15 15:15:31 +0100 | [diff] [blame] | 38 | #include <pcu_l1_if_phy.h> |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 39 | #include <osmocom/pcu/pcuif_proto.h> |
| 40 | #include <bts.h> |
| 41 | |
| 42 | extern void *tall_pcu_ctx; |
| 43 | |
| 44 | uint32_t l1if_ts_to_hLayer2(uint8_t trx, uint8_t ts) |
| 45 | { |
| 46 | return (ts << 16) | (trx << 24); |
| 47 | } |
| 48 | |
| 49 | /* allocate a msgb containing a GsmL1_Prim_t */ |
| 50 | struct msgb *l1p_msgb_alloc(void) |
| 51 | { |
| 52 | struct msgb *msg = msgb_alloc(sizeof(GsmL1_Prim_t), "l1_prim"); |
| 53 | |
| 54 | if (msg) |
| 55 | msg->l1h = msgb_put(msg, sizeof(GsmL1_Prim_t)); |
| 56 | |
| 57 | return msg; |
| 58 | } |
| 59 | |
| 60 | static int l1if_req_pdch(struct oc2gl1_hdl *fl1h, struct msgb *msg) |
| 61 | { |
| 62 | struct osmo_wqueue *wqueue = &fl1h->write_q[MQ_PDTCH_WRITE]; |
| 63 | |
| 64 | if (osmo_wqueue_enqueue(wqueue, msg) != 0) { |
| 65 | LOGP(DL1IF, LOGL_ERROR, "PDTCH queue full. dropping message.\n"); |
| 66 | msgb_free(msg); |
| 67 | } |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static void *prim_init(GsmL1_Prim_t *prim, GsmL1_PrimId_t id, struct oc2gl1_hdl *gl1) |
| 73 | { |
| 74 | prim->id = id; |
| 75 | |
| 76 | switch (id) { |
| 77 | case GsmL1_PrimId_MphInitReq: |
| 78 | //prim->u.mphInitReq.hLayer1 = (HANDLE)gl1->hLayer1; |
| 79 | break; |
| 80 | case GsmL1_PrimId_MphCloseReq: |
| 81 | prim->u.mphCloseReq.hLayer1 = (HANDLE)gl1->hLayer1; |
| 82 | break; |
| 83 | case GsmL1_PrimId_MphConnectReq: |
| 84 | prim->u.mphConnectReq.hLayer1 = (HANDLE)gl1->hLayer1; |
| 85 | break; |
| 86 | case GsmL1_PrimId_MphDisconnectReq: |
| 87 | prim->u.mphDisconnectReq.hLayer1 = (HANDLE)gl1->hLayer1; |
| 88 | break; |
| 89 | case GsmL1_PrimId_MphActivateReq: |
| 90 | prim->u.mphActivateReq.hLayer1 = (HANDLE)gl1->hLayer1; |
| 91 | break; |
| 92 | case GsmL1_PrimId_MphDeactivateReq: |
| 93 | prim->u.mphDeactivateReq.hLayer1 = (HANDLE)gl1->hLayer1; |
| 94 | break; |
| 95 | case GsmL1_PrimId_MphConfigReq: |
| 96 | prim->u.mphConfigReq.hLayer1 = (HANDLE)gl1->hLayer1; |
| 97 | break; |
| 98 | case GsmL1_PrimId_MphMeasureReq: |
| 99 | prim->u.mphMeasureReq.hLayer1 = (HANDLE)gl1->hLayer1; |
| 100 | break; |
| 101 | case GsmL1_PrimId_MphInitCnf: |
| 102 | case GsmL1_PrimId_MphCloseCnf: |
| 103 | case GsmL1_PrimId_MphConnectCnf: |
| 104 | case GsmL1_PrimId_MphDisconnectCnf: |
| 105 | case GsmL1_PrimId_MphActivateCnf: |
| 106 | case GsmL1_PrimId_MphDeactivateCnf: |
| 107 | case GsmL1_PrimId_MphConfigCnf: |
| 108 | case GsmL1_PrimId_MphMeasureCnf: |
| 109 | break; |
| 110 | case GsmL1_PrimId_MphTimeInd: |
| 111 | break; |
| 112 | case GsmL1_PrimId_MphSyncInd: |
| 113 | break; |
| 114 | case GsmL1_PrimId_PhEmptyFrameReq: |
| 115 | prim->u.phEmptyFrameReq.hLayer1 = (HANDLE)gl1->hLayer1; |
| 116 | break; |
| 117 | case GsmL1_PrimId_PhDataReq: |
| 118 | prim->u.phDataReq.hLayer1 = (HANDLE)gl1->hLayer1; |
| 119 | break; |
| 120 | case GsmL1_PrimId_PhConnectInd: |
| 121 | break; |
| 122 | case GsmL1_PrimId_PhReadyToSendInd: |
| 123 | break; |
| 124 | case GsmL1_PrimId_PhDataInd: |
| 125 | break; |
| 126 | case GsmL1_PrimId_PhRaInd: |
| 127 | break; |
| 128 | default: |
| 129 | LOGP(DL1IF, LOGL_ERROR, "unknown L1 primitive %u\n", id); |
| 130 | break; |
| 131 | } |
| 132 | return &prim->u; |
| 133 | } |
| 134 | |
| 135 | /* connect PDTCH */ |
| 136 | int l1if_connect_pdch(void *obj, uint8_t ts) |
| 137 | { |
| 138 | struct oc2gl1_hdl *fl1h = obj; |
| 139 | struct msgb *msg = l1p_msgb_alloc(); |
| 140 | GsmL1_MphConnectReq_t *cr; |
| 141 | |
| 142 | cr = prim_init(msgb_l1prim(msg), GsmL1_PrimId_MphConnectReq, fl1h); |
| 143 | cr->u8Tn = ts; |
| 144 | cr->logChComb = GsmL1_LogChComb_XIII; |
| 145 | |
| 146 | return l1if_req_pdch(fl1h, msg); |
| 147 | } |
| 148 | |
Philipp Maier | 72ed333 | 2023-02-27 15:32:00 +0100 | [diff] [blame] | 149 | int l1if_disconnect_pdch(void *obj, uint8_t ts) |
| 150 | { |
| 151 | return 0; |
| 152 | } |
| 153 | |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 154 | static int handle_ph_readytosend_ind(struct oc2gl1_hdl *fl1h, |
| 155 | GsmL1_PhReadyToSendInd_t *rts_ind) |
| 156 | { |
| 157 | struct gsm_time g_time; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 158 | struct gprs_rlcmac_bts *bts; |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 159 | int rc = 0; |
| 160 | |
| 161 | gsm_fn2gsmtime(&g_time, rts_ind->u32Fn); |
| 162 | |
| 163 | DEBUGP(DL1IF, "Rx PH-RTS.ind %02u/%02u/%02u SAPI=%s\n", |
| 164 | g_time.t1, g_time.t2, g_time.t3, |
| 165 | get_value_string(oc2gbts_l1sapi_names, rts_ind->sapi)); |
| 166 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 167 | bts = llist_first_entry_or_null(&the_pcu->bts_list, struct gprs_rlcmac_bts, list); |
| 168 | |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 169 | switch (rts_ind->sapi) { |
| 170 | case GsmL1_Sapi_Pdtch: |
| 171 | case GsmL1_Sapi_Pacch: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 172 | rc = pcu_rx_rts_req_pdtch(bts, fl1h->trx_no, rts_ind->u8Tn, |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 173 | rts_ind->u32Fn, rts_ind->u8BlockNbr); |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 174 | break; |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 175 | case GsmL1_Sapi_Ptcch: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 176 | rc = pcu_rx_rts_req_ptcch(bts, fl1h->trx_no, rts_ind->u8Tn, |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 177 | rts_ind->u32Fn, rts_ind->u8BlockNbr); |
| 178 | break; |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 179 | default: |
| 180 | break; |
| 181 | } |
| 182 | |
| 183 | return rc; |
| 184 | } |
| 185 | |
| 186 | static void get_meas(struct pcu_l1_meas *meas, const GsmL1_MeasParam_t *l1_meas) |
| 187 | { |
| 188 | meas->rssi = (int8_t) (l1_meas->fRssi); |
| 189 | meas->have_rssi = 1; |
| 190 | meas->ber = (uint8_t) (l1_meas->fBer * 100); |
| 191 | meas->have_ber = 1; |
| 192 | meas->bto = (int16_t) (l1_meas->i16BurstTiming); |
| 193 | meas->have_bto = 1; |
| 194 | meas->link_qual = (int16_t) (l1_meas->fLinkQuality); |
| 195 | meas->have_link_qual = 1; |
| 196 | } |
| 197 | |
| 198 | static int handle_ph_data_ind(struct oc2gl1_hdl *fl1h, |
| 199 | GsmL1_PhDataInd_t *data_ind, struct msgb *l1p_msg) |
| 200 | { |
| 201 | int rc = 0; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 202 | struct gprs_rlcmac_bts *bts; |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 203 | struct gprs_rlcmac_pdch *pdch; |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 204 | struct pcu_l1_meas meas = {0}; |
Pau Espin Pedrol | 81c549d | 2021-03-08 13:08:06 +0100 | [diff] [blame] | 205 | uint8_t *data; |
| 206 | uint8_t data_len; |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 207 | |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 208 | DEBUGP(DL1IF, "(trx=%" PRIu8 ",ts=%u) FN=%u Rx PH-DATA.ind %s (hL2 %08x): %s\n", |
| 209 | fl1h->trx_no, data_ind->u8Tn, data_ind->u32Fn, |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 210 | get_value_string(oc2gbts_l1sapi_names, data_ind->sapi), |
| 211 | data_ind->hLayer2, |
| 212 | osmo_hexdump(data_ind->msgUnitParam.u8Buffer, |
| 213 | data_ind->msgUnitParam.u8Size)); |
| 214 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 215 | bts = llist_first_entry_or_null(&the_pcu->bts_list, struct gprs_rlcmac_bts, list); |
| 216 | |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 217 | gsmtap_send(fl1h->gsmtap, data_ind->u16Arfcn | GSMTAP_ARFCN_F_UPLINK, |
| 218 | data_ind->u8Tn, GSMTAP_CHANNEL_PACCH, 0, |
| 219 | data_ind->u32Fn, 0, 0, data_ind->msgUnitParam.u8Buffer+1, |
| 220 | data_ind->msgUnitParam.u8Size-1); |
| 221 | |
| 222 | get_meas(&meas, &data_ind->measParam); |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 223 | bts_update_tbf_ta(bts, "PH-DATA", data_ind->u32Fn, fl1h->trx_no, |
Minh-Quang Nguyen | 2ba6084 | 2017-11-07 15:17:12 -0500 | [diff] [blame] | 224 | data_ind->u8Tn, sign_qta2ta(meas.bto), false); |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 225 | |
| 226 | switch (data_ind->sapi) { |
| 227 | case GsmL1_Sapi_Pdtch: |
| 228 | case GsmL1_Sapi_Pacch: |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 229 | /* PDTCH / PACCH frame handling */ |
Pau Espin Pedrol | 81c549d | 2021-03-08 13:08:06 +0100 | [diff] [blame] | 230 | if (data_ind->msgUnitParam.u8Size != 0 && |
Pau Espin Pedrol | 755a8d6 | 2021-03-18 12:39:27 +0100 | [diff] [blame] | 231 | data_ind->msgUnitParam.u8Buffer[0] == GsmL1_PdtchPlType_Full) { |
Pau Espin Pedrol | 81c549d | 2021-03-08 13:08:06 +0100 | [diff] [blame] | 232 | data = data_ind->msgUnitParam.u8Buffer + 1; |
| 233 | data_len = data_ind->msgUnitParam.u8Size - 1; |
| 234 | if (data_len == 0) |
| 235 | data = NULL; |
| 236 | } else { |
| 237 | data = NULL; |
| 238 | data_len = 0; |
| 239 | } |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 240 | pdch = &bts->trx[fl1h->trx_no].pdch[data_ind->u8Tn]; |
| 241 | pcu_rx_data_ind_pdtch(bts, pdch, data, data_len, data_ind->u32Fn, &meas); |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 242 | break; |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 243 | default: |
Pau Espin Pedrol | c1f31c4 | 2021-03-09 14:50:14 +0100 | [diff] [blame] | 244 | LOGP(DL1IF, LOGL_NOTICE, |
| 245 | "(trx=%" PRIu8 ",ts=%u) FN=%u Rx PH-DATA.ind for unknown L1 SAPI %s\n", |
| 246 | fl1h->trx_no, data_ind->u8Tn, data_ind->u32Fn, |
| 247 | get_value_string(oc2gbts_l1sapi_names, data_ind->sapi)); |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 248 | break; |
| 249 | } |
| 250 | |
| 251 | return rc; |
| 252 | } |
| 253 | |
| 254 | #define MIN_QUAL_RACH 5.0f |
| 255 | |
| 256 | static int handle_ph_ra_ind(struct oc2gl1_hdl *fl1h, GsmL1_PhRaInd_t *ra_ind) |
| 257 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 258 | struct gprs_rlcmac_bts *bts; |
| 259 | |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 260 | if (ra_ind->measParam.fLinkQuality < MIN_QUAL_RACH) |
| 261 | return 0; |
| 262 | |
Minh-Quang Nguyen | ba66ea4 | 2017-11-15 13:08:30 -0500 | [diff] [blame] | 263 | LOGP(DL1IF, LOGL_DEBUG, "PH-RA-IND L1 qta=%d\n", ra_ind->measParam.i16BurstTiming); |
| 264 | |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 265 | bts = llist_first_entry_or_null(&the_pcu->bts_list, struct gprs_rlcmac_bts, list); |
| 266 | |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 267 | switch (ra_ind->sapi) { |
| 268 | case GsmL1_Sapi_Pdtch: |
Vadim Yanitskiy | 811c90c | 2020-03-30 16:14:07 +0700 | [diff] [blame] | 269 | case GsmL1_Sapi_Prach: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 270 | bts_update_tbf_ta(bts, "PH-RA", ra_ind->u32Fn, fl1h->trx_no, ra_ind->u8Tn, |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 271 | qta2ta(ra_ind->measParam.i16BurstTiming), true); |
| 272 | break; |
| 273 | case GsmL1_Sapi_Ptcch: |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 274 | pcu_rx_rach_ind_ptcch(bts, fl1h->trx_no, ra_ind->u8Tn, ra_ind->u32Fn, |
Vadim Yanitskiy | ffebd24 | 2019-10-05 23:45:31 +0700 | [diff] [blame] | 275 | ra_ind->measParam.i16BurstTiming); |
| 276 | break; |
| 277 | default: |
| 278 | LOGP(DL1IF, LOGL_NOTICE, "Rx PH-RA.ind for unknown L1 SAPI %s\n", |
| 279 | get_value_string(oc2gbts_l1sapi_names, ra_ind->sapi)); |
| 280 | return -ENOTSUP; |
| 281 | } |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | /* handle any random indication from the L1 */ |
| 288 | int l1if_handle_l1prim(int wq, struct oc2gl1_hdl *fl1h, struct msgb *msg) |
| 289 | { |
| 290 | GsmL1_Prim_t *l1p = msgb_l1prim(msg); |
| 291 | int rc = 0; |
| 292 | |
| 293 | LOGP(DL1IF, LOGL_DEBUG, "Rx L1 prim %s on queue %d\n", |
| 294 | get_value_string(oc2gbts_l1prim_names, l1p->id), wq); |
| 295 | |
| 296 | switch (l1p->id) { |
| 297 | #if 0 |
| 298 | case GsmL1_PrimId_MphTimeInd: |
| 299 | rc = handle_mph_time_ind(fl1h, &l1p->u.mphTimeInd); |
| 300 | break; |
| 301 | case GsmL1_PrimId_MphSyncInd: |
| 302 | break; |
| 303 | case GsmL1_PrimId_PhConnectInd: |
| 304 | break; |
| 305 | #endif |
| 306 | case GsmL1_PrimId_PhReadyToSendInd: |
| 307 | rc = handle_ph_readytosend_ind(fl1h, &l1p->u.phReadyToSendInd); |
| 308 | break; |
| 309 | case GsmL1_PrimId_PhDataInd: |
| 310 | rc = handle_ph_data_ind(fl1h, &l1p->u.phDataInd, msg); |
| 311 | break; |
| 312 | case GsmL1_PrimId_PhRaInd: |
| 313 | rc = handle_ph_ra_ind(fl1h, &l1p->u.phRaInd); |
| 314 | break; |
| 315 | default: |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 316 | break; |
| 317 | } |
| 318 | |
| 319 | msgb_free(msg); |
| 320 | |
| 321 | return rc; |
| 322 | } |
| 323 | |
| 324 | int l1if_handle_sysprim(struct oc2gl1_hdl *fl1h, struct msgb *msg) |
| 325 | { |
| 326 | return -ENOTSUP; |
| 327 | } |
| 328 | |
| 329 | /* send packet data request to L1 */ |
| 330 | int l1if_pdch_req(void *obj, uint8_t ts, int is_ptcch, uint32_t fn, |
| 331 | uint16_t arfcn, uint8_t block_nr, uint8_t *data, uint8_t len) |
| 332 | { |
| 333 | struct oc2gl1_hdl *fl1h = obj; |
| 334 | struct msgb *msg; |
| 335 | GsmL1_Prim_t *l1p; |
| 336 | GsmL1_PhDataReq_t *data_req; |
| 337 | GsmL1_MsgUnitParam_t *msu_param; |
| 338 | struct gsm_time g_time; |
| 339 | |
| 340 | gsm_fn2gsmtime(&g_time, fn); |
| 341 | |
| 342 | DEBUGP(DL1IF, "TX packet data %02u/%02u/%02u is_ptcch=%d ts=%d " |
| 343 | "block_nr=%d, arfcn=%d, len=%d\n", g_time.t1, g_time.t2, |
| 344 | g_time.t3, is_ptcch, ts, block_nr, arfcn, len); |
| 345 | |
| 346 | msg = l1p_msgb_alloc(); |
| 347 | l1p = msgb_l1prim(msg); |
| 348 | l1p->id = GsmL1_PrimId_PhDataReq; |
| 349 | data_req = &l1p->u.phDataReq; |
| 350 | data_req->hLayer1 = (HANDLE)fl1h->hLayer1; |
| 351 | data_req->sapi = (is_ptcch) ? GsmL1_Sapi_Ptcch : GsmL1_Sapi_Pdtch; |
| 352 | data_req->subCh = GsmL1_SubCh_NA; |
| 353 | data_req->u8BlockNbr = block_nr; |
| 354 | data_req->u8Tn = ts; |
| 355 | data_req->u32Fn = fn; |
| 356 | msu_param = &data_req->msgUnitParam; |
| 357 | msu_param->u8Size = len; |
| 358 | memcpy(msu_param->u8Buffer, data, len); |
| 359 | |
| 360 | gsmtap_send(fl1h->gsmtap, arfcn, data_req->u8Tn, GSMTAP_CHANNEL_PACCH, |
| 361 | 0, data_req->u32Fn, 0, 0, |
| 362 | data_req->msgUnitParam.u8Buffer, |
| 363 | data_req->msgUnitParam.u8Size); |
| 364 | |
| 365 | |
| 366 | /* transmit */ |
| 367 | if (osmo_wqueue_enqueue(&fl1h->write_q[MQ_PDTCH_WRITE], msg) != 0) { |
| 368 | LOGP(DL1IF, LOGL_ERROR, "PDTCH queue full. dropping message.\n"); |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 369 | msgb_free(msg); |
| 370 | } |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
Philipp Maier | c82c948 | 2023-03-03 11:39:00 +0100 | [diff] [blame^] | 375 | void *l1if_open_pdch(uint8_t bts_nr, uint8_t trx_no, uint32_t hlayer1, struct gsmtap_inst *gsmtap) |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 376 | { |
| 377 | struct oc2gl1_hdl *fl1h; |
| 378 | int rc; |
| 379 | |
| 380 | fl1h = talloc_zero(tall_pcu_ctx, struct oc2gl1_hdl); |
| 381 | if (!fl1h) |
| 382 | return NULL; |
| 383 | |
| 384 | fl1h->hLayer1 = hlayer1; |
| 385 | fl1h->trx_no = trx_no; |
| 386 | /* hardware queues are numbered starting from 0 */ |
| 387 | fl1h->hw_info.trx_nr = trx_no; |
| 388 | |
| 389 | DEBUGP(DL1IF, "PCU: Using TRX HW#%u\n", fl1h->hw_info.trx_nr); |
| 390 | |
| 391 | rc = l1if_transport_open(MQ_PDTCH_WRITE, fl1h); |
| 392 | if (rc < 0) { |
Jean-Francois Dionne | c1e4490 | 2017-06-05 14:44:57 -0400 | [diff] [blame] | 393 | talloc_free(fl1h); |
| 394 | return NULL; |
| 395 | } |
| 396 | |
| 397 | fl1h->gsmtap = gsmtap_source_init("localhost", GSMTAP_UDP_PORT, 1); |
| 398 | if (fl1h->gsmtap) |
| 399 | gsmtap_source_add_sink(fl1h->gsmtap); |
| 400 | |
| 401 | return fl1h; |
| 402 | } |
| 403 | |
| 404 | int l1if_close_pdch(void *obj) |
| 405 | { |
| 406 | struct oc2gl1_hdl *fl1h = obj; |
| 407 | if (fl1h) |
| 408 | l1if_transport_close(MQ_PDTCH_WRITE, fl1h); |
| 409 | talloc_free(fl1h); |
| 410 | return 0; |
| 411 | } |
Philipp Maier | 916e9d3 | 2023-02-27 16:42:26 +0100 | [diff] [blame] | 412 | |
| 413 | int l1if_init(void) |
| 414 | { |
| 415 | return 0; |
| 416 | } |