From owner-svn-src-head@freebsd.org Tue May 19 13:44:33 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 469DB2CFD48; Tue, 19 May 2020 13:44:33 +0000 (UTC) (envelope-from takawata@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49RHDd1F7bz4XK6; Tue, 19 May 2020 13:44:33 +0000 (UTC) (envelope-from takawata@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 25FB7BD06; Tue, 19 May 2020 13:44:33 +0000 (UTC) (envelope-from takawata@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 04JDiXAS015695; Tue, 19 May 2020 13:44:33 GMT (envelope-from takawata@FreeBSD.org) Received: (from takawata@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04JDiWF2015694; Tue, 19 May 2020 13:44:32 GMT (envelope-from takawata@FreeBSD.org) Message-Id: <202005191344.04JDiWF2015694@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: takawata set sender to takawata@FreeBSD.org using -f From: Takanori Watanabe Date: Tue, 19 May 2020 13:44:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r361251 - head/usr.sbin/bluetooth/hccontrol X-SVN-Group: head X-SVN-Commit-Author: takawata X-SVN-Commit-Paths: head/usr.sbin/bluetooth/hccontrol X-SVN-Commit-Revision: 361251 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 May 2020 13:44:33 -0000 Author: takawata Date: Tue May 19 13:44:32 2020 New Revision: 361251 URL: https://svnweb.freebsd.org/changeset/base/361251 Log: Add LE Whitelist commands to hccontrol PR: 214555 Submitted by Marc Veldman Modified: head/usr.sbin/bluetooth/hccontrol/hccontrol.8 head/usr.sbin/bluetooth/hccontrol/le.c Modified: head/usr.sbin/bluetooth/hccontrol/hccontrol.8 ============================================================================== --- head/usr.sbin/bluetooth/hccontrol/hccontrol.8 Tue May 19 12:16:44 2020 (r361250) +++ head/usr.sbin/bluetooth/hccontrol/hccontrol.8 Tue May 19 13:44:32 2020 (r361251) @@ -157,6 +157,10 @@ are: .It Cm LE_Read_Supported_States .It Cm LE_Read_Buffer_Size .It Cm LE Scan +.It Cm LE_Read_White_List_Size +.It Cm LE_Clear_White_List +.It Cm LE_Add_Device_To_White_List +.It Cm LE_Remove_Device_From_White_List .El .Pp The currently supported node commands in Modified: head/usr.sbin/bluetooth/hccontrol/le.c ============================================================================== --- head/usr.sbin/bluetooth/hccontrol/le.c Tue May 19 12:16:44 2020 (r361250) +++ head/usr.sbin/bluetooth/hccontrol/le.c Tue May 19 13:44:32 2020 (r361251) @@ -63,6 +63,10 @@ static int le_set_advertising_param(int s, int argc, c static int le_read_advertising_channel_tx_power(int s, int argc, char *argv[]); static int le_scan(int s, int argc, char *argv[]); static void handle_le_event(ng_hci_event_pkt_t* e, bool verbose); +static int le_read_white_list_size(int s, int argc, char *argv[]); +static int le_clear_white_list(int s, int argc, char *argv[]); +static int le_add_device_to_white_list(int s, int argc, char *argv[]); +static int le_remove_device_from_white_list(int s, int argc, char *argv[]); static int le_set_scan_param(int s, int argc, char *argv[]) @@ -762,6 +766,173 @@ static void handle_le_event(ng_hci_event_pkt_t* e, boo } } +static int +le_read_white_list_size(int s, int argc, char *argv[]) +{ + ng_hci_le_read_white_list_size_rp rp; + int n; + + n = sizeof(rp); + + if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, + NG_HCI_OCF_LE_READ_WHITE_LIST_SIZE), + (void *)&rp, &n) == ERROR) + return (ERROR); + + if (rp.status != 0x00) { + fprintf(stdout, "Status: %s [%#02x]\n", + hci_status2str(rp.status), rp.status); + return (FAILED); + } + + fprintf(stdout, "White list size: %d\n", + (uint8_t)rp.white_list_size); + + return (OK); +} + +static int +le_clear_white_list(int s, int argc, char *argv[]) +{ + ng_hci_le_clear_white_list_rp rp; + int n; + + n = sizeof(rp); + + if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, + NG_HCI_OCF_LE_CLEAR_WHITE_LIST), + (void *)&rp, &n) == ERROR) + return (ERROR); + + if (rp.status != 0x00) { + fprintf(stdout, "Status: %s [%#02x]\n", + hci_status2str(rp.status), rp.status); + return (FAILED); + } + + fprintf(stdout, "White list cleared\n"); + + return (OK); +} + +static int +le_add_device_to_white_list(int s, int argc, char *argv[]) +{ + ng_hci_le_add_device_to_white_list_cp cp; + ng_hci_le_add_device_to_white_list_rp rp; + int n; + char ch; + optreset = 1; + optind = 0; + bool addr_set = false; + + n = sizeof(rp); + + cp.address_type = 0x00; + + while ((ch = getopt(argc, argv , "t:a:")) != -1) { + switch(ch) { + case 't': + if (strcmp(optarg, "public") == 0) + cp.address_type = 0x00; + else if (strcmp(optarg, "random") == 0) + cp.address_type = 0x01; + else + return (USAGE); + break; + case 'a': + addr_set = true; + if (!bt_aton(optarg, &cp.address)) { + struct hostent *he = NULL; + + if ((he = bt_gethostbyname(optarg)) == NULL) + return (USAGE); + + memcpy(&cp.address, he->h_addr, + sizeof(cp.address)); + } + break; + } + } + + if (addr_set == false) + return (USAGE); + + if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, + NG_HCI_OCF_LE_ADD_DEVICE_TO_WHITE_LIST), + (void *)&cp, sizeof(cp), (void *)&rp, &n) == ERROR) + return (ERROR); + + if (rp.status != 0x00) { + fprintf(stdout, "Status: %s [%#02x]\n", + hci_status2str(rp.status), rp.status); + return (FAILED); + } + + fprintf(stdout, "Address added to white list\n"); + + return (OK); +} + +static int +le_remove_device_from_white_list(int s, int argc, char *argv[]) +{ + ng_hci_le_remove_device_from_white_list_cp cp; + ng_hci_le_remove_device_from_white_list_rp rp; + int n; + char ch; + optreset = 1; + optind = 0; + bool addr_set = false; + + n = sizeof(rp); + + cp.address_type = 0x00; + + while ((ch = getopt(argc, argv , "t:a:")) != -1) { + switch(ch) { + case 't': + if (strcmp(optarg, "public") == 0) + cp.address_type = 0x00; + else if (strcmp(optarg, "random") == 0) + cp.address_type = 0x01; + else + return (USAGE); + break; + case 'a': + addr_set = true; + if (!bt_aton(optarg, &cp.address)) { + struct hostent *he = NULL; + + if ((he = bt_gethostbyname(optarg)) == NULL) + return (USAGE); + + memcpy(&cp.address, he->h_addr, + sizeof(cp.address)); + } + break; + } + } + + if (addr_set == false) + return (USAGE); + + if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, + NG_HCI_OCF_LE_ADD_DEVICE_TO_WHITE_LIST), + (void *)&cp, sizeof(cp), (void *)&rp, &n) == ERROR) + return (ERROR); + + if (rp.status != 0x00) { + fprintf(stdout, "Status: %s [%#02x]\n", + hci_status2str(rp.status), rp.status); + return (FAILED); + } + + fprintf(stdout, "Address removed from white list\n"); + + return (OK); +} + struct hci_command le_commands[] = { { "le_enable", @@ -839,5 +1010,31 @@ struct hci_command le_commands[] = { "le_scan [-a] [-v] [-n number_of_scans]\n" "Do an LE scan", &le_scan + }, + { + "le_read_white_list_size", + "le_read_white_list_size\n" + "Read total number of white list entries that can be stored", + &le_read_white_list_size + }, + { + "le_clear_white_list", + "le_clear_white_list\n" + "Clear the white list in the controller", + &le_clear_white_list + }, + { + "le_add_device_to_white_list", + "le_add_device_to_white_list\n" + "[-t public|random] -a address\n" + "Add device to the white list", + &le_add_device_to_white_list + }, + { + "le_remove_device_from_white_list", + "le_remove_device_from_white_list\n" + "[-t public|random] -a address\n" + "Remove device from the white list", + &le_remove_device_from_white_list }, };