View | Details | Raw Unified | Return to bug 246664 | Differences between
and this patch

Collapse All | Expand All

(-)usr.sbin/bluetooth/hccontrol/hccontrol.8 (+1 lines)
Lines 161-166 Link Here
161
.It Cm LE_Clear_White_List
161
.It Cm LE_Clear_White_List
162
.It Cm LE_Add_Device_To_White_List
162
.It Cm LE_Add_Device_To_White_List
163
.It Cm LE_Remove_Device_From_White_List
163
.It Cm LE_Remove_Device_From_White_List
164
.It Cm LE_Connect
164
.El
165
.El
165
.Pp
166
.Pp
166
The currently supported node commands in
167
The currently supported node commands in
(-)usr.sbin/bluetooth/hccontrol/hccontrol.h (+2 lines)
Lines 80-85 Link Here
80
char const *	hci_status2str      (int);
80
char const *	hci_status2str      (int);
81
char const *	hci_bdaddr2str      (bdaddr_t const *);
81
char const *	hci_bdaddr2str      (bdaddr_t const *);
82
char const * 	hci_addrtype2str    (int type);
82
char const * 	hci_addrtype2str    (int type);
83
char const *    hci_role2str        (int role);
84
char const *    hci_mc_accuracy2str (int accuracy);
83
85
84
void dump_adv_data(int len, uint8_t* advdata);
86
void dump_adv_data(int len, uint8_t* advdata);
85
void print_adv_data(int len, uint8_t* advdata);
87
void print_adv_data(int len, uint8_t* advdata);
(-)usr.sbin/bluetooth/hccontrol/le.c (+159 lines)
Lines 67-72 Link Here
67
static int le_clear_white_list(int s, int argc, char *argv[]);
67
static int le_clear_white_list(int s, int argc, char *argv[]);
68
static int le_add_device_to_white_list(int s, int argc, char *argv[]);
68
static int le_add_device_to_white_list(int s, int argc, char *argv[]);
69
static int le_remove_device_from_white_list(int s, int argc, char *argv[]);
69
static int le_remove_device_from_white_list(int s, int argc, char *argv[]);
70
static int le_connect(int s, int argc, char *argv[]);
71
static void handle_le_connection_event(ng_hci_event_pkt_t* e, bool verbose);
70
72
71
static int
73
static int
72
le_set_scan_param(int s, int argc, char *argv[])
74
le_set_scan_param(int s, int argc, char *argv[])
Lines 933-938 Link Here
933
	return (OK);
935
	return (OK);
934
}
936
}
935
937
938
static int
939
le_connect(int s, int argc, char *argv[])
940
{ 
941
	ng_hci_le_create_connection_cp cp;
942
	ng_hci_status_rp rp;
943
	char 			b[512];
944
	ng_hci_event_pkt_t	*e = (ng_hci_event_pkt_t *) b;
945
946
	int n, scancount, bufsize;
947
	char ch;
948
	bool addr_set = false;
949
	bool verbose = false;
950
951
	optreset = 1;
952
	optind = 0;
953
954
	/* minimal scan interval (2.5ms) */ 
955
	cp.scan_interval = htole16(4);
956
	cp.scan_window = htole16(4);
957
958
	/* Don't use the whitelist */
959
	cp.filter_policy = 0x00;
960
961
	/* Default to public peer address */
962
	cp.peer_addr_type = 0x00;
963
964
	/* Own address type public */
965
	cp.own_address_type = 0x00;
966
967
	/* 18.75ms min connection interval */
968
	cp.conn_interval_min = htole16(0x000F);
969
	/* 18.75ms max connection interval */
970
	cp.conn_interval_max = htole16(0x000F);
971
972
	/* 0 events connection latency */
973
	cp.conn_latency = htole16(0x0000);
974
975
	/* 32s supervision timeout */
976
	cp.supervision_timeout = htole16(0x0C80);
977
978
	/* Min CE Length 0.625 ms */
979
	cp.min_ce_length = htole16(1);
980
	/* Max CE Length 0.625 ms */
981
	cp.max_ce_length = htole16(1);
982
983
	while ((ch = getopt(argc, argv , "a:t:v")) != -1) {
984
		switch(ch) {
985
		case 't':
986
			if (strcmp(optarg, "public") == 0)
987
				cp.peer_addr_type = 0x00;
988
			else if (strcmp(optarg, "random") == 0)
989
				cp.peer_addr_type = 0x01;
990
			else 
991
				return (USAGE);
992
			break;
993
		case 'a':
994
			addr_set = true;
995
			if (!bt_aton(optarg, &cp.peer_addr)) {
996
				struct hostent	*he = NULL;
997
998
				if ((he = bt_gethostbyname(optarg)) == NULL)
999
					return (USAGE);
1000
1001
				memcpy(&cp.peer_addr, he->h_addr,
1002
					sizeof(cp.peer_addr));
1003
			}
1004
			break;
1005
		case 'v':
1006
			verbose = true;
1007
			break;
1008
		}
1009
	}
1010
1011
	if (addr_set == false) 
1012
		return (USAGE);
1013
1014
	n = sizeof(rp);
1015
	if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE,
1016
		NG_HCI_OCF_LE_CREATE_CONNECTION), 
1017
		(void *)&cp, sizeof(cp), (void *)&rp, &n) == ERROR)
1018
		return (ERROR);
1019
1020
	if (rp.status != 0x00) {
1021
		fprintf(stdout,
1022
			"Create connection failed. Status: %s [%#02x]\n", 
1023
			hci_status2str(rp.status), rp.status);
1024
		return (FAILED);
1025
	}
1026
1027
	scancount = 0;
1028
	while (scancount < 3) {
1029
		/* wait for connection events */
1030
		bufsize = sizeof(b);
1031
		if (hci_recv(s, b, &bufsize) == ERROR) {
1032
			return (ERROR);
1033
		}
1034
1035
		if (bufsize < sizeof(*e)) {
1036
			errno = EIO;
1037
			return (ERROR);
1038
		}
1039
		scancount++;
1040
		if (e->event == NG_HCI_EVENT_LE) {
1041
			handle_le_connection_event(e, verbose);
1042
			break;
1043
		}
1044
	}
1045
1046
	return (OK);
1047
}
1048
1049
static void handle_le_connection_event(ng_hci_event_pkt_t* e, bool verbose) 
1050
{
1051
	ng_hci_le_ep	*ev_pkt;
1052
	ng_hci_le_connection_complete_ep *conn_event;
1053
1054
	ev_pkt = (ng_hci_le_ep *)(e + 1);
1055
1056
	if (ev_pkt->subevent_code == NG_HCI_LEEV_CON_COMPL) {
1057
		conn_event =(ng_hci_le_connection_complete_ep *)(ev_pkt + 1);
1058
		fprintf(stdout, "Handle: %d\n", le16toh(conn_event->handle));
1059
		if (verbose) {
1060
			fprintf(stdout,
1061
				"Status: %s\n",
1062
				hci_status2str(conn_event->status));
1063
			fprintf(stdout,
1064
				"Role: %s\n",
1065
				hci_role2str(conn_event->role));
1066
			fprintf(stdout,
1067
				"Address Type: %s\n",
1068
				hci_addrtype2str(conn_event->address_type));
1069
			fprintf(stdout,
1070
				"Address: %s\n",
1071
				hci_bdaddr2str(&conn_event->address));
1072
			fprintf(stdout,
1073
				"Interval: %.2fms\n", 
1074
				6.25 * le16toh(conn_event->interval));
1075
			fprintf(stdout,
1076
				"Latency: %d events\n", conn_event->latency);
1077
			fprintf(stdout,
1078
				"Supervision timeout: %dms\n",
1079
				 10 * le16toh(conn_event->supervision_timeout));
1080
			fprintf(stdout,
1081
				"Master clock accuracy: %sn",
1082
				hci_mc_accuracy2str(
1083
					conn_event->master_clock_accuracy));
1084
		}
1085
	}
1086
	return;
1087
}
1088
936
struct hci_command le_commands[] = {
1089
struct hci_command le_commands[] = {
937
{
1090
{
938
	"le_enable",
1091
	"le_enable",
Lines 1037-1040 Link Here
1037
	  "Remove device from the white list",
1190
	  "Remove device from the white list",
1038
	  &le_remove_device_from_white_list
1191
	  &le_remove_device_from_white_list
1039
  },
1192
  },
1193
  {
1194
	  "le_connect",
1195
	  "le_connect -a address [-t public|random] [-v]\n"
1196
	  "Connect to an LE device",
1197
	  &le_connect
1198
  },
1040
};
1199
};
(-)usr.sbin/bluetooth/hccontrol/util.c (+27 lines)
Lines 3295-3297 Link Here
3295
	return (type >= SIZE(t)? "?" : t[type]);
3295
	return (type >= SIZE(t)? "?" : t[type]);
3296
} /* hci_addrtype2str */
3296
} /* hci_addrtype2str */
3297
3297
3298
char const *
3299
hci_role2str(int role)
3300
{
3301
	static char const * const	roles[] = {
3302
		/* 0x00 */ "Master",
3303
		/* 0x01 */ "Slave",
3304
	};
3305
3306
	return (role >= SIZE(roles)? "Unknown role" : roles[role]);
3307
} /* hci_role2str */
3308
3309
char const *
3310
hci_mc_accuracy2str(int accuracy)
3311
{
3312
	static char const * const	acc[] = {
3313
		/* 0x00 */ "500 ppm",
3314
		/* 0x01 */ "250 ppm",
3315
		/* 0x02 */ "150 ppm",
3316
		/* 0x03 */ "100 ppm",
3317
		/* 0x04 */ "75 ppm",
3318
		/* 0x05 */ "50 ppm",
3319
		/* 0x06 */ "30 ppm",
3320
		/* 0x07 */ "20 ppm",
3321
	};
3322
3323
	return (accuracy >= SIZE(acc)? "Unknown accuracy" : acc[accuracy]);
3324
} /* hci_mc_accuracy2str */

Return to bug 246664