blob: 4fb75f771170026c0d0d2b60ef08ab37de3c414a [file] [log] [blame]
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001/* gprs_rlcmac.cpp
2 *
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
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (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 General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
Pau Espin Pedrol585cfb22019-12-10 17:09:51 +010021
Pau Espin Pedrol5530f122019-12-10 19:26:27 +010022extern "C" {
23 #include <osmocom/gsm/gsm48.h>
24}
25
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040026#include <pcu_l1_if.h>
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040027#include <gprs_rlcmac.h>
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020028#include <bts.h>
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020029#include <encoding.h>
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +020030#include <tbf.h>
Max1187a772018-01-26 13:31:42 +010031#include <gprs_debug.h>
Andreas Eversberg53f47252012-07-15 07:10:10 +020032
Andreas Eversberg6681bb82012-07-25 08:48:44 +020033extern void *tall_pcu_ctx;
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040034
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +020035int gprs_rlcmac_paging_request(const struct osmo_mobile_identity *mi, uint16_t pgroup)
Andreas Eversberg8c3680d2012-10-08 12:30:56 +020036{
Neels Hofmeyr00520512020-08-21 15:44:58 +020037 if (log_check_level(DRLCMAC, LOGL_NOTICE)) {
Neels Hofmeyr00520512020-08-21 15:44:58 +020038 char str[64];
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +020039 osmo_mobile_identity_to_str_buf(str, sizeof(str), mi);
Neels Hofmeyr00520512020-08-21 15:44:58 +020040 LOGP(DRLCMAC, LOGL_NOTICE, "TX: [PCU -> BTS] Paging Request (CCCH) MI=%s\n", str);
41 }
Pau Espin Pedrol05bca352019-10-16 14:36:26 +020042 bitvec *paging_request = bitvec_alloc(22, tall_pcu_ctx);
Max7426c5f2019-02-18 20:42:42 +010043 bitvec_unhex(paging_request, DUMMY_VEC);
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +020044 int plen = Encoding::write_paging_request(paging_request, mi);
45 if (plen <= 0) {
46 LOGP(DRLCMAC, LOGL_ERROR, "TX: [PCU -> BTS] Failed to encode Paging Request\n");
47 return -1;
48 }
Pau Espin Pedrold7c32652019-12-23 12:41:34 +010049 pcu_l1if_tx_pch(paging_request, plen, pgroup);
Andreas Eversberg8c3680d2012-10-08 12:30:56 +020050 bitvec_free(paging_request);
51
52 return 0;
53}
Andreas Eversberga004e6a2013-05-13 16:45:21 +020054
Oliver Smithcfb63212019-09-05 17:13:33 +020055/* Encode Application Information Request to Packet Application Information (3GPP TS 44.060 11.2.47) */
56struct msgb *gprs_rlcmac_app_info_msg(const struct gsm_pcu_if_app_info_req *req) {
57 struct msgb *msg;
58 uint16_t msgb_len = req->len + 1;
59 struct bitvec bv = {0, msgb_len, NULL};
60 const enum bit_value page_mode[] = {ZERO, ZERO}; /* Normal Paging (3GPP TS 44.060 12.20) */
Andreas Eversberga004e6a2013-05-13 16:45:21 +020061
Oliver Smithcfb63212019-09-05 17:13:33 +020062 if (!req->len) {
63 LOGP(DRLCMAC, LOGL_ERROR, "Application Information Request with zero length received!\n");
64 return NULL;
65 }
66
67 msg = msgb_alloc(msgb_len, "app_info_msg");
68 if (!msg)
69 return NULL;
70
71 bv.data = msgb_put(msg, msgb_len);
72 bitvec_set_bits(&bv, page_mode, 2);
73 bitvec_set_uint(&bv, req->application_type, 4);
74 bitvec_set_bytes(&bv, req->data, req->len);
75 return msg;
76}