Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/next/external/cache/sources/hcitools/monitor/lmp.c
Views: 3959
/*1*2* BlueZ - Bluetooth protocol stack for Linux3*4* Copyright (C) 2011-2012 Intel Corporation5* Copyright (C) 2004-2010 Marcel Holtmann <[email protected]>6*7*8* This program is free software; you can redistribute it and/or modify9* it under the terms of the GNU General Public License as published by10* the Free Software Foundation; either version 2 of the License, or11* (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 of15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16* GNU General Public License for more details.17*18* You should have received a copy of the GNU General Public License19* along with this program; if not, write to the Free Software20* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA21*22*/2324#ifdef HAVE_CONFIG_H25#include <config.h>26#endif2728#include <stdio.h>2930#include "display.h"31#include "packet.h"32#include "lmp.h"3334#define COLOR_OPCODE COLOR_MAGENTA35#define COLOR_OPCODE_UNKNOWN COLOR_WHITE_BG3637#define ESC4(x) ((127 << 8) | (x))3839struct lmp_data {40uint16_t opcode;41const char *str;42void (*func) (const void *data, uint8_t size);43uint8_t size;44bool fixed;45};4647static const struct lmp_data lmp_table[] = {48{ 1, "LMP_name_req" },49{ 2, "LMP_name_res" },50{ 3, "LMP_accepted" },51{ 4, "LMP_not_accepted" },52{ 5, "LMP_clkoffset_req" },53{ 6, "LMP_clkoffset_res" },54{ 7, "LMP_detach" },55{ 8, "LMP_in_rand" },56{ 9, "LMP_comb_key" },57{ 10, "LMP_unit_key" },58{ 11, "LMP_au_rand" },59{ 12, "LMP_sres" },60{ 13, "LMP_temp_rand" },61{ 14, "LMP_temp_key" },62{ 15, "LMP_encryption_mode_req" },63{ 16, "LMP_encryption_key_size_req" },64{ 17, "LMP_start_encryption_req" },65{ 18, "LMP_stop_encryption_req" },66{ 19, "LMP_switch_req" },67{ 20, "LMP_hold" },68{ 21, "LMP_hold_req" },69{ 22, "LMP_sniff" },70{ 23, "LMP_sniff_req" },71{ 24, "LMP_unsniff_req" },72{ 25, "LMP_park_req" },73{ 26, "LMP_park" },74{ 27, "LMP_set_broadcast_scan_window" },75{ 28, "LMP_modify_beacon" },76{ 29, "LMP_unpark_BD_ADDR_req" },77{ 30, "LMP_unpark_PM_ADDR_req" },78{ 31, "LMP_incr_power_req" },79{ 32, "LMP_decr_power_req" },80{ 33, "LMP_max_power" },81{ 34, "LMP_min_power" },82{ 35, "LMP_auto_rate" },83{ 36, "LMP_preferred_rate" },84{ 37, "LMP_version_req" },85{ 38, "LMP_version_res" },86{ 39, "LMP_features_req" },87{ 40, "LMP_features_res" },88{ 41, "LMP_quality_of_service" },89{ 42, "LMP_quality_of_service_req" },90{ 43, "LMP_SCO_link_req" },91{ 44, "LMP_remove_SCO_link_req" },92{ 45, "LMP_max_slot" },93{ 46, "LMP_max_slot_req" },94{ 47, "LMP_timing_accuracy_req" },95{ 48, "LMP_timing_accuracy_res" },96{ 49, "LMP_setup_complete" },97{ 50, "LMP_use_semi_permanent_key" },98{ 51, "LMP_host_connection_req" },99{ 52, "LMP_slot_offset" },100{ 53, "LMP_page_mode_req" },101{ 54, "LMP_Page_scan_mode_req" },102{ 55, "LMP_supervision_timeout" },103{ 56, "LMP_test_activate" },104{ 57, "LMP_test_control" },105{ 58, "LMP_encryption_key_size_mask_req" },106{ 59, "LMP_encryption_key_size_mask_res" },107{ 60, "LMP_set_AFH" },108{ 61, "LMP_encapsulated_header" },109{ 62, "LMP_encapsulated_payload" },110{ 63, "LMP_simple_pairing_confirm" },111{ 64, "LMP_simple_pairing_number" },112{ 65, "LMP_DHkey_check" },113{ 66, "LMP_pause_encryption_aes_req" },114{ ESC4(1), "LMP_accepted_ext" },115{ ESC4(2), "LMP_not_accepted_ext" },116{ ESC4(3), "LMP_features_req_ext" },117{ ESC4(4), "LMP_features_res_ext" },118{ ESC4(5), "LMP_clk_adj" },119{ ESC4(6), "LMP_clk_adj_ack" },120{ ESC4(7), "LMP_clk_adj_req" },121{ ESC4(11), "LMP_packet_type_table" },122{ ESC4(12), "LMP_eSCO_link_req" },123{ ESC4(13), "LMP_remove_eSCO_link_req" },124{ ESC4(16), "LMP_channel_classification_req" },125{ ESC4(17), "LMP_channel_classification" },126{ ESC4(21), "LMP_sniff_subrating_req" },127{ ESC4(22), "LMP_sniff_subrating_res" },128{ ESC4(23), "LMP_pause_encryption_req" },129{ ESC4(24), "LMP_resume_encryption_req" },130{ ESC4(25), "LMP_IO_capability_req" },131{ ESC4(26), "LMP_IO_capability_res" },132{ ESC4(27), "LMP_numeric_comparision_failed" },133{ ESC4(28), "LMP_passkey_failed" },134{ ESC4(29), "LMP_oob_failed" },135{ ESC4(30), "LMP_keypress_notification" },136{ ESC4(31), "LMP_power_control_req" },137{ ESC4(32), "LMP_power_control_res" },138{ ESC4(33), "LMP_ping_req" },139{ ESC4(34), "LMP_ping_res" },140{ }141};142143144void lmp_packet(const void *data, uint8_t size)145{146const struct lmp_data *lmp_data = NULL;147const char *opcode_color, *opcode_str;148uint16_t opcode;149uint8_t tid, off;150int i;151152tid = ((const uint8_t *) data)[0] & 0x01;153opcode = (((const uint8_t *) data)[0] & 0xfe) >> 1;154155switch (opcode) {156case 127:157opcode = ESC4(((const uint8_t *) data)[1]);158off = 2;159break;160case 126:161case 125:162case 124:163return;164default:165off = 1;166break;167}168169for (i = 0; lmp_table[i].str; i++) {170if (lmp_table[i].opcode == opcode) {171lmp_data = &lmp_table[i];172break;173}174}175176if (lmp_data) {177if (lmp_data->func)178opcode_color = COLOR_OPCODE;179else180opcode_color = COLOR_OPCODE_UNKNOWN;181opcode_str = lmp_data->str;182} else {183opcode_color = COLOR_OPCODE_UNKNOWN;184opcode_str = "Unknown";185}186187if (opcode & 0xff00)188print_indent(6, opcode_color, "", opcode_str, COLOR_OFF,189" (%d/%d) TID %d", opcode >> 8, opcode & 0xff, tid);190else191print_indent(6, opcode_color, "", opcode_str, COLOR_OFF,192" (%d) TID %d", opcode, tid);193194if (!lmp_data || !lmp_data->func) {195packet_hexdump(data + off, size - off);196return;197}198199if (lmp_data->fixed) {200if (size - 1 != lmp_data->size) {201print_text(COLOR_ERROR, "invalid packet size");202packet_hexdump(data + off, size - off);203return;204}205} else {206if (size - 1 < lmp_data->size) {207print_text(COLOR_ERROR, "too short packet");208packet_hexdump(data + off, size - off);209return;210}211}212213lmp_data->func(data + off, size - off);214}215216217