Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * (C) 2013-2016 by Harald Welte <laforge@gnumonks.org> |
| 3 | * |
| 4 | * originally based on earlier code from Dieter Spaar and Holger |
| 5 | * Freyther, though by now almost entirely rewritten. Nevertheless, |
| 6 | * thanks to Dieter and Holger! |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | */ |
| 22 | |
| 23 | #include "protocol/protocol.h" |
| 24 | #include "protocol/diagcmd.h" |
| 25 | #include "diag_cmd.h" |
| 26 | #include "diag_log.h" |
| 27 | #include "diag_msg.h" |
| 28 | |
| 29 | |
| 30 | /*********************************************************************** |
| 31 | * CMD Dispatch |
| 32 | ***********************************************************************/ |
| 33 | |
| 34 | static diag_cmd_handler *cmd_handlers[0xff]; |
| 35 | |
| 36 | /* called by individual modules to register their own decoders */ |
| 37 | void diag_cmd_reg_dispatch(const struct diag_cmd_dispatch_tbl *tbl, unsigned int size) |
| 38 | { |
| 39 | unsigned int i; |
| 40 | for (i = 0; i < size; i++) { |
| 41 | printf("Registering CMD dispatch for 0x%02x\n", tbl[i].code); |
| 42 | cmd_handlers[tbl[i].code] = tbl[i].handler; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | int diag_process_msg(struct diag_instance *di, struct msgb *msg) |
| 47 | { |
| 48 | uint8_t cmd = msg->l2h[0]; |
| 49 | |
| 50 | switch (cmd) { |
| 51 | case DIAG_LOG_F: |
| 52 | diag_log_handle(di, msg); |
| 53 | msgb_free(msg); |
| 54 | return 1; |
| 55 | case DIAG_EXT_MSG_F: |
| 56 | diag_rx_ext_msg_f(di, msg); |
| 57 | msgb_free(msg); |
| 58 | return 1; |
| 59 | default: |
| 60 | if (cmd_handlers[cmd]) { |
| 61 | (cmd_handlers[cmd])(di, msg); |
| 62 | msgb_free(msg); |
| 63 | return 1; |
| 64 | } else { |
| 65 | printf("Got %d bytes data of unknown payload type 0x%02x: %s\n", |
| 66 | msgb_length(msg), msg->l2h[0], |
| 67 | osmo_hexdump(msgb_data(msg), msgb_length(msg))); |
| 68 | return 0; |
| 69 | } |
| 70 | break; |
| 71 | } |
| 72 | } |