blob: 88fcc596516b6b0865487c1ba2ed4ba7bc0c5d09 [file] [log] [blame]
Maxcb947e02023-04-12 08:27:54 +03001/* gprs_rlcmac.c
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04002 *
3 * Copyright (C) 2012 Ivan Klyuchnikov
Andreas Eversberg5dac2f02012-06-27 15:52:04 +02004 * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
Holger Hans Peter Freytherd6bd91e2013-08-24 21:16:55 +02005 * Copyright (C) 2013 by Holger Hans Peter Freyther
Maxcb947e02023-04-12 08:27:54 +03006 * Copyright (C) 2023 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04007 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040017 */
Pau Espin Pedrol585cfb22019-12-10 17:09:51 +010018
Maxcb947e02023-04-12 08:27:54 +030019#include <osmocom/gsm/gsm48.h>
Pau Espin Pedrol5530f122019-12-10 19:26:27 +010020
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040021#include <pcu_l1_if.h>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040022#include <gprs_rlcmac.h>
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020023#include <bts.h>
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020024#include <encoding.h>
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +020025#include <tbf.h>
Max1187a772018-01-26 13:31:42 +010026#include <gprs_debug.h>
Andreas Eversberg53f47252012-07-15 07:10:10 +020027
Andreas Eversberg6681bb82012-07-25 08:48:44 +020028extern void *tall_pcu_ctx;
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040029
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +010030int gprs_rlcmac_paging_request(struct gprs_rlcmac_bts *bts, const struct osmo_mobile_identity *mi,
Philipp Maier41e38472023-03-03 16:04:26 +010031 const char *imsi)
Andreas Eversberg8c3680d2012-10-08 12:30:56 +020032{
Neels Hofmeyr00520512020-08-21 15:44:58 +020033 if (log_check_level(DRLCMAC, LOGL_NOTICE)) {
Neels Hofmeyr00520512020-08-21 15:44:58 +020034 char str[64];
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +020035 osmo_mobile_identity_to_str_buf(str, sizeof(str), mi);
Neels Hofmeyr00520512020-08-21 15:44:58 +020036 LOGP(DRLCMAC, LOGL_NOTICE, "TX: [PCU -> BTS] Paging Request (CCCH) MI=%s\n", str);
37 }
Maxcb947e02023-04-12 08:27:54 +030038 struct bitvec *paging_request = bitvec_alloc(22, tall_pcu_ctx);
Max7426c5f2019-02-18 20:42:42 +010039 bitvec_unhex(paging_request, DUMMY_VEC);
Maxcb947e02023-04-12 08:27:54 +030040 int plen = write_paging_request(paging_request, mi);
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +020041 if (plen <= 0) {
42 LOGP(DRLCMAC, LOGL_ERROR, "TX: [PCU -> BTS] Failed to encode Paging Request\n");
43 return -1;
44 }
Oliver Smith4df959d2021-06-24 17:01:41 +020045 bts_do_rate_ctr_inc(bts, CTR_PCH_REQUESTS);
Philipp Maier98e59102023-05-11 13:38:18 +020046
47 if (the_pcu->pcu_if_version >= 0x0b)
48 pcu_l1if_tx_pch_dt(bts, paging_request, plen, imsi, GSM_RESERVED_TMSI);
49 else
50 pcu_l1if_tx_pch(bts, paging_request, plen, imsi);
51
Andreas Eversberg8c3680d2012-10-08 12:30:56 +020052 bitvec_free(paging_request);
53
54 return 0;
55}
Andreas Eversberga004e6a2013-05-13 16:45:21 +020056
Oliver Smithcfb63212019-09-05 17:13:33 +020057/* Encode Application Information Request to Packet Application Information (3GPP TS 44.060 11.2.47) */
58struct msgb *gprs_rlcmac_app_info_msg(const struct gsm_pcu_if_app_info_req *req) {
59 struct msgb *msg;
60 uint16_t msgb_len = req->len + 1;
61 struct bitvec bv = {0, msgb_len, NULL};
62 const enum bit_value page_mode[] = {ZERO, ZERO}; /* Normal Paging (3GPP TS 44.060 12.20) */
Andreas Eversberga004e6a2013-05-13 16:45:21 +020063
Oliver Smithcfb63212019-09-05 17:13:33 +020064 if (!req->len) {
65 LOGP(DRLCMAC, LOGL_ERROR, "Application Information Request with zero length received!\n");
66 return NULL;
67 }
68
69 msg = msgb_alloc(msgb_len, "app_info_msg");
70 if (!msg)
71 return NULL;
72
73 bv.data = msgb_put(msg, msgb_len);
74 bitvec_set_bits(&bv, page_mode, 2);
75 bitvec_set_uint(&bv, req->application_type, 4);
76 bitvec_set_bytes(&bv, req->data, req->len);
77 return msg;
78}