blob: 512935a20f7f36893da704ad26771dacb0dc59e5 [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
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 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 General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#include <stdarg.h>
Holger Freytherd546e312008-12-27 12:03:07 +000024#include <stdlib.h>
Holger Freyther32636e82008-12-27 11:07:15 +000025#include <stdio.h>
26#include <string.h>
Holger Freytherd546e312008-12-27 12:03:07 +000027#include <strings.h>
Holger Freyther32636e82008-12-27 11:07:15 +000028#include <time.h>
Harald Welte (local)b79bdd92009-12-26 19:45:22 +010029#include <errno.h>
Holger Freyther32636e82008-12-27 11:07:15 +000030
Harald Weltedfe6c7d2010-02-20 16:24:02 +010031#include <osmocore/talloc.h>
Harald Welte2e411c72010-03-01 21:59:06 +010032#include <osmocore/utils.h>
Harald Weltedc5062b2010-03-26 21:28:59 +080033#include <osmocore/logging.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 },
82 [DSMS] = {
83 .name = "DSMS",
Harald Weltef171a6e2010-05-11 10:51:30 +020084 .description = "Layer3 Short Message Service (SMS)",
Harald Weltedc5062b2010-03-26 21:28:59 +080085 .color = "\033[1;37m",
86 .enabled = 1, .loglevel = LOGL_NOTICE,
87 },
88 [DPAG] = {
89 .name = "DPAG",
Harald Weltef171a6e2010-05-11 10:51:30 +020090 .description = "Paging Subsystem",
Harald Weltedc5062b2010-03-26 21:28:59 +080091 .color = "\033[1;38m",
92 .enabled = 1, .loglevel = LOGL_NOTICE,
93 },
94 [DMEAS] = {
95 .name = "DMEAS",
Harald Weltef171a6e2010-05-11 10:51:30 +020096 .description = "Radio Measurement Processing",
Harald Weltedc5062b2010-03-26 21:28:59 +080097 .enabled = 0, .loglevel = LOGL_NOTICE,
98 },
99 [DMI] = {
100 .name = "DMI",
Harald Weltef171a6e2010-05-11 10:51:30 +0200101 .description = "A-bis Input Driver for Signalling",
Harald Weltedc5062b2010-03-26 21:28:59 +0800102 .enabled = 0, .loglevel = LOGL_NOTICE,
103 },
104 [DMIB] = {
105 .name = "DMIB",
Harald Weltef171a6e2010-05-11 10:51:30 +0200106 .description = "A-bis Input Driver for B-Channels (voice)",
Harald Weltedc5062b2010-03-26 21:28:59 +0800107 .enabled = 0, .loglevel = LOGL_NOTICE,
108 },
109 [DMUX] = {
110 .name = "DMUX",
Harald Weltef171a6e2010-05-11 10:51:30 +0200111 .description = "A-bis B-Subchannel TRAU Frame Multiplex",
Harald Weltedc5062b2010-03-26 21:28:59 +0800112 .enabled = 1, .loglevel = LOGL_NOTICE,
113 },
114 [DINP] = {
115 .name = "DINP",
Harald Weltef171a6e2010-05-11 10:51:30 +0200116 .description = "A-bis Intput Subsystem",
Harald Weltedc5062b2010-03-26 21:28:59 +0800117 .enabled = 1, .loglevel = LOGL_NOTICE,
118 },
119 [DSCCP] = {
120 .name = "DSCCP",
121 .description = "SCCP Protocol",
122 .enabled = 1, .loglevel = LOGL_NOTICE,
123 },
124 [DMSC] = {
125 .name = "DMSC",
126 .description = "Mobile Switching Center",
127 .enabled = 1, .loglevel = LOGL_NOTICE,
128 },
129 [DMGCP] = {
130 .name = "DMGCP",
131 .description = "Media Gateway Control Protocol",
132 .enabled = 1, .loglevel = LOGL_NOTICE,
133 },
134 [DHO] = {
135 .name = "DHO",
136 .description = "Hand-Over",
137 .enabled = 1, .loglevel = LOGL_NOTICE,
138 },
139 [DDB] = {
140 .name = "DDB",
Harald Weltef171a6e2010-05-11 10:51:30 +0200141 .description = "Database Layer",
Harald Weltedc5062b2010-03-26 21:28:59 +0800142 .enabled = 1, .loglevel = LOGL_NOTICE,
143 },
144 [DREF] = {
145 .name = "DREF",
146 .description = "Reference Counting",
147 .enabled = 0, .loglevel = LOGL_NOTICE,
148 },
Harald Welte2977d672010-03-28 17:44:55 +0800149 [DGPRS] = {
150 .name = "DGPRS",
151 .description = "GPRS Packet Service",
152 .enabled = 1, .loglevel = LOGL_DEBUG,
153 },
Harald Welte6b72cdf2010-05-11 05:54:22 +0200154 [DNS] = {
155 .name = "DNS",
Harald Weltef171a6e2010-05-11 10:51:30 +0200156 .description = "GPRS Network Service (NS)",
Harald Welteb2e49182010-05-13 19:47:01 +0200157 .enabled = 1, .loglevel = LOGL_INFO,
Harald Welte6b72cdf2010-05-11 05:54:22 +0200158 },
159 [DBSSGP] = {
160 .name = "DBSSGP",
Harald Weltef171a6e2010-05-11 10:51:30 +0200161 .description = "GPRS BSS Gateway Protocol (BSSGP)",
Harald Welte6b72cdf2010-05-11 05:54:22 +0200162 .enabled = 1, .loglevel = LOGL_DEBUG,
163 },
Harald Welteb2e49182010-05-13 19:47:01 +0200164 [DLLC] = {
165 .name = "DLLC",
166 .description = "GPRS Logical Link Control Protocol (LLC)",
167 .enabled = 1, .loglevel = LOGL_DEBUG,
168 },
169 [DSNDCP] = {
170 .name = "DSNDCP",
171 .description = "GPRS Sub-Network Dependent Control Protocol (SNDCP)",
172 .enabled = 1, .loglevel = LOGL_DEBUG,
173 },
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100174};
Holger Freyther32636e82008-12-27 11:07:15 +0000175
Harald Weltedc5062b2010-03-26 21:28:59 +0800176enum log_filter {
Harald Welte332442d2010-03-26 21:40:29 +0800177 _FLT_ALL = LOG_FILTER_ALL, /* libosmocore */
178 FLT_IMSI = 1,
Harald Welted9a55f62010-05-17 23:41:43 +0200179 FLT_NSVC = 2,
180 FLT_BVC = 3,
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100181};
182
Harald Weltedc5062b2010-03-26 21:28:59 +0800183static int filter_fn(const struct log_context *ctx,
184 struct log_target *tar)
185{
Harald Welte3bac9a82010-05-15 23:50:56 +0200186 struct gsm_subscriber *subscr = ctx->ctx[BSC_CTX_SUBSCR];
Harald Welte8be8c8f2010-05-15 23:52:02 +0200187 const struct gprs_nsvc *nsvc = ctx->ctx[BSC_CTX_NSVC];
Harald Welted9a55f62010-05-17 23:41:43 +0200188 const struct gprs_nsvc *bvc = ctx->ctx[BSC_CTX_BVC];
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100189
Harald Weltedc5062b2010-03-26 21:28:59 +0800190 if ((tar->filter_map & (1 << FLT_IMSI)) != 0
191 && subscr && strcmp(subscr->imsi, tar->filter_data[FLT_IMSI]) == 0)
192 return 1;
Holger Freytherd546e312008-12-27 12:03:07 +0000193
Harald Welte8be8c8f2010-05-15 23:52:02 +0200194 /* Filter on the NS Virtual Connection */
195 if ((tar->filter_map & (1 << FLT_NSVC)) != 0
196 && nsvc && (nsvc == tar->filter_data[FLT_NSVC]))
197 return 1;
198
Harald Welted9a55f62010-05-17 23:41:43 +0200199 /* Filter on the NS Virtual Connection */
200 if ((tar->filter_map & (1 << FLT_BVC)) != 0
201 && bvc && (bvc == tar->filter_data[FLT_BVC]))
202 return 1;
203
Harald Weltedc5062b2010-03-26 21:28:59 +0800204 return 0;
205}
206
207const struct log_info log_info = {
208 .filter_fn = filter_fn,
209 .cat = default_categories,
210 .num_cat = ARRAY_SIZE(default_categories),
Holger Freytherd546e312008-12-27 12:03:07 +0000211};
212
Harald Weltedc5062b2010-03-26 21:28:59 +0800213void log_set_imsi_filter(struct log_target *target, const char *imsi)
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100214{
215 if (imsi) {
Harald Weltedc5062b2010-03-26 21:28:59 +0800216 target->filter_map |= (1 << FLT_IMSI);
217 target->filter_data[FLT_IMSI] = talloc_strdup(target, imsi);
218 } else if (target->filter_data[FLT_IMSI]) {
219 target->filter_map &= ~(1 << FLT_IMSI);
220 talloc_free(target->filter_data[FLT_IMSI]);
221 target->filter_data[FLT_IMSI] = NULL;
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100222 }
223}
Harald Welte8be8c8f2010-05-15 23:52:02 +0200224
Holger Hans Peter Freytherd92f9af2010-05-23 20:59:55 +0800225void log_set_nsvc_filter(struct log_target *target, struct gprs_nsvc *nsvc)
Harald Welte8be8c8f2010-05-15 23:52:02 +0200226{
227 if (nsvc) {
228 target->filter_map |= (1 << FLT_NSVC);
229 target->filter_data[FLT_NSVC] = nsvc;
230 } else if (target->filter_data[FLT_NSVC]) {
231 target->filter_map = ~(1 << FLT_NSVC);
232 target->filter_data[FLT_NSVC] = NULL;
233 }
234}
Harald Welted9a55f62010-05-17 23:41:43 +0200235
Holger Hans Peter Freytherd92f9af2010-05-23 20:59:55 +0800236void log_set_bvc_filter(struct log_target *target, struct bssgp_bvc_ctx *bctx)
Harald Welted9a55f62010-05-17 23:41:43 +0200237{
238 if (bctx) {
239 target->filter_map |= (1 << FLT_BVC);
240 target->filter_data[FLT_BVC] = bctx;
241 } else if (target->filter_data[FLT_NSVC]) {
242 target->filter_map = ~(1 << FLT_BVC);
243 target->filter_data[FLT_BVC] = NULL;
244 }
245}