Lines 762-767
Link Here
|
762 |
} |
762 |
} |
763 |
} |
763 |
} |
764 |
|
764 |
|
|
|
765 |
static int |
766 |
le_read_white_list_size(int s, int argc, char *argv[]) |
767 |
{ |
768 |
ng_hci_le_read_white_list_size_rp rp; |
769 |
int n; |
770 |
|
771 |
n = sizeof(rp); |
772 |
|
773 |
if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, |
774 |
NG_HCI_OCF_LE_READ_WHITE_LIST_SIZE), |
775 |
(void *)&rp, &n) == ERROR) |
776 |
return (ERROR); |
777 |
|
778 |
if (rp.status != 0x00) { |
779 |
fprintf(stdout, "Status: %s [%#02x]\n", |
780 |
hci_status2str(rp.status), rp.status); |
781 |
return (FAILED); |
782 |
} |
783 |
|
784 |
fprintf(stdout, "White list size: %d\n", |
785 |
(uint8_t)rp.white_list_size); |
786 |
|
787 |
return (OK); |
788 |
} |
789 |
|
790 |
static int |
791 |
le_clear_white_list(int s, int argc, char *argv[]) |
792 |
{ |
793 |
ng_hci_le_clear_white_list_rp rp; |
794 |
int n; |
795 |
|
796 |
n = sizeof(rp); |
797 |
|
798 |
if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, |
799 |
NG_HCI_OCF_LE_CLEAR_WHITE_LIST), |
800 |
(void *)&rp, &n) == ERROR) |
801 |
return (ERROR); |
802 |
|
803 |
if (rp.status != 0x00) { |
804 |
fprintf(stdout, "Status: %s [%#02x]\n", |
805 |
hci_status2str(rp.status), rp.status); |
806 |
return (FAILED); |
807 |
} |
808 |
|
809 |
fprintf(stdout, "White list cleared\n"); |
810 |
|
811 |
return (OK); |
812 |
} |
813 |
|
814 |
static int |
815 |
le_add_device_to_white_list(int s, int argc, char *argv[]) |
816 |
{ |
817 |
ng_hci_le_add_device_to_white_list_cp cp; |
818 |
ng_hci_le_add_device_to_white_list_rp rp; |
819 |
int n; |
820 |
char ch; |
821 |
optreset = 1; |
822 |
optind = 0; |
823 |
bool addr_set = false; |
824 |
|
825 |
n = sizeof(rp); |
826 |
|
827 |
cp.address_type = 0x00; |
828 |
|
829 |
while ((ch = getopt(argc, argv , "t:a:")) != -1) { |
830 |
switch(ch) { |
831 |
case 't': |
832 |
if (strcmp(optarg, "public") == 0) |
833 |
cp.address_type = 0x00; |
834 |
else if (strcmp(optarg, "random") == 0) |
835 |
cp.address_type = 0x01; |
836 |
else |
837 |
return (USAGE); |
838 |
break; |
839 |
case 'a': |
840 |
addr_set = true; |
841 |
if (!bt_aton(optarg, &cp.address)) { |
842 |
struct hostent *he = NULL; |
843 |
|
844 |
if ((he = bt_gethostbyname(optarg)) == NULL) |
845 |
return (USAGE); |
846 |
|
847 |
memcpy(&cp.address, he->h_addr, |
848 |
sizeof(cp.address)); |
849 |
} |
850 |
break; |
851 |
} |
852 |
} |
853 |
|
854 |
if (addr_set == false) |
855 |
return (USAGE); |
856 |
|
857 |
if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, |
858 |
NG_HCI_OCF_LE_ADD_DEVICE_TO_WHITE_LIST), |
859 |
(void *)&cp, sizeof(cp), (void *)&rp, &n) == ERROR) |
860 |
return (ERROR); |
861 |
|
862 |
if (rp.status != 0x00) { |
863 |
fprintf(stdout, "Status: %s [%#02x]\n", |
864 |
hci_status2str(rp.status), rp.status); |
865 |
return (FAILED); |
866 |
} |
867 |
|
868 |
fprintf(stdout, "Address added to white list\n"); |
869 |
|
870 |
return (OK); |
871 |
} |
872 |
|
873 |
static int |
874 |
le_remove_device_from_white_list(int s, int argc, char *argv[]) |
875 |
{ |
876 |
ng_hci_le_remove_device_from_white_list_cp cp; |
877 |
ng_hci_le_remove_device_from_white_list_rp rp; |
878 |
int n; |
879 |
char ch; |
880 |
optreset = 1; |
881 |
optind = 0; |
882 |
bool addr_set = false; |
883 |
|
884 |
n = sizeof(rp); |
885 |
|
886 |
cp.address_type = 0x00; |
887 |
bt_aton("00:00:00:00:00:00", &cp.address); |
888 |
|
889 |
while ((ch = getopt(argc, argv , "t:a:")) != -1) { |
890 |
switch(ch) { |
891 |
case 't': |
892 |
if (strcmp(optarg, "public") == 0) |
893 |
cp.address_type = 0x00; |
894 |
else if (strcmp(optarg, "random") == 0) |
895 |
cp.address_type = 0x01; |
896 |
else |
897 |
return (USAGE); |
898 |
break; |
899 |
case 'a': |
900 |
addr_set = true; |
901 |
if (!bt_aton(optarg, &cp.address)) { |
902 |
struct hostent *he = NULL; |
903 |
|
904 |
if ((he = bt_gethostbyname(optarg)) == NULL) |
905 |
return (USAGE); |
906 |
|
907 |
memcpy(&cp.address, he->h_addr, |
908 |
sizeof(cp.address)); |
909 |
} |
910 |
break; |
911 |
} |
912 |
} |
913 |
|
914 |
if (addr_set == false) |
915 |
return (USAGE); |
916 |
|
917 |
if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE, |
918 |
NG_HCI_OCF_LE_ADD_DEVICE_TO_WHITE_LIST), |
919 |
(void *)&cp, sizeof(cp), (void *)&rp, &n) == ERROR) |
920 |
return (ERROR); |
921 |
|
922 |
if (rp.status != 0x00) { |
923 |
fprintf(stdout, "Status: %s [%#02x]\n", |
924 |
hci_status2str(rp.status), rp.status); |
925 |
return (FAILED); |
926 |
} |
927 |
|
928 |
fprintf(stdout, "Address removed from white list\n"); |
929 |
|
930 |
return (OK); |
931 |
} |
932 |
|
765 |
struct hci_command le_commands[] = { |
933 |
struct hci_command le_commands[] = { |
766 |
{ |
934 |
{ |
767 |
"le_enable", |
935 |
"le_enable", |
Lines 840-843
Link Here
|
840 |
"Do an LE scan", |
1008 |
"Do an LE scan", |
841 |
&le_scan |
1009 |
&le_scan |
842 |
}, |
1010 |
}, |
|
|
1011 |
{ |
1012 |
"le_read_white_list_size", |
1013 |
"le_read_white_list_size\n" |
1014 |
"Read total number of white list entries that can be stored", |
1015 |
&le_read_white_list_size |
1016 |
}, |
1017 |
{ |
1018 |
"le_clear_white_list", |
1019 |
"le_clear_white_list\n" |
1020 |
"Clear the white list in the controller", |
1021 |
&le_clear_white_list |
1022 |
}, |
1023 |
{ |
1024 |
"le_add_device_to_white_list", |
1025 |
"le_add_device_to_white_list\n" |
1026 |
"[-t public|random] -a address\n" |
1027 |
"Add device to the white list", |
1028 |
&le_add_device_to_white_list |
1029 |
}, |
1030 |
{ |
1031 |
"le_remove_device_from_white_list", |
1032 |
"le_remove_device_from_white_list\n" |
1033 |
"[-t public|random] -a address\n" |
1034 |
"Remove device from the white list", |
1035 |
&le_remove_device_from_white_list |
1036 |
}, |
843 |
}; |
1037 |
}; |