blob: 5355bf4ed693c4bb73f519ce09b80e202d1d4f52 [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",
42 .description = "Radio Link Layer",
43 .color = "\033[1;31m",
44 .enabled = 1, .loglevel = LOGL_NOTICE,
45 },
46 [DCC] = {
47 .name = "DCC",
48 .description = "Call Control",
49 .color = "\033[1;32m",
50 .enabled = 1, .loglevel = LOGL_NOTICE,
51 },
52 [DMM] = {
53 .name = "DMM",
54 .description = "Mobility Management",
55 .color = "\033[1;33m",
56 .enabled = 1, .loglevel = LOGL_NOTICE,
57 },
58 [DRR] = {
59 .name = "DRR",
60 .description = "Radio Resource",
61 .color = "\033[1;34m",
62 .enabled = 1, .loglevel = LOGL_NOTICE,
63 },
64 [DRSL] = {
65 .name = "DRSL",
66 .description = "Radio Siganlling Link",
67 .color = "\033[1;35m",
68 .enabled = 1, .loglevel = LOGL_NOTICE,
69 },
70 [DNM] = {
71 .name = "DNM",
72 .description = "Network Management (OML)",
73 .color = "\033[1;36m",
74 .enabled = 1, .loglevel = LOGL_INFO,
75 },
76 [DMNCC] = {
77 .name = "DMNCC",
78 .description = "BSC<->MSC interface",
79 .color = "\033[1;39m",
80 .enabled = 1, .loglevel = LOGL_NOTICE,
81 },
82 [DSMS] = {
83 .name = "DSMS",
84 .description = "Short Message Service",
85 .color = "\033[1;37m",
86 .enabled = 1, .loglevel = LOGL_NOTICE,
87 },
88 [DPAG] = {
89 .name = "DPAG",
90 .description = "Paging",
91 .color = "\033[1;38m",
92 .enabled = 1, .loglevel = LOGL_NOTICE,
93 },
94 [DMEAS] = {
95 .name = "DMEAS",
96 .description = "Measurement Processing",
97 .enabled = 0, .loglevel = LOGL_NOTICE,
98 },
99 [DMI] = {
100 .name = "DMI",
101 .description = "mISDN Input Driver",
102 .enabled = 0, .loglevel = LOGL_NOTICE,
103 },
104 [DMIB] = {
105 .name = "DMIB",
106 .description = "mISDN B-Channels",
107 .enabled = 0, .loglevel = LOGL_NOTICE,
108 },
109 [DMUX] = {
110 .name = "DMUX",
111 .description = "TRAU Frame Multiplex",
112 .enabled = 1, .loglevel = LOGL_NOTICE,
113 },
114 [DINP] = {
115 .name = "DINP",
116 .description = "Input Driver",
117 .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",
141 .description = "Database",
142 .enabled = 1, .loglevel = LOGL_NOTICE,
143 },
144 [DREF] = {
145 .name = "DREF",
146 .description = "Reference Counting",
147 .enabled = 0, .loglevel = LOGL_NOTICE,
148 },
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100149};
Holger Freyther32636e82008-12-27 11:07:15 +0000150
Harald Weltedc5062b2010-03-26 21:28:59 +0800151enum log_ctxt {
152 CTX_SUBSCRIBER,
Holger Freytherd546e312008-12-27 12:03:07 +0000153};
154
Harald Weltedc5062b2010-03-26 21:28:59 +0800155enum log_filter {
156 FLT_IMSI,
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100157};
158
Harald Weltedc5062b2010-03-26 21:28:59 +0800159static int filter_fn(const struct log_context *ctx,
160 struct log_target *tar)
161{
162 struct gsm_subscriber *subscr = ctx->ctx[CTX_SUBSCRIBER];
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100163
Harald Weltedc5062b2010-03-26 21:28:59 +0800164 if ((tar->filter_map & (1 << FLT_IMSI)) != 0
165 && subscr && strcmp(subscr->imsi, tar->filter_data[FLT_IMSI]) == 0)
166 return 1;
Holger Freytherd546e312008-12-27 12:03:07 +0000167
Harald Weltedc5062b2010-03-26 21:28:59 +0800168 return 0;
169}
170
171const struct log_info log_info = {
172 .filter_fn = filter_fn,
173 .cat = default_categories,
174 .num_cat = ARRAY_SIZE(default_categories),
Holger Freytherd546e312008-12-27 12:03:07 +0000175};
176
Harald Weltedc5062b2010-03-26 21:28:59 +0800177void log_set_imsi_filter(struct log_target *target, const char *imsi)
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100178{
179 if (imsi) {
Harald Weltedc5062b2010-03-26 21:28:59 +0800180 target->filter_map |= (1 << FLT_IMSI);
181 target->filter_data[FLT_IMSI] = talloc_strdup(target, imsi);
182 } else if (target->filter_data[FLT_IMSI]) {
183 target->filter_map &= ~(1 << FLT_IMSI);
184 talloc_free(target->filter_data[FLT_IMSI]);
185 target->filter_data[FLT_IMSI] = NULL;
Holger Hans Peter Freytherb61e3b22009-12-22 22:32:51 +0100186 }
187}