Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 1 | /* OpenBSC Debugging/Logging support code */ |
| 2 | |
| 3 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 4 | * (C) 2008 by Holger Hans Peter Freyther <zecke@selfish.org> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 8 | * 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 Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 16 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * 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 Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <stdarg.h> |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 23 | #include <stdlib.h> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 24 | #include <stdio.h> |
| 25 | #include <string.h> |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 26 | #include <strings.h> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 27 | #include <time.h> |
Harald Welte (local) | b79bdd9 | 2009-12-26 19:45:22 +0100 | [diff] [blame] | 28 | #include <errno.h> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 29 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 30 | #include <osmocom/core/talloc.h> |
| 31 | #include <osmocom/core/utils.h> |
| 32 | #include <osmocom/core/logging.h> |
Harald Welte | 68d85d5 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 33 | #include <osmocom/gprs/gprs_msgb.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 34 | #include <osmocom/msc/gsm_data.h> |
| 35 | #include <osmocom/msc/debug.h> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 36 | |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 37 | /* default categories */ |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 38 | static const struct log_info_cat default_categories[] = { |
| 39 | [DRLL] = { |
| 40 | .name = "DRLL", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 41 | .description = "A-bis Radio Link Layer (RLL)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 42 | .color = "\033[1;31m", |
| 43 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 44 | }, |
| 45 | [DCC] = { |
| 46 | .name = "DCC", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 47 | .description = "Layer3 Call Control (CC)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 48 | .color = "\033[1;32m", |
| 49 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 50 | }, |
| 51 | [DMM] = { |
| 52 | .name = "DMM", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 53 | .description = "Layer3 Mobility Management (MM)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 54 | .color = "\033[1;33m", |
| 55 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 56 | }, |
| 57 | [DRR] = { |
| 58 | .name = "DRR", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 59 | .description = "Layer3 Radio Resource (RR)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 60 | .color = "\033[1;34m", |
| 61 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 62 | }, |
| 63 | [DRSL] = { |
| 64 | .name = "DRSL", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 65 | .description = "A-bis Radio Siganlling Link (RSL)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 66 | .color = "\033[1;35m", |
| 67 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 68 | }, |
| 69 | [DNM] = { |
| 70 | .name = "DNM", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 71 | .description = "A-bis Network Management / O&M (NM/OML)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 72 | .color = "\033[1;36m", |
| 73 | .enabled = 1, .loglevel = LOGL_INFO, |
| 74 | }, |
| 75 | [DMNCC] = { |
| 76 | .name = "DMNCC", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 77 | .description = "MNCC API for Call Control application", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 78 | .color = "\033[1;39m", |
| 79 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 80 | }, |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 81 | [DPAG] = { |
| 82 | .name = "DPAG", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 83 | .description = "Paging Subsystem", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 84 | .color = "\033[1;38m", |
| 85 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 86 | }, |
| 87 | [DMEAS] = { |
| 88 | .name = "DMEAS", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 89 | .description = "Radio Measurement Processing", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 90 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 91 | }, |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 92 | [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 Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 114 | .description = "Database Layer", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 115 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 116 | }, |
| 117 | [DREF] = { |
| 118 | .name = "DREF", |
| 119 | .description = "Reference Counting", |
| 120 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 121 | }, |
Harald Welte | 2977d67 | 2010-03-28 17:44:55 +0800 | [diff] [blame] | 122 | [DGPRS] = { |
| 123 | .name = "DGPRS", |
| 124 | .description = "GPRS Packet Service", |
| 125 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 126 | }, |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 127 | [DNS] = { |
| 128 | .name = "DNS", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 129 | .description = "GPRS Network Service (NS)", |
Harald Welte | b2e4918 | 2010-05-13 19:47:01 +0200 | [diff] [blame] | 130 | .enabled = 1, .loglevel = LOGL_INFO, |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 131 | }, |
| 132 | [DBSSGP] = { |
| 133 | .name = "DBSSGP", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 134 | .description = "GPRS BSS Gateway Protocol (BSSGP)", |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 135 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 136 | }, |
Harald Welte | b2e4918 | 2010-05-13 19:47:01 +0200 | [diff] [blame] | 137 | [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 Freyther | 3d73e0d | 2010-06-15 19:27:25 +0800 | [diff] [blame] | 147 | [DNAT] = { |
| 148 | .name = "DNAT", |
Holger Hans Peter Freyther | 30a3d2f | 2013-01-10 23:46:17 +0100 | [diff] [blame] | 149 | .description = "GSM 08.08 NAT/Multiplexer", |
Holger Hans Peter Freyther | 3d73e0d | 2010-06-15 19:27:25 +0800 | [diff] [blame] | 150 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 151 | }, |
Daniel Willmann | 1c33d4c | 2011-07-19 12:14:34 +0200 | [diff] [blame] | 152 | [DCTRL] = { |
| 153 | .name = "DCTRL", |
| 154 | .description = "Control interface", |
| 155 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 156 | }, |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 157 | [DSMPP] = { |
| 158 | .name = "DSMPP", |
| 159 | .description = "SMPP interface for external SMS apps", |
| 160 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 161 | }, |
Holger Hans Peter Freyther | 06a88fa | 2015-04-05 19:34:12 +0200 | [diff] [blame] | 162 | [DFILTER] = { |
| 163 | .name = "DFILTER", |
| 164 | .description = "BSC/NAT IMSI based filtering", |
| 165 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 166 | }, |
Daniel Willmann | 35a65ed | 2016-05-20 21:59:45 +0200 | [diff] [blame] | 167 | [DRANAP] = { |
| 168 | .name = "DRANAP", |
| 169 | .description = "Radio Access Network Application Part Protocol", |
| 170 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 171 | }, |
Daniel Willmann | 3adb23c | 2016-05-20 21:59:35 +0200 | [diff] [blame] | 172 | [DSUA] = { |
| 173 | .name = "DSUA", |
| 174 | .description = "SCCP User Adaptation Protocol", |
| 175 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 176 | }, |
Philipp Maier | b4999b6 | 2016-10-26 15:19:41 +0200 | [diff] [blame] | 177 | [DPCU] = { |
| 178 | .name = "DPCU", |
| 179 | .description = "PCU Interface", |
| 180 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 181 | }, |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 182 | [DVLR] = { |
| 183 | .name = "DVLR", |
| 184 | .description = "Visitor Location Register", |
| 185 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 186 | }, |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 187 | [DIUCS] = { |
| 188 | .name = "DIUCS", |
| 189 | .description = "Iu-CS Protocol", |
| 190 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 191 | }, |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 192 | [DSIGTRAN] = { |
| 193 | .name = "DSIGTRAN", |
| 194 | .description = "SIGTRAN Signalling Transport", |
| 195 | .color = "\033[1;29m", |
| 196 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 197 | }, |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 198 | }; |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 199 | |
Neels Hofmeyr | 94f49a4 | 2017-02-17 17:06:59 +0100 | [diff] [blame] | 200 | static int filter_fn(const struct log_context *ctx, struct log_target *tar) |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 201 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 202 | const struct vlr_subscr *vsub = ctx->ctx[LOG_CTX_VLR_SUBSCR]; |
Neels Hofmeyr | 6d804b1 | 2017-02-18 22:20:46 +0100 | [diff] [blame] | 203 | const struct bsc_subscr *bsub = ctx->ctx[LOG_CTX_BSC_SUBSCR]; |
Neels Hofmeyr | 89a8e72 | 2017-02-23 18:00:51 +0100 | [diff] [blame] | 204 | const struct gprs_nsvc *nsvc = ctx->ctx[LOG_CTX_GB_NSVC]; |
| 205 | const struct gprs_nsvc *bvc = ctx->ctx[LOG_CTX_GB_BVC]; |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 206 | |
Neels Hofmeyr | 89a8e72 | 2017-02-23 18:00:51 +0100 | [diff] [blame] | 207 | if ((tar->filter_map & (1 << LOG_FLT_VLR_SUBSCR)) != 0 |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 208 | && vsub && vsub == tar->filter_data[LOG_FLT_VLR_SUBSCR]) |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 209 | return 1; |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 210 | |
Neels Hofmeyr | 6d804b1 | 2017-02-18 22:20:46 +0100 | [diff] [blame] | 211 | if ((tar->filter_map & (1 << LOG_FLT_BSC_SUBSCR)) != 0 |
| 212 | && bsub && bsub == tar->filter_data[LOG_FLT_BSC_SUBSCR]) |
| 213 | return 1; |
| 214 | |
Harald Welte | 8be8c8f | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 215 | /* Filter on the NS Virtual Connection */ |
Neels Hofmeyr | 89a8e72 | 2017-02-23 18:00:51 +0100 | [diff] [blame] | 216 | if ((tar->filter_map & (1 << LOG_FLT_GB_NSVC)) != 0 |
| 217 | && nsvc && (nsvc == tar->filter_data[LOG_FLT_GB_NSVC])) |
Harald Welte | 8be8c8f | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 218 | return 1; |
| 219 | |
Harald Welte | d9a55f6 | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 220 | /* Filter on the NS Virtual Connection */ |
Neels Hofmeyr | 89a8e72 | 2017-02-23 18:00:51 +0100 | [diff] [blame] | 221 | if ((tar->filter_map & (1 << LOG_FLT_GB_BVC)) != 0 |
| 222 | && bvc && (bvc == tar->filter_data[LOG_FLT_GB_BVC])) |
Harald Welte | d9a55f6 | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 223 | return 1; |
| 224 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | const struct log_info log_info = { |
| 229 | .filter_fn = filter_fn, |
| 230 | .cat = default_categories, |
| 231 | .num_cat = ARRAY_SIZE(default_categories), |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 232 | }; |