blob: dc79a843e14d0908befc821ff68c31fd136351f5 [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>
Harald Weltedc5062b2010-03-26 21:28:59 +080035#include <openbsc/debug.h>
Holger Freyther32636e82008-12-27 11:07:15 +000036
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +010037/* default categories */
Harald Weltedc5062b2010-03-26 21:28:59 +080038static const struct log_info_cat default_categories[] = {
39 [DRLL] = {
40 .name = "DRLL",
Harald Weltef171a6e2010-05-11 10:51:30 +020041 .description = "A-bis Radio Link Layer (RLL)",
Harald Weltedc5062b2010-03-26 21:28:59 +080042 .color = "\033[1;31m",
43 .enabled = 1, .loglevel = LOGL_NOTICE,
44 },
45 [DCC] = {
46 .name = "DCC",
Harald Weltef171a6e2010-05-11 10:51:30 +020047 .description = "Layer3 Call Control (CC)",
Harald Weltedc5062b2010-03-26 21:28:59 +080048 .color = "\033[1;32m",
49 .enabled = 1, .loglevel = LOGL_NOTICE,
50 },
51 [DMM] = {
52 .name = "DMM",
Harald Weltef171a6e2010-05-11 10:51:30 +020053 .description = "Layer3 Mobility Management (MM)",
Harald Weltedc5062b2010-03-26 21:28:59 +080054 .color = "\033[1;33m",
55 .enabled = 1, .loglevel = LOGL_NOTICE,
56 },
57 [DRR] = {
58 .name = "DRR",
Harald Weltef171a6e2010-05-11 10:51:30 +020059 .description = "Layer3 Radio Resource (RR)",
Harald Weltedc5062b2010-03-26 21:28:59 +080060 .color = "\033[1;34m",
61 .enabled = 1, .loglevel = LOGL_NOTICE,
62 },
63 [DRSL] = {
64 .name = "DRSL",
Harald Weltef171a6e2010-05-11 10:51:30 +020065 .description = "A-bis Radio Siganlling Link (RSL)",
Harald Weltedc5062b2010-03-26 21:28:59 +080066 .color = "\033[1;35m",
67 .enabled = 1, .loglevel = LOGL_NOTICE,
68 },
69 [DNM] = {
70 .name = "DNM",
Harald Weltef171a6e2010-05-11 10:51:30 +020071 .description = "A-bis Network Management / O&M (NM/OML)",
Harald Weltedc5062b2010-03-26 21:28:59 +080072 .color = "\033[1;36m",
73 .enabled = 1, .loglevel = LOGL_INFO,
74 },
75 [DMNCC] = {
76 .name = "DMNCC",
Harald Weltef171a6e2010-05-11 10:51:30 +020077 .description = "MNCC API for Call Control application",
Harald Weltedc5062b2010-03-26 21:28:59 +080078 .color = "\033[1;39m",
79 .enabled = 1, .loglevel = LOGL_NOTICE,
80 },
Harald Weltedc5062b2010-03-26 21:28:59 +080081 [DPAG] = {
82 .name = "DPAG",
Harald Weltef171a6e2010-05-11 10:51:30 +020083 .description = "Paging Subsystem",
Harald Weltedc5062b2010-03-26 21:28:59 +080084 .color = "\033[1;38m",
85 .enabled = 1, .loglevel = LOGL_NOTICE,
86 },
87 [DMEAS] = {
88 .name = "DMEAS",
Harald Weltef171a6e2010-05-11 10:51:30 +020089 .description = "Radio Measurement Processing",
Harald Weltedc5062b2010-03-26 21:28:59 +080090 .enabled = 0, .loglevel = LOGL_NOTICE,
91 },
Harald Weltedc5062b2010-03-26 21:28:59 +080092 [DSCCP] = {
93 .name = "DSCCP",
94 .description = "SCCP Protocol",
95 .enabled = 1, .loglevel = LOGL_NOTICE,
96 },
97 [DMSC] = {
98 .name = "DMSC",
99 .description = "Mobile Switching Center",
100 .enabled = 1, .loglevel = LOGL_NOTICE,
101 },
102 [DMGCP] = {
103 .name = "DMGCP",
104 .description = "Media Gateway Control Protocol",
105 .enabled = 1, .loglevel = LOGL_NOTICE,
106 },
107 [DHO] = {
108 .name = "DHO",
109 .description = "Hand-Over",
110 .enabled = 1, .loglevel = LOGL_NOTICE,
111 },
112 [DDB] = {
113 .name = "DDB",
Harald Weltef171a6e2010-05-11 10:51:30 +0200114 .description = "Database Layer",
Harald Weltedc5062b2010-03-26 21:28:59 +0800115 .enabled = 1, .loglevel = LOGL_NOTICE,
116 },
117 [DREF] = {
118 .name = "DREF",
119 .description = "Reference Counting",
120 .enabled = 0, .loglevel = LOGL_NOTICE,
121 },
Harald Welte2977d672010-03-28 17:44:55 +0800122 [DGPRS] = {
123 .name = "DGPRS",
124 .description = "GPRS Packet Service",
125 .enabled = 1, .loglevel = LOGL_DEBUG,
126 },
Harald Welte6b72cdf2010-05-11 05:54:22 +0200127 [DNS] = {
128 .name = "DNS",
Harald Weltef171a6e2010-05-11 10:51:30 +0200129 .description = "GPRS Network Service (NS)",
Harald Welteb2e49182010-05-13 19:47:01 +0200130 .enabled = 1, .loglevel = LOGL_INFO,
Harald Welte6b72cdf2010-05-11 05:54:22 +0200131 },
132 [DBSSGP] = {
133 .name = "DBSSGP",
Harald Weltef171a6e2010-05-11 10:51:30 +0200134 .description = "GPRS BSS Gateway Protocol (BSSGP)",
Harald Welte6b72cdf2010-05-11 05:54:22 +0200135 .enabled = 1, .loglevel = LOGL_DEBUG,
136 },
Harald Welteb2e49182010-05-13 19:47:01 +0200137 [DLLC] = {
138 .name = "DLLC",
139 .description = "GPRS Logical Link Control Protocol (LLC)",
140 .enabled = 1, .loglevel = LOGL_DEBUG,
141 },
142 [DSNDCP] = {
143 .name = "DSNDCP",
144 .description = "GPRS Sub-Network Dependent Control Protocol (SNDCP)",
145 .enabled = 1, .loglevel = LOGL_DEBUG,
146 },
Holger Hans Peter Freyther3d73e0d2010-06-15 19:27:25 +0800147 [DNAT] = {
148 .name = "DNAT",
Holger Hans Peter Freyther30a3d2f2013-01-10 23:46:17 +0100149 .description = "GSM 08.08 NAT/Multiplexer",
Holger Hans Peter Freyther3d73e0d2010-06-15 19:27:25 +0800150 .enabled = 1, .loglevel = LOGL_NOTICE,
151 },
Daniel Willmann1c33d4c2011-07-19 12:14:34 +0200152 [DCTRL] = {
153 .name = "DCTRL",
154 .description = "Control interface",
155 .enabled = 1, .loglevel = LOGL_NOTICE,
156 },
Harald Weltef1033cc2012-11-08 16:14:37 +0100157 [DSMPP] = {
158 .name = "DSMPP",
159 .description = "SMPP interface for external SMS apps",
160 .enabled = 1, .loglevel = LOGL_DEBUG,
161 },
Holger Hans Peter Freyther06a88fa2015-04-05 19:34:12 +0200162 [DFILTER] = {
163 .name = "DFILTER",
164 .description = "BSC/NAT IMSI based filtering",
165 .enabled = 1, .loglevel = LOGL_DEBUG,
166 },
Daniel Willmann35a65ed2016-05-20 21:59:45 +0200167 [DRANAP] = {
168 .name = "DRANAP",
169 .description = "Radio Access Network Application Part Protocol",
170 .enabled = 1, .loglevel = LOGL_DEBUG,
171 },
Daniel Willmann3adb23c2016-05-20 21:59:35 +0200172 [DSUA] = {
173 .name = "DSUA",
174 .description = "SCCP User Adaptation Protocol",
175 .enabled = 1, .loglevel = LOGL_DEBUG,
176 },
Philipp Maierb4999b62016-10-26 15:19:41 +0200177 [DPCU] = {
178 .name = "DPCU",
179 .description = "PCU Interface",
180 .enabled = 1, .loglevel = LOGL_DEBUG,
181 },
Harald Weltea183a6e2016-06-17 00:06:42 +0200182 [DVLR] = {
183 .name = "DVLR",
184 .description = "Visitor Location Register",
185 .enabled = 1, .loglevel = LOGL_DEBUG,
186 },
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100187};
Holger Freyther32636e82008-12-27 11:07:15 +0000188
Neels Hofmeyr94f49a42017-02-17 17:06:59 +0100189static int filter_fn(const struct log_context *ctx, struct log_target *tar)
Harald Weltedc5062b2010-03-26 21:28:59 +0800190{
Harald Welte7b423ed2016-06-19 18:06:02 +0200191 const struct vlr_subscr *vsub = ctx->ctx[LOG_CTX_VLR_SUBSCR];
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100192 const struct bsc_subscr *bsub = ctx->ctx[LOG_CTX_BSC_SUBSCR];
Neels Hofmeyr89a8e722017-02-23 18:00:51 +0100193 const struct gprs_nsvc *nsvc = ctx->ctx[LOG_CTX_GB_NSVC];
194 const struct gprs_nsvc *bvc = ctx->ctx[LOG_CTX_GB_BVC];
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100195
Neels Hofmeyr89a8e722017-02-23 18:00:51 +0100196 if ((tar->filter_map & (1 << LOG_FLT_VLR_SUBSCR)) != 0
Harald Welte7b423ed2016-06-19 18:06:02 +0200197 && vsub && vsub == tar->filter_data[LOG_FLT_VLR_SUBSCR])
Harald Weltedc5062b2010-03-26 21:28:59 +0800198 return 1;
Holger Freytherd546e312008-12-27 12:03:07 +0000199
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100200 if ((tar->filter_map & (1 << LOG_FLT_BSC_SUBSCR)) != 0
201 && bsub && bsub == tar->filter_data[LOG_FLT_BSC_SUBSCR])
202 return 1;
203
Harald Welte8be8c8f2010-05-15 23:52:02 +0200204 /* Filter on the NS Virtual Connection */
Neels Hofmeyr89a8e722017-02-23 18:00:51 +0100205 if ((tar->filter_map & (1 << LOG_FLT_GB_NSVC)) != 0
206 && nsvc && (nsvc == tar->filter_data[LOG_FLT_GB_NSVC]))
Harald Welte8be8c8f2010-05-15 23:52:02 +0200207 return 1;
208
Harald Welted9a55f62010-05-17 23:41:43 +0200209 /* Filter on the NS Virtual Connection */
Neels Hofmeyr89a8e722017-02-23 18:00:51 +0100210 if ((tar->filter_map & (1 << LOG_FLT_GB_BVC)) != 0
211 && bvc && (bvc == tar->filter_data[LOG_FLT_GB_BVC]))
Harald Welted9a55f62010-05-17 23:41:43 +0200212 return 1;
213
Harald Weltedc5062b2010-03-26 21:28:59 +0800214 return 0;
215}
216
217const struct log_info log_info = {
218 .filter_fn = filter_fn,
219 .cat = default_categories,
220 .num_cat = ARRAY_SIZE(default_categories),
Holger Freytherd546e312008-12-27 12:03:07 +0000221};