Author: hselasky
Date: Sun Apr 19 14:22:21 2020
New Revision: 360094
URL: https://svnweb.freebsd.org/changeset/base/360094

Log:
  Improve printing of le features in hccontrol(8).
  
  Submitted by: Marc Veldman <m...@bumblingdork.com>
  PR:           245739
  MFC after:    1 week
  Sponsored by: Mellanox Technologies

Modified:
  head/usr.sbin/bluetooth/hccontrol/hccontrol.h
  head/usr.sbin/bluetooth/hccontrol/le.c
  head/usr.sbin/bluetooth/hccontrol/util.c

Modified: head/usr.sbin/bluetooth/hccontrol/hccontrol.h
==============================================================================
--- head/usr.sbin/bluetooth/hccontrol/hccontrol.h       Sun Apr 19 10:50:29 
2020        (r360093)
+++ head/usr.sbin/bluetooth/hccontrol/hccontrol.h       Sun Apr 19 14:22:21 
2020        (r360094)
@@ -73,6 +73,7 @@ char const *  hci_ver2str         (int);
 char const *   hci_lmpver2str      (int);
 char const *   hci_manufacturer2str(int);
 char const *   hci_features2str    (uint8_t *, char *, int);
+char const *   hci_le_features2str (uint8_t *, char *, int);
 char const *   hci_cc2str          (int);
 char const *   hci_con_state2str   (int);
 char const *   hci_status2str      (int);

Modified: head/usr.sbin/bluetooth/hccontrol/le.c
==============================================================================
--- head/usr.sbin/bluetooth/hccontrol/le.c      Sun Apr 19 10:50:29 2020        
(r360093)
+++ head/usr.sbin/bluetooth/hccontrol/le.c      Sun Apr 19 14:22:21 2020        
(r360094)
@@ -225,18 +225,37 @@ static int
 le_read_local_supported_features(int s, int argc ,char *argv[])
 {
        ng_hci_le_read_local_supported_features_rp rp;
-       int e;
        int n = sizeof(rp);
 
-       e = hci_simple_request(s,
+       union {
+               uint64_t raw;
+               uint8_t octets[8];
+       } le_features;
+
+       char buffer[2048];
+
+       if (hci_simple_request(s,
                        NG_HCI_OPCODE(NG_HCI_OGF_LE,
                        NG_HCI_OCF_LE_READ_LOCAL_SUPPORTED_FEATURES), 
-                       (void *)&rp, &n);
+                       (void *)&rp, &n) == ERROR)
+               return (ERROR);
 
-       printf("LOCAL SUPPORTED: %d %d %jx\n", e, rp.status,
-              (uintmax_t) rp.le_features);
+       if (rp.status != 0x00) {
+               fprintf(stdout, "Status: %s [%#02x]\n", 
+                       hci_status2str(rp.status), rp.status);
+               return (FAILED);
+       }
 
-       return 0;
+       le_features.raw = rp.le_features;
+
+       fprintf(stdout, "LE Features: ");
+       for(int i = 0; i < 8; i++)
+                fprintf(stdout, " %#02x", le_features.octets[i]);
+       fprintf(stdout, "\n%s\n", hci_le_features2str(le_features.octets, 
+               buffer, sizeof(buffer)));
+       fprintf(stdout, "\n");
+
+       return OK;
 }
 
 static int

Modified: head/usr.sbin/bluetooth/hccontrol/util.c
==============================================================================
--- head/usr.sbin/bluetooth/hccontrol/util.c    Sun Apr 19 10:50:29 2020        
(r360093)
+++ head/usr.sbin/bluetooth/hccontrol/util.c    Sun Apr 19 14:22:21 2020        
(r360094)
@@ -371,6 +371,119 @@ done:
 } /* hci_features2str */
 
 char const *
+hci_le_features2str(uint8_t *features, char *buffer, int size)
+{
+       static char const * const t[][8] = {
+       { /* byte 0 */
+               /* 0 */ "<LE Encryption> ",
+               /* 1 */ "<Connection Parameters Request Procedure> ",
+               /* 2 */ "<Extended Reject Indication> ",
+               /* 3 */ "<Slave-initiated Features Exchange> ",
+               /* 4 */ "<LE Ping> ",
+               /* 5 */ "<LE Data Packet Length Extension> ",
+               /* 6 */ "<LL Privacy> ",
+               /* 7 */ "<Extended Scanner Filter Policies> "
+       },
+       { /* byte 1 */
+               /* 0 */ "<LE 2M PHY> ",
+               /* 1 */ "<Stable Modulation Index - Transmitter> ",
+               /* 2 */ "<Stable Modulation Index - Receiver> ",
+               /* 3 */ "<LE Coded PHY> ",
+               /* 4 */ "<LE Extended Advertising> ",
+               /* 5 */ "<LE Periodic Advertising> ",
+               /* 6 */ "<Channel Selection Algorithm #2> ",
+               /* 7 */ "<LE Power Class 1> "
+       },
+       { /* byte 2 */
+               /* 0 */ "<Minimum Number of Used Channels Procedure> ",
+               /* 1 */ "<Connection CTE Request> ",
+               /* 2 */ "<Connection CTE Response> ",
+               /* 3 */ "<Connectionless CTE Transmitter> ",
+               /* 4 */ "<Connectionless CTE Receiver> ",
+               /* 5 */ "<Antenna Switching During CTE Transmission (AoD)> ",
+               /* 6 */ "<Antenna Switching During CTE Reception (AoA)> ",
+               /* 7 */ "<Receiving Constant Tone Extensions> "
+       },
+       { /* byte 3 */
+               /* 0 */ "<Periodic Advertising Sync Transfer - Sender> ",
+               /* 1 */ "<Periodic Advertising Sync Transfer - Recipient> ",
+               /* 2 */ "<Sleep Clock Accuracy Updates> ",
+               /* 3 */ "<Remote Public Key Validation> ",
+               /* 4 */ "<Connected Isochronous Stream - Master> ",
+               /* 5 */ "<Connected Isochronous Stream - Slave> ",
+               /* 6 */ "<Isochronous Broadcaster> ",
+               /* 7 */ "<Synchronized Receiver> "
+       },
+       { /* byte 4 */
+               /* 0 */ "<Isochronous Channels (Host Support)> ",
+               /* 1 */ "<LE Power Control Request> ",
+               /* 2 */ "<LE Power Change Indication> ",
+               /* 3 */ "<LE Path Loss Monitoring> ",
+               /* 4 */ "<Reserved for future use> ",
+               /* 5 */ "<Unknown 4.5> ",
+               /* 6 */ "<Unknown 4.6> ",
+               /* 7 */ "<Unknown 4.7> "
+       },
+       { /* byte 5 */
+               /* 0 */ "<Unknown 5.0> ",
+               /* 1 */ "<Unknown 5.1> ",
+               /* 2 */ "<Unknown 5.2> ",
+               /* 3 */ "<Unknown 5.3> ",
+               /* 4 */ "<Unknown 5.4> ",
+               /* 5 */ "<Unknown 5.5> ",
+               /* 6 */ "<Unknown 5.6> ",
+               /* 7 */ "<Unknown 5.7> "
+       },
+       { /* byte 6 */
+               /* 0 */ "<Unknown 6.0> ",
+               /* 1 */ "<Unknown 6.1> ",
+               /* 2 */ "<Unknown 6.2> ",
+               /* 3 */ "<Unknown 6.3> ",
+               /* 4 */ "<Unknown 6.4> ",
+               /* 5 */ "<Unknown 6.5> ",
+               /* 6 */ "<Unknown 6.6> ",
+               /* 7 */ "<Unknown 6.7> "
+       },
+       { /* byte 7 */
+               /* 0 */ "<Unknown 7.0> ",
+               /* 1 */ "<Unknown 7.1> ",
+               /* 2 */ "<Unknown 7.2> ",
+               /* 3 */ "<Unknown 7.3> ",
+               /* 4 */ "<Unknown 7.4> ",
+               /* 5 */ "<Unknown 7.5> ",
+               /* 6 */ "<Unknown 7.6> ",
+               /* 7 */ "<Unknown 7.7> "
+       }};
+
+       if (buffer != NULL && size > 0) {
+               int n, i, len0, len1;
+
+               memset(buffer, 0, size);
+               len1 = 0;
+
+               for (n = 0; n < SIZE(t); n++) {
+                       for (i = 0; i < SIZE(t[n]); i++) {
+                               len0 = strlen(buffer);
+                               if (len0 >= size)
+                                       goto done;
+
+                               if (features[n] & (1 << i)) {
+                                       if (len1 + strlen(t[n][i]) > 60) {
+                                               len1 = 0;
+                                               buffer[len0 - 1] = '\n';
+                                       }
+
+                                       len1 += strlen(t[n][i]);
+                                       strncat(buffer, t[n][i], size - len0);
+                               }
+                       }
+               }
+       }
+done:
+       return (buffer);
+}
+
+char const *
 hci_cc2str(int cc)
 {
        static char const * const       t[] = {
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to