View | Details | Raw Unified | Return to bug 245848
Collapse All | Expand All

(-)usr.sbin/bluetooth/hccontrol/hccontrol.8 (+11 lines)
Lines 133-138 Link Here
133
.It Cm Write_Page_Scan_Period_Mode
133
.It Cm Write_Page_Scan_Period_Mode
134
.It Cm Read_Page_Scan_Mode
134
.It Cm Read_Page_Scan_Mode
135
.It Cm Write_Page_Scan_Mode
135
.It Cm Write_Page_Scan_Mode
136
.It Cm Read_LE_Host_Support
137
.It Cm Write_LE_Host_Support
136
.It Cm Read_Local_Version_Information
138
.It Cm Read_Local_Version_Information
137
.It Cm Read_Local_Supported_Commands
139
.It Cm Read_Local_Supported_Commands
138
.It Cm Read_Local_Supported_Features
140
.It Cm Read_Local_Supported_Features
Lines 143-148 Link Here
143
.It Cm Reset_Failed_Contact_Counter
145
.It Cm Reset_Failed_Contact_Counter
144
.It Cm Get_Link_Quality
146
.It Cm Get_Link_Quality
145
.It Cm Read_RSSI
147
.It Cm Read_RSSI
148
.It Cm LE_Read_Local_Supported_Features
149
.It Cm LE_Set_Advertising_Parameters 
150
.It Cm LE_Read_Advertising_Physical_Channel_Tx_Power 
151
.It Cm LE_Set_Advertising_Data
152
.It Cm LE_Set_Scan_Response_Data
153
.It Cm LE_Set_Advertising_Enable
154
.It Cm LE_Set_Scan_Parameters
155
.It Cm LE_Set_Scan_Enable
156
.It Cm LE_Read_Supported_States
146
.El
157
.El
147
.Pp
158
.Pp
148
The currently supported node commands in
159
The currently supported node commands in
(-)usr.sbin/bluetooth/hccontrol/le.c (+194 lines)
Lines 57-62 Link Here
57
static int set_le_event_mask(int s, uint64_t mask);
57
static int set_le_event_mask(int s, uint64_t mask);
58
static int set_event_mask(int s, uint64_t mask);
58
static int set_event_mask(int s, uint64_t mask);
59
static int le_enable(int s, int argc, char *argv[]);
59
static int le_enable(int s, int argc, char *argv[]);
60
static int le_set_advertising_enable(int s, int argc, char *argv[]);
61
static int le_set_advertising_param(int s, int argc, char *argv[]);
62
static int le_read_advertising_channel_tx_power(int s, int argc, char *argv[]);
60
63
61
static int
64
static int
62
le_set_scan_param(int s, int argc, char *argv[])
65
le_set_scan_param(int s, int argc, char *argv[])
Lines 339-344 Link Here
339
	return OK;
342
	return OK;
340
}
343
}
341
344
345
static int
346
le_set_advertising_enable(int s, int argc, char *argv[])
347
{
348
	ng_hci_le_set_advertise_enable_cp cp;
349
	ng_hci_le_set_advertise_enable_rp rp;
350
	int n, enable = 0;
351
352
	if (argc != 1)
353
		return USAGE;
354
	  
355
	if (strcmp(argv[0], "enable") == 0)
356
		enable = 1;
357
	else if (strcmp(argv[0], "disable") != 0)
358
		return USAGE;
359
360
	n = sizeof(rp);
361
	cp.advertising_enable = enable;
362
	if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE,
363
		NG_HCI_OCF_LE_SET_ADVERTISE_ENABLE), 
364
		(void *)&cp, sizeof(cp), (void *)&rp, &n) == ERROR)
365
		return (ERROR);
366
			
367
	if (rp.status != 0x00) {
368
		fprintf(stdout, "Status: %s [%#02x]\n", 
369
			hci_status2str(rp.status), rp.status);
370
		return (FAILED);
371
	}
372
        fprintf(stdout, "LE Advertising %s\n", (enable ? "enabled" : "disabled"));
373
374
	return (OK);
375
}
376
377
static int
378
le_set_advertising_param(int s, int argc, char *argv[])
379
{
380
	ng_hci_le_set_advertising_parameters_cp cp;
381
	ng_hci_le_set_advertising_parameters_rp rp;
382
383
	int n, ch;
384
385
	cp.advertising_interval_min = 0x800;
386
	cp.advertising_interval_max = 0x800;
387
	cp.advertising_type = 0;
388
	cp.own_address_type = 0;
389
	cp.direct_address_type = 0;
390
391
	cp.advertising_channel_map = 7;
392
	cp.advertising_filter_policy = 0;
393
394
	optreset = 1;
395
	optind = 0;
396
	while ((ch = getopt(argc, argv , "m:M:t:o:p:a:c:f:")) != -1) {
397
		switch(ch){
398
		case 'm':
399
			cp.advertising_interval_min =
400
				(uint16_t)(strtod(optarg, NULL)/0.625);
401
			break;
402
		case 'M':
403
			cp.advertising_interval_max =
404
				(uint16_t)(strtod(optarg, NULL)/0.625);
405
			break;
406
		case 't':
407
			cp.advertising_type =
408
				(uint8_t)strtod(optarg, NULL);
409
			break;
410
		case 'o':
411
			cp.own_address_type =
412
				(uint8_t)strtod(optarg, NULL);
413
			break;
414
		case 'p':
415
			cp.direct_address_type =
416
				(uint8_t)strtod(optarg, NULL);
417
			break;
418
		case 'a':
419
			if (!bt_aton(optarg, &cp.direct_address)) {
420
				struct hostent	*he = NULL;
421
422
				if ((he = bt_gethostbyname(optarg)) == NULL)
423
					return (USAGE);
424
425
				memcpy(&cp.direct_address, he->h_addr, sizeof(cp.direct_address));
426
			}
427
			break;
428
		case 'c':
429
			cp.advertising_channel_map =
430
				(uint8_t)strtod(optarg, NULL);
431
			break;
432
		case 'f':
433
			cp.advertising_filter_policy =
434
				(uint8_t)strtod(optarg, NULL);
435
			break;
436
		}
437
	}
438
439
	n = sizeof(rp);
440
	if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE,
441
		NG_HCI_OCF_LE_SET_ADVERTISING_PARAMETERS), 
442
		(void *)&cp, sizeof(cp), (void *)&rp, &n) == ERROR)
443
		return (ERROR);
444
			
445
	if (rp.status != 0x00) {
446
		fprintf(stdout, "Status: %s [%#02x]\n", 
447
			hci_status2str(rp.status), rp.status);
448
		return (FAILED);
449
	}
450
451
	return (OK);
452
}
453
454
static int
455
le_read_advertising_channel_tx_power(int s, int argc, char *argv[])
456
{
457
	ng_hci_le_read_advertising_channel_tx_power_rp rp;
458
	int n;
459
460
	n = sizeof(rp);
461
462
	if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE,
463
		NG_HCI_OCF_LE_READ_ADVERTISING_CHANNEL_TX_POWER), 
464
		(void *)&rp, &n) == ERROR)
465
		return (ERROR);
466
			
467
	if (rp.status != 0x00) {
468
		fprintf(stdout, "Status: %s [%#02x]\n", 
469
			hci_status2str(rp.status), rp.status);
470
		return (FAILED);
471
	}
472
473
        fprintf(stdout, "Advertising transmit power level: %d dBm\n",
474
		(int8_t)rp.transmit_power_level);
475
476
	return (OK);
477
}
478
479
static int
480
le_set_advertising_data(int s, int argc, char *argv[])
481
{
482
	ng_hci_le_set_advertising_data_cp cp;
483
	ng_hci_le_set_advertising_data_rp rp;
484
	int n, len;
485
486
	n = sizeof(rp);
487
488
	char buf[NG_HCI_ADVERTISING_DATA_SIZE];
489
490
	len = sizeof(buf);
491
	parse_param(argc, argv, buf, &len);
492
	memset(cp.advertising_data, 0, sizeof(cp.advertising_data));
493
	cp.advertising_data_length = len;
494
495
	if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LE,
496
		NG_HCI_OCF_LE_SET_ADVERTISING_DATA), 
497
		(void *)&cp, sizeof(cp), (void *)&rp, &n) == ERROR)
498
		return (ERROR);
499
			
500
	if (rp.status != 0x00) {
501
		fprintf(stdout, "Status: %s [%#02x]\n", 
502
			hci_status2str(rp.status), rp.status);
503
		return (FAILED);
504
	}
505
506
	return (OK);
507
}
508
342
struct hci_command le_commands[] = {
509
struct hci_command le_commands[] = {
343
{
510
{
344
	"le_enable",
511
	"le_enable",
Lines 378-381 Link Here
378
	  "set LE device scan parameter",
545
	  "set LE device scan parameter",
379
	  &le_set_scan_param
546
	  &le_set_scan_param
380
  },
547
  },
548
  {
549
	  "le_set_advertising_enable",
550
	  "le_set_advertising_enable [enable|disable] \n"
551
	  "Start or stop advertising",
552
	  &le_set_advertising_enable
553
  },
554
  {
555
	  "le_read_advertising_channel_tx_power",
556
	  "le_read_advertising_channel_tx_power\n"
557
	  "Read host advertising transmit poser level (dBm)",
558
	  &le_read_advertising_channel_tx_power
559
  },
560
  {
561
	  "le_set_advertising_param",
562
	  "le_set_advertising_param  [-m min_interval(ms)] [- M max_interval(ms)]\n"
563
	  "[-t advertising_type] [-o own_address_type] [-p peer_address_type]\n"
564
	  "[-c advertising_channel_map] [-f advertising_filter_policy]\n"
565
	  "[-a peer_address]\n"
566
	  "set LE device advertising parameters",
567
	  &le_set_advertising_param
568
  },
569
  {
570
	  "le_set_advertising_data",
571
	  "le_set_advertising_data -n $name -f $flag -u $uuid16,$uuid16 \n"
572
	  "set LE device advertising packed data",
573
	  &le_set_advertising_data
574
  },
381
};
575
};

Return to bug 245848