blob: f29f1683d7d1639c5ca7bb14b64da39c7aa419d1 [file] [log] [blame]
Harald Weltedc5062b2010-03-26 21:28:59 +08001/* OpenBSC Debugging/Logging support code */
2
3/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
Holger Freytherd546e312008-12-27 12:03:07 +00004 * (C) 2008 by Holger Hans Peter Freyther <zecke@selfish.org>
Holger Freyther32636e82008-12-27 11:07:15 +00005 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01008 * 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
Holger Freyther32636e82008-12-27 11:07:15 +000010 * (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
Harald Welte9af6ddf2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Holger Freyther32636e82008-12-27 11:07:15 +000016 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * 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/>.
Holger Freyther32636e82008-12-27 11:07:15 +000019 *
20 */
21
22#include <stdarg.h>
Holger Freytherd546e312008-12-27 12:03:07 +000023#include <stdlib.h>
Holger Freyther32636e82008-12-27 11:07:15 +000024#include <stdio.h>
25#include <string.h>
Holger Freytherd546e312008-12-27 12:03:07 +000026#include <strings.h>
Holger Freyther32636e82008-12-27 11:07:15 +000027#include <time.h>
Harald Welte (local)b79bdd92009-12-26 19:45:22 +010028#include <errno.h>
Holger Freyther32636e82008-12-27 11:07:15 +000029
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010030#include <osmocom/core/talloc.h>
31#include <osmocom/core/utils.h>
32#include <osmocom/core/logging.h>
Harald Welte68d85d52012-06-16 17:45:59 +080033#include <osmocom/gprs/gprs_msgb.h>
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +010034#include <openbsc/gsm_data.h>
35#include <openbsc/gsm_subscriber.h>
Harald Weltedc5062b2010-03-26 21:28:59 +080036#include <openbsc/debug.h>
Holger Freyther32636e82008-12-27 11:07:15 +000037
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +010038/* default categories */
Harald Weltedc5062b2010-03-26 21:28:59 +080039static const struct log_info_cat default_categories[] = {
40 [DRLL] = {
41 .name = "DRLL",
Harald Weltef171a6e2010-05-11 10:51:30 +020042 .description = "A-bis Radio Link Layer (RLL)",
Harald Weltedc5062b2010-03-26 21:28:59 +080043 .color = "\033[1;31m",
44 .enabled = 1, .loglevel = LOGL_NOTICE,
45 },
46 [DCC] = {
47 .name = "DCC",
Harald Weltef171a6e2010-05-11 10:51:30 +020048 .description = "Layer3 Call Control (CC)",
Harald Weltedc5062b2010-03-26 21:28:59 +080049 .color = "\033[1;32m",
50 .enabled = 1, .loglevel = LOGL_NOTICE,
51 },
52 [DMM] = {
53 .name = "DMM",
Harald Weltef171a6e2010-05-11 10:51:30 +020054 .description = "Layer3 Mobility Management (MM)",
Harald Weltedc5062b2010-03-26 21:28:59 +080055 .color = "\033[1;33m",
56 .enabled = 1, .loglevel = LOGL_NOTICE,
57 },
58 [DRR] = {
59 .name = "DRR",
Harald Weltef171a6e2010-05-11 10:51:30 +020060 .description = "Layer3 Radio Resource (RR)",
Harald Weltedc5062b2010-03-26 21:28:59 +080061 .color = "\033[1;34m",
62 .enabled = 1, .loglevel = LOGL_NOTICE,
63 },
64 [DRSL] = {
65 .name = "DRSL",
Harald Weltef171a6e2010-05-11 10:51:30 +020066 .description = "A-bis Radio Siganlling Link (RSL)",
Harald Weltedc5062b2010-03-26 21:28:59 +080067 .color = "\033[1;35m",
68 .enabled = 1, .loglevel = LOGL_NOTICE,
69 },
70 [DNM] = {
71 .name = "DNM",
Harald Weltef171a6e2010-05-11 10:51:30 +020072 .description = "A-bis Network Management / O&M (NM/OML)",
Harald Weltedc5062b2010-03-26 21:28:59 +080073 .color = "\033[1;36m",
74 .enabled = 1, .loglevel = LOGL_INFO,
75 },
76 [DMNCC] = {
77 .name = "DMNCC",
Harald Weltef171a6e2010-05-11 10:51:30 +020078 .description = "MNCC API for Call Control application",
Harald Weltedc5062b2010-03-26 21:28:59 +080079 .color = "\033[1;39m",
80 .enabled = 1, .loglevel = LOGL_NOTICE,
81 },
Harald Weltedc5062b2010-03-26 21:28:59 +080082 [DPAG] = {
83 .name = "DPAG",
Harald Weltef171a6e2010-05-11 10:51:30 +020084 .description = "Paging Subsystem",
Harald Weltedc5062b2010-03-26 21:28:59 +080085 .color = "\033[1;38m",
86 .enabled = 1, .loglevel = LOGL_NOTICE,
87 },
88 [DMEAS] = {
89 .name = "DMEAS",
Harald Weltef171a6e2010-05-11 10:51:30 +020090 .description = "Radio Measurement Processing",
Harald Weltedc5062b2010-03-26 21:28:59 +080091 .enabled = 0, .loglevel = LOGL_NOTICE,
92 },
Harald Weltedc5062b2010-03-26 21:28:59 +080093 [DSCCP] = {
94 .name = "DSCCP",
95 .description = "SCCP Protocol",
96 .enabled = 1, .loglevel = LOGL_NOTICE,
97 },
98 [DMSC] = {
99 .name = "DMSC",
100 .description = "Mobile Switching Center",
101 .enabled = 1, .loglevel = LOGL_NOTICE,
102 },
103 [DMGCP] = {
104 .name = "DMGCP",
105 .description = "Media Gateway Control Protocol",
106 .enabled = 1, .loglevel = LOGL_NOTICE,
107 },
108 [DHO] = {
109 .name = "DHO",
110 .description = "Hand-Over",
111 .enabled = 1, .loglevel = LOGL_NOTICE,
112 },
113 [DDB] = {
114 .name = "DDB",
Harald Weltef171a6e2010-05-11 10:51:30 +0200115 .description = "Database Layer",
Harald Weltedc5062b2010-03-26 21:28:59 +0800116 .enabled = 1, .loglevel = LOGL_NOTICE,
117 },
118 [DREF] = {
119 .name = "DREF",
120 .description = "Reference Counting",
121 .enabled = 0, .loglevel = LOGL_NOTICE,
122 },
Harald Welte2977d672010-03-28 17:44:55 +0800123 [DGPRS] = {
124 .name = "DGPRS",
125 .description = "GPRS Packet Service",
126 .enabled = 1, .loglevel = LOGL_DEBUG,
127 },
Harald Welte6b72cdf2010-05-11 05:54:22 +0200128 [DNS] = {
129 .name = "DNS",
Harald Weltef171a6e2010-05-11 10:51:30 +0200130 .description = "GPRS Network Service (NS)",
Harald Welteb2e49182010-05-13 19:47:01 +0200131 .enabled = 1, .loglevel = LOGL_INFO,
Harald Welte6b72cdf2010-05-11 05:54:22 +0200132 },
133 [DBSSGP] = {
134 .name = "DBSSGP",
Harald Weltef171a6e2010-05-11 10:51:30 +0200135 .description = "GPRS BSS Gateway Protocol (BSSGP)",
Harald Welte6b72cdf2010-05-11 05:54:22 +0200136 .enabled = 1, .loglevel = LOGL_DEBUG,
137 },
Harald Welteb2e49182010-05-13 19:47:01 +0200138 [DLLC] = {
139 .name = "DLLC",
140 .description = "GPRS Logical Link Control Protocol (LLC)",
141 .enabled = 1, .loglevel = LOGL_DEBUG,
142 },
143 [DSNDCP] = {
144 .name = "DSNDCP",
145 .description = "GPRS Sub-Network Dependent Control Protocol (SNDCP)",
146 .enabled = 1, .loglevel = LOGL_DEBUG,
147 },
Holger Hans Peter Freyther3d73e0d2010-06-15 19:27:25 +0800148 [DNAT] = {
149 .name = "DNAT",
Holger Hans Peter Freyther30a3d2f2013-01-10 23:46:17 +0100150 .description = "GSM 08.08 NAT/Multiplexer",
Holger Hans Peter Freyther3d73e0d2010-06-15 19:27:25 +0800151 .enabled = 1, .loglevel = LOGL_NOTICE,
152 },
Daniel Willmann1c33d4c2011-07-19 12:14:34 +0200153 [DCTRL] = {
154 .name = "DCTRL",
155 .description = "Control interface",
156 .enabled = 1, .loglevel = LOGL_NOTICE,
157 },
Harald Weltef1033cc2012-11-08 16:14:37 +0100158 [DSMPP] = {
159 .name = "DSMPP",
160 .description = "SMPP interface for external SMS apps",
161 .enabled = 1, .loglevel = LOGL_DEBUG,
162 },
Holger Hans Peter Freyther06a88fa2015-04-05 19:34:12 +0200163 [DFILTER] = {
164 .name = "DFILTER",
165 .description = "BSC/NAT IMSI based filtering",
166 .enabled = 1, .loglevel = LOGL_DEBUG,
167 },
Daniel Willmann35a65ed2016-05-20 21:59:45 +0200168 [DRANAP] = {
169 .name = "DRANAP",
170 .description = "Radio Access Network Application Part Protocol",
171 .enabled = 1, .loglevel = LOGL_DEBUG,
172 },
Daniel Willmann3adb23c2016-05-20 21:59:35 +0200173 [DSUA] = {
174 .name = "DSUA",
175 .description = "SCCP User Adaptation Protocol",
176 .enabled = 1, .loglevel = LOGL_DEBUG,
177 },
Philipp Maierb4999b62016-10-26 15:19:41 +0200178 [DPCU] = {
179 .name = "DPCU",
180 .description = "PCU Interface",
181 .enabled = 1, .loglevel = LOGL_DEBUG,
182 },
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100183};
Holger Freyther32636e82008-12-27 11:07:15 +0000184
Neels Hofmeyr94f49a42017-02-17 17:06:59 +0100185static int filter_fn(const struct log_context *ctx, struct log_target *tar)
Harald Weltedc5062b2010-03-26 21:28:59 +0800186{
Neels Hofmeyr89a8e722017-02-23 18:00:51 +0100187 const struct gsm_subscriber *subscr = ctx->ctx[LOG_CTX_VLR_SUBSCR];
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100188 const struct bsc_subscr *bsub = ctx->ctx[LOG_CTX_BSC_SUBSCR];
Neels Hofmeyr89a8e722017-02-23 18:00:51 +0100189 const struct gprs_nsvc *nsvc = ctx->ctx[LOG_CTX_GB_NSVC];
190 const struct gprs_nsvc *bvc = ctx->ctx[LOG_CTX_GB_BVC];
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100191
Neels Hofmeyr89a8e722017-02-23 18:00:51 +0100192 if ((tar->filter_map & (1 << LOG_FLT_VLR_SUBSCR)) != 0
193 && subscr && subscr == tar->filter_data[LOG_FLT_VLR_SUBSCR])
Harald Weltedc5062b2010-03-26 21:28:59 +0800194 return 1;
Holger Freytherd546e312008-12-27 12:03:07 +0000195
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100196 if ((tar->filter_map & (1 << LOG_FLT_BSC_SUBSCR)) != 0
197 && bsub && bsub == tar->filter_data[LOG_FLT_BSC_SUBSCR])
198 return 1;
199
Harald Welte8be8c8f2010-05-15 23:52:02 +0200200 /* Filter on the NS Virtual Connection */
Neels Hofmeyr89a8e722017-02-23 18:00:51 +0100201 if ((tar->filter_map & (1 << LOG_FLT_GB_NSVC)) != 0
202 && nsvc && (nsvc == tar->filter_data[LOG_FLT_GB_NSVC]))
Harald Welte8be8c8f2010-05-15 23:52:02 +0200203 return 1;
204
Harald Welted9a55f62010-05-17 23:41:43 +0200205 /* Filter on the NS Virtual Connection */
Neels Hofmeyr89a8e722017-02-23 18:00:51 +0100206 if ((tar->filter_map & (1 << LOG_FLT_GB_BVC)) != 0
207 && bvc && (bvc == tar->filter_data[LOG_FLT_GB_BVC]))
Harald Welted9a55f62010-05-17 23:41:43 +0200208 return 1;
209
Harald Weltedc5062b2010-03-26 21:28:59 +0800210 return 0;
211}
212
213const struct log_info log_info = {
214 .filter_fn = filter_fn,
215 .cat = default_categories,
216 .num_cat = ARRAY_SIZE(default_categories),
Holger Freytherd546e312008-12-27 12:03:07 +0000217};
218
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100219void log_set_filter_vlr_subscr(struct log_target *target,
220 struct gsm_subscriber *vlr_subscr)
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100221{
Neels Hofmeyr89a8e722017-02-23 18:00:51 +0100222 struct gsm_subscriber **fsub = (void*)&target->filter_data[LOG_FLT_VLR_SUBSCR];
Neels Hofmeyrf13b3c92017-02-17 17:05:40 +0100223
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100224 /* free the old data */
Neels Hofmeyrf13b3c92017-02-17 17:05:40 +0100225 if (*fsub) {
226 subscr_put(*fsub);
227 *fsub = NULL;
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100228 }
Holger Hans Peter Freyther6995f242014-12-28 18:54:32 +0100229
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100230 if (vlr_subscr) {
Neels Hofmeyr89a8e722017-02-23 18:00:51 +0100231 target->filter_map |= (1 << LOG_FLT_VLR_SUBSCR);
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100232 *fsub = subscr_get(vlr_subscr);
Neels Hofmeyrf13b3c92017-02-17 17:05:40 +0100233 } else
Neels Hofmeyr89a8e722017-02-23 18:00:51 +0100234 target->filter_map &= ~(1 << LOG_FLT_VLR_SUBSCR);
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100235}