Path: blob/main/usr.sbin/bluetooth/hccontrol/info.c
105240 views
/*-1* info.c2*3* SPDX-License-Identifier: BSD-2-Clause4*5* Copyright (c) 2001-2002 Maksim Yevmenkin <[email protected]>6* All rights reserved.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions10* are met:11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE21* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT25* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY26* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF27* SUCH DAMAGE.28*29* $Id: info.c,v 1.3 2003/08/18 19:19:54 max Exp $30*/3132#define L2CAP_SOCKET_CHECKED33#include <bluetooth.h>34#include <errno.h>35#include <stdio.h>36#include <string.h>37#include "hccontrol.h"3839/* Send Read_Local_Version_Information command to the unit */40static int41hci_read_local_version_information(int s, int argc, char **argv)42{43ng_hci_read_local_ver_rp rp;44int n;4546n = sizeof(rp);47if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,48NG_HCI_OCF_READ_LOCAL_VER), (char *) &rp, &n) == ERROR)49return (ERROR);5051if (rp.status != 0x00) {52fprintf(stdout, "Status: %s [%#02x]\n",53hci_status2str(rp.status), rp.status);54return (FAILED);55}5657rp.manufacturer = le16toh(rp.manufacturer);5859fprintf(stdout, "HCI version: %s [%#02x]\n",60hci_ver2str(rp.hci_version), rp.hci_version);61fprintf(stdout, "HCI revision: %#04x\n",62le16toh(rp.hci_revision));63fprintf(stdout, "LMP version: %s [%#02x]\n",64hci_lmpver2str(rp.lmp_version), rp.lmp_version);65fprintf(stdout, "LMP sub-version: %#04x\n",66le16toh(rp.lmp_subversion));67fprintf(stdout, "Manufacturer: %s [%#04x]\n",68hci_manufacturer2str(rp.manufacturer), rp.manufacturer);6970return (OK);71} /* hci_read_local_version_information */7273/* Send Read_Local_Supported_Commands command to the unit */74static int75hci_read_local_supported_commands(int s, int argc, char **argv)76{77ng_hci_read_local_commands_rp rp;78int n;79char buffer[16384];8081n = sizeof(rp);82if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,83NG_HCI_OCF_READ_LOCAL_COMMANDS),84(char *) &rp, &n) == ERROR)85return (ERROR);8687if (rp.status != 0x00) {88fprintf(stdout, "Status: %s [%#02x]\n",89hci_status2str(rp.status), rp.status);90return (FAILED);91}9293fprintf(stdout, "Supported commands:");94for (n = 0; n < sizeof(rp.features); n++) {95if (n % 8 == 0)96fprintf(stdout, "\n");97fprintf(stdout, "%#02x ", rp.features[n]);98}99fprintf(stdout, "\n%s\n", hci_commands2str(rp.features,100buffer, sizeof(buffer)));101102return (OK);103} /* hci_read_local_supported_commands */104105/* Send Read_Local_Supported_Features command to the unit */106static int107hci_read_local_supported_features(int s, int argc, char **argv)108{109ng_hci_read_local_features_rp rp;110int n;111char buffer[2048];112113n = sizeof(rp);114if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,115NG_HCI_OCF_READ_LOCAL_FEATURES),116(char *) &rp, &n) == ERROR)117return (ERROR);118119if (rp.status != 0x00) {120fprintf(stdout, "Status: %s [%#02x]\n",121hci_status2str(rp.status), rp.status);122return (FAILED);123}124125fprintf(stdout, "Features: ");126for (n = 0; n < sizeof(rp.features); n++)127fprintf(stdout, "%#02x ", rp.features[n]);128fprintf(stdout, "\n%s\n", hci_features2str(rp.features,129buffer, sizeof(buffer)));130131return (OK);132} /* hci_read_local_supported_features */133134/* Sent Read_Buffer_Size command to the unit */135static int136hci_read_buffer_size(int s, int argc, char **argv)137{138ng_hci_read_buffer_size_rp rp;139int n;140141n = sizeof(rp);142if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,143NG_HCI_OCF_READ_BUFFER_SIZE),144(char *) &rp, &n) == ERROR)145return (ERROR);146147if (rp.status != 0x00) {148fprintf(stdout, "Status: %s [%#02x]\n",149hci_status2str(rp.status), rp.status);150return (FAILED);151}152153fprintf(stdout, "Max. ACL packet size: %d bytes\n",154le16toh(rp.max_acl_size));155fprintf(stdout, "Number of ACL packets: %d\n",156le16toh(rp.num_acl_pkt));157fprintf(stdout, "Max. SCO packet size: %d bytes\n",158rp.max_sco_size);159fprintf(stdout, "Number of SCO packets: %d\n",160le16toh(rp.num_sco_pkt));161162return (OK);163} /* hci_read_buffer_size */164165/* Send Read_Country_Code command to the unit */166static int167hci_read_country_code(int s, int argc, char **argv)168{169ng_hci_read_country_code_rp rp;170int n;171172n = sizeof(rp);173if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,174NG_HCI_OCF_READ_COUNTRY_CODE),175(char *) &rp, &n) == ERROR)176return (ERROR);177178if (rp.status != 0x00) {179fprintf(stdout, "Status: %s [%#02x]\n",180hci_status2str(rp.status), rp.status);181return (FAILED);182}183184fprintf(stdout, "Country code: %s [%#02x]\n",185hci_cc2str(rp.country_code), rp.country_code);186187return (OK);188} /* hci_read_country_code */189190/* Send Read_BD_ADDR command to the unit */191static int192hci_read_bd_addr(int s, int argc, char **argv)193{194ng_hci_read_bdaddr_rp rp;195int n;196197n = sizeof(rp);198if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO,199NG_HCI_OCF_READ_BDADDR), (char *) &rp, &n) == ERROR)200return (ERROR);201202if (rp.status != 0x00) {203fprintf(stdout, "Status: %s [%#02x]\n",204hci_status2str(rp.status), rp.status);205return (FAILED);206}207208fprintf(stdout, "BD_ADDR: %s\n", bt_ntoa(&rp.bdaddr, NULL));209210return (OK);211} /* hci_read_bd_addr */212213struct hci_command info_commands[] = {214{215"read_local_version_information",216"\nThis command will read the values for the version information for the\n" \217"local Bluetooth unit.",218&hci_read_local_version_information219},220{221"read_local_supported_commands",222"\nThis command will read the commands the local Bluetooth unit supports.\n",223&hci_read_local_supported_commands224},225{226"read_local_supported_features",227"\nThis command requests a list of the supported features for the local\n" \228"unit. This command will return a list of the LMP features.",229&hci_read_local_supported_features230},231{232"read_buffer_size",233"\nThe Read_Buffer_Size command is used to read the maximum size of the\n" \234"data portion of HCI ACL and SCO Data Packets sent from the Host to the\n" \235"Host Controller.",236&hci_read_buffer_size237},238{239"read_country_code",240"\nThis command will read the value for the Country_Code return parameter.\n" \241"The Country_Code defines which range of frequency band of the ISM 2.4 GHz\n" \242"band will be used by the unit.",243&hci_read_country_code244},245{246"read_bd_addr",247"\nThis command will read the value for the BD_ADDR parameter. The BD_ADDR\n" \248"is a 48-bit unique identifier for a Bluetooth unit.",249&hci_read_bd_addr250},251{252NULL,253}};254255256257