xref: /haiku/src/kits/bluetooth/CommandManager.cpp (revision 7749d0bb0c358a3279b1b9cc76d8376e900130a5)
1 /*
2  * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3  * Copyright 2008 Mika Lindqvist
4  * All rights reserved. Distributed under the terms of the MIT License.
5  */
6 
7 #include "CommandManager.h"
8 
9 
10 #include <bluetooth/bluetooth_error.h>
11 
12 inline void* buildCommand(uint8 ogf, uint8 ocf, void** param, size_t psize,
13 	size_t* outsize)
14 {
15 	struct hci_command_header* header;
16 
17 #ifdef BT_IOCTLS_PASS_SIZE
18 	header = (struct hci_command_header*) malloc(psize
19 		+ sizeof(struct hci_command_header));
20 	*outsize = psize + sizeof(struct hci_command_header);
21 #else
22 	size_t* size = (size_t*)malloc(psize + sizeof(struct hci_command_header)
23 		+ sizeof(size_t));
24 	*outsize = psize + sizeof(struct hci_command_header) + sizeof(size_t);
25 
26 	*size = psize + sizeof(struct hci_command_header);
27 	header = (struct hci_command_header*) (((uint8*)size)+4);
28 #endif
29 
30 
31 	if (header != NULL) {
32 
33 		header->opcode = B_HOST_TO_LENDIAN_INT16(PACK_OPCODE(ogf, ocf));
34 		header->clen = psize;
35 
36 		if (param != NULL && psize != 0) {
37 			*param = ((uint8*)header) + sizeof(struct hci_command_header);
38 		}
39 	}
40 #ifdef BT_IOCTLS_PASS_SIZE
41 	return header;
42 #else
43 	return (void*)size;
44 #endif
45 }
46 
47 
48 // This is for request that only require a Command complete in reply.
49 
50 // Propagate to ReadBufferSize => reply stored in server side
51 // ReadLocalVersion => reply stored in server side
52 // Reset => no reply
53 
54 // Request that do not need any input parameter
55 // Output reply can be fit in 32 bits field without talking status into account
56 status_t
57 NonParameterCommandRequest(uint8 ofg, uint8 ocf, int32* result, hci_id hId,
58 	BMessenger* messenger)
59 {
60 	int8 bt_status = BT_ERROR;
61 
62 	BluetoothCommand<> simpleCommand(ofg, ocf);
63 
64 	BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
65 	BMessage reply;
66 
67 	request.AddInt32("hci_id", hId);
68 	request.AddData("raw command", B_ANY_TYPE,
69 		simpleCommand.Data(), simpleCommand.Size());
70 	request.AddInt16("eventExpected",  HCI_EVENT_CMD_COMPLETE);
71 	request.AddInt16("opcodeExpected", PACK_OPCODE(ofg, ocf));
72 
73 	if (messenger->SendMessage(&request, &reply) == B_OK) {
74 		reply.FindInt8("status", &bt_status);
75 		if (result != NULL)
76 			reply.FindInt32("result", result);
77 	}
78 
79 	return bt_status;
80 }
81 
82 
83 #if 0
84 #pragma mark - CONTROL BASEBAND -
85 #endif
86 
87 
88 void* buildReset(size_t* outsize)
89 {
90 	return buildCommand(OGF_CONTROL_BASEBAND, OCF_RESET,
91 		NULL, 0, outsize);
92 }
93 
94 
95 void* buildReadLocalName(size_t* outsize)
96 {
97 	return buildCommand(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME,
98 		NULL, 0, outsize);
99 }
100 
101 
102 void* buildReadClassOfDevice(size_t* outsize)
103 {
104 	return buildCommand(OGF_CONTROL_BASEBAND, OCF_READ_CLASS_OF_DEV,
105 	NULL, 0, outsize);
106 }
107 
108 
109 void* buildWriteScan(uint8 scanmode, size_t* outsize)
110 {
111 	struct hci_write_scan_enable* param;
112 	void* command = buildCommand(OGF_CONTROL_BASEBAND, OCF_WRITE_SCAN_ENABLE,
113 		(void**) &param, sizeof(struct hci_write_scan_enable), outsize);
114 
115 
116 	if (command != NULL) {
117 		param->scan = scanmode;
118 	}
119 
120 	return command;
121 
122 }
123 
124 
125 #if 0
126 #pragma mark - LINK CONTROL -
127 #endif
128 
129 
130 void* buildRemoteNameRequest(bdaddr_t bdaddr, uint8 pscan_rep_mode,
131 	uint16 clock_offset, size_t* outsize)
132 {
133 
134 	struct hci_remote_name_request* param;
135 	void* command = buildCommand(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST,
136 		(void**)&param, sizeof(struct hci_remote_name_request), outsize);
137 
138 	if (command != NULL) {
139 		param->bdaddr = bdaddr;
140 		param->pscan_rep_mode = pscan_rep_mode;
141 		param->clock_offset = clock_offset;
142 	}
143 
144 	return command;
145 }
146 
147 
148 void* buildInquiry(uint32 lap, uint8 length, uint8 num_rsp, size_t* outsize)
149 {
150 
151 	struct hci_cp_inquiry* param;
152 	void* command = buildCommand(OGF_LINK_CONTROL, OCF_INQUIRY,
153 		(void**) &param, sizeof(struct hci_cp_inquiry), outsize);
154 
155 	if (command != NULL) {
156 
157 		param->lap[2] = (lap >> 16) & 0xFF;
158 		param->lap[1] = (lap >>  8) & 0xFF;
159 		param->lap[0] = (lap >>  0) & 0xFF;
160 		param->length = length;
161 		param->num_rsp = num_rsp;
162 	}
163 
164 	return command;
165 }
166 
167 
168 void* buildInquiryCancel(size_t* outsize)
169 {
170 
171 	return buildCommand(OGF_LINK_CONTROL, OCF_INQUIRY_CANCEL, NULL, 0, outsize);
172 
173 }
174 
175 
176 void* buildPinCodeRequestReply(bdaddr_t bdaddr, uint8 length, char pincode[16],
177 	size_t* outsize)
178 {
179 	struct hci_cp_pin_code_reply* param;
180 
181 	if (length > HCI_PIN_SIZE)  // PinCode cannot be longer than 16
182 		return NULL;
183 
184 	void* command = buildCommand(OGF_LINK_CONTROL, OCF_PIN_CODE_REPLY,
185 		(void**)&param, sizeof(struct hci_cp_pin_code_reply), outsize);
186 
187 	if (command != NULL) {
188 		param->bdaddr = bdaddr;
189 		param->pin_len = length;
190 		memcpy(&param->pin_code, pincode, length);
191 	}
192 
193 	return command;
194 }
195 
196 
197 void* buildPinCodeRequestNegativeReply(bdaddr_t bdaddr, size_t* outsize)
198 {
199 
200 	struct hci_cp_pin_code_neg_reply* param;
201 
202 	void* command = buildCommand(OGF_LINK_CONTROL, OCF_PIN_CODE_NEG_REPLY,
203 		(void**) &param, sizeof(struct hci_cp_pin_code_neg_reply), outsize);
204 
205 	if (command != NULL) {
206 
207 		param->bdaddr = bdaddr;
208 
209 	}
210 
211 	return command;
212 }
213 
214 
215 void* buildAcceptConnectionRequest(bdaddr_t bdaddr, uint8 role, size_t* outsize)
216 {
217 	struct hci_cp_accept_conn_req* param;
218 
219 	void* command = buildCommand(OGF_LINK_CONTROL, OCF_ACCEPT_CONN_REQ,
220 					(void**) &param, sizeof(struct hci_cp_accept_conn_req), outsize);
221 
222 	if (command != NULL) {
223 		param->bdaddr = bdaddr;
224 		param->role = role;
225 	}
226 
227 	return command;
228 }
229 
230 
231 void* buildRejectConnectionRequest(bdaddr_t bdaddr, size_t* outsize)
232 {
233 	struct hci_cp_reject_conn_req* param;
234 
235 	void* command = buildCommand(OGF_LINK_CONTROL, OCF_REJECT_CONN_REQ,
236 					(void**)&param, sizeof(struct hci_cp_reject_conn_req),
237 					outsize);
238 
239 	if (command != NULL) {
240 		param->bdaddr = bdaddr;
241 	}
242 
243 	return command;
244 }
245 
246 
247 #if 0
248 #pragma mark - INFORMATIONAL_PARAM -
249 #endif
250 
251 void* buildReadLocalVersionInformation(size_t* outsize)
252 {
253 	return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_VERSION,
254 		NULL, 0, outsize);
255 }
256 
257 
258 void* buildReadBufferSize(size_t* outsize)
259 {
260 	return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_BUFFER_SIZE,
261 		NULL, 0, outsize);
262 }
263 
264 
265 void* buildReadBdAddr(size_t* outsize)
266 {
267 	return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR,
268 		NULL, 0, outsize);
269 }
270 
271 
272 const char* bluetoothManufacturers[] = {
273 	"Ericsson Technology Licensing",
274 	"Nokia Mobile Phones",
275 	"Intel Corp.",
276 	"IBM Corp.",
277 	"Toshiba Corp.",
278 	"3Com",
279 	"Microsoft",
280 	"Lucent",
281 	"Motorola",
282 	"Infineon Technologies AG",
283 	"Cambridge Silicon Radio",
284 	"Silicon Wave",
285 	"Digianswer A/S",
286 	"Texas Instruments Inc.",
287 	"Parthus Technologies Inc.",
288 	"Broadcom Corporation",
289 	"Mitel Semiconductor",
290 	"Widcomm, Inc.",
291 	"Zeevo, Inc.",
292 	"Atmel Corporation",
293 	"Mitsubishi Electric Corporation",
294 	"RTX Telecom A/S",
295 	"KC Technology Inc.",
296 	"Newlogic",
297 	"Transilica, Inc.",
298 	"Rohde & Schwartz GmbH & Co. KG",
299 	"TTPCom Limited",
300 	"Signia Technologies, Inc.",
301 	"Conexant Systems Inc.",
302 	"Qualcomm",
303 	"Inventel",
304 	"AVM Berlin",
305 	"BandSpeed, Inc.",
306 	"Mansella Ltd",
307 	"NEC Corporation",
308 	"WavePlus Technology Co., Ltd.",
309 	"Alcatel",
310 	"Philips Semiconductors",
311 	"C Technologies",
312 	"Open Interface",
313 	"R F Micro Devices",
314 	"Hitachi Ltd",
315 	"Symbol Technologies, Inc.",
316 	"Tenovis",
317 	"Macronix International Co. Ltd.",
318 	"GCT Semiconductor",
319 	"Norwood Systems",
320 	"MewTel Technology Inc.",
321 	"ST Microelectronics",
322 	"Synopsys",
323 	"Red-M (Communications) Ltd",
324 	"Commil Ltd",
325 	"Computer Access Technology Corporation (CATC)",
326 	"Eclipse (HQ España) S.L.",
327 	"Renesas Technology Corp.",
328 	"Mobilian Corporation",
329 	"Terax",
330 	"Integrated System Solution Corp.",
331 	"Matsushita Electric Industrial Co., Ltd.",
332 	"Gennum Corporation",
333 	"Research In Motion",
334 	"IPextreme, Inc.",
335 	"Systems and Chips, Inc",
336 	"Bluetooth SIG, Inc",
337 	"Seiko Epson Corporation",
338 	"Integrated Silicon Solution Taiwain, Inc.",
339 	"CONWISE Technology Corporation Ltd",
340 	"PARROT SA",
341 	"Socket Communications",
342 	"Atheros Communications, Inc.",
343 	"MediaTek, Inc.",
344 	"Bluegiga",	/* (tentative) */
345 	"Marvell Technology Group Ltd.",
346 	"3DSP Corporation",
347 	"Accel Semiconductor Ltd.",
348 	"Continental Automotive Systems",
349 	"Apple, Inc.",
350 	"Staccato Communications, Inc."
351 };
352 
353 
354 const char* linkControlCommands[] = {
355 	"Inquiry",
356 	"Inquiry Cancel",
357 	"Periodic Inquiry Mode",
358 	"Exit Periodic Inquiry Mode",
359 	"Create Connection",
360 	"Disconnect",
361 	"Add SCO Connection", // not on 2.1
362 	"Cancel Create Connection",
363 	"Accept Connection Request",
364 	"Reject Connection Request",
365 	"Link Key Request Reply",
366 	"Link Key Request Negative Reply",
367 	"PIN Code Request Reply",
368 	"PIN Code Request Negative Reply",
369 	"Change Connection Packet Type",
370 	"Reserved", // not on 2.1",
371 	"Authentication Requested",
372 	"Reserved", // not on 2.1",
373 	"Set Connection Encryption",
374 	"Reserved", // not on 2.1",
375 	"Change Connection Link Key",
376 	"Reserved", // not on 2.1",
377 	"Master Link Key",
378 	"Reserved", // not on 2.1",
379 	"Remote Name Request",
380 	"Cancel Remote Name Request",
381 	"Read Remote Supported Features",
382 	"Read Remote Extended Features",
383 	"Read Remote Version Information",
384 	"Reserved", // not on 2.1",
385 	"Read Clock Offset",
386 	"Read LMP Handle",
387 	"Reserved",
388 	"Reserved",
389 	"Reserved",
390 	"Reserved",
391 	"Reserved",
392 	"Reserved",
393 	"Reserved",
394 	"Setup Synchronous Connection",
395 	"Accept Synchronous Connection",
396 	"Reject Synchronous Connection",
397 	"IO Capability Request Reply",
398 	"User Confirmation Request Reply",
399 	"User Confirmation Request Negative Reply",
400 	"User Passkey Request Reply",
401 	"User Passkey Request Negative Reply",
402 	"Remote OOB Data Request Reply",
403 	"Reserved",
404 	"Reserved",
405 	"Remote OOB Data Request Negative Reply",
406 	"IO Capabilities Response Negative Reply"
407 };
408 
409 
410 const char* linkPolicyCommands[] = {
411 	"Hold Mode",
412 	"Reserved",
413 	"Sniff Mode",
414 	"Exit Sniff Mode",
415 	"Park State",
416 	"Exit Park State",
417 	"QoS Setup",
418 	"Reserved",
419 	"Role Discovery",
420 	"Reserved",
421 	"Switch Role",
422 	"Read Link Policy Settings",
423 	"Write Link Policy Settings",
424 	"Read Default Link Policy Settings",
425 	"Write Default Link Policy Settings",
426 	"Flow Specification",
427 	"Sniff Subrating"
428 };
429 
430 
431 const char* controllerBasebandCommands[] = {
432 	"Set Event Mask",
433 	"Reserved",
434 	"Reset",
435 	"Reserved",
436 	"Set Event Filter",
437 	"Reserved",
438 	"Reserved",
439 	"Flush",
440 	"Read PIN Type",
441 	"Write PIN Type",
442 	"Create New Unit Key",
443 	"Reserved",
444 	"Read Stored Link Key",
445 	"Reserved",
446 	"Reserved",
447 	"Reserved",
448 	"Write Stored Link Key",
449 	"Delete Stored Link Key",
450 	"Write Local Name",
451 	"Read Local Name",
452 	"Read Connection Accept Timeout",
453 	"Write Connection Accept Timeout",
454 	"Read Page Timeout",
455 	"Write Page Timeout",
456 	"Read Scan Enable",
457 	"Write Scan Enable",
458 	"Read Page Scan Activity",
459 	"Write Page Scan Activity",
460 	"Read Inquiry Scan Activity",
461 	"Write Inquiry Scan Activity",
462 	"Read Authentication Enable",
463 	"Write Authentication Enable",
464 	"Read Encryption Mode", // not 2.1
465 	"Write Encryption Mode",// not 2.1
466 	"Read Class Of Device",
467 	"Write Class Of Device",
468 	"Read Voice Setting",
469 	"Write Voice Setting",
470 	"Read Automatic Flush Timeout",
471 	"Write Automatic Flush Timeout",
472 	"Read Num Broadcast Retransmissions",
473 	"Write Num Broadcast Retransmissions",
474 	"Read Hold Mode Activity",
475 	"Write Hold Mode Activity",
476 	"Read Transmit Power Level",
477 	"Read Synchronous Flow Control Enable",
478 	"Write Synchronous Flow Control Enable",
479 	"Reserved",
480 	"Set Host Controller To Host Flow Control",
481 	"Reserved",
482 	"Host Buffer Size",
483 	"Reserved",
484 	"Host Number Of Completed Packets",
485 	"Read Link Supervision Timeout",
486 	"Write Link Supervision Timeout",
487 	"Read Number of Supported IAC",
488 	"Read Current IAC LAP",
489 	"Write Current IAC LAP",
490 	"Read Page Scan Period Mode", // not 2.1
491 	"Write Page Scan Period Mode", // not 2.1
492 	"Read Page Scan Mode",		// not 2.1
493 	"Write Page Scan Mode",		// not 2.1
494 	"Set AFH Channel Classification",
495 	"Reserved",
496 	"Reserved",
497 	"Read Inquiry Scan Type",
498 	"Write Inquiry Scan Type",
499 	"Read Inquiry Mode",
500 	"Write Inquiry Mode",
501 	"Read Page Scan Type",
502 	"Write Page Scan Type",
503 	"Read AFH Channel Assessment Mode",
504 	"Write AFH Channel Assessment Mode",
505 	"Reserved",
506 	"Reserved",
507 	"Reserved",
508 	"Reserved",
509 	"Reserved",
510 	"Reserved",
511 	"Reserved",
512 	"Read Extended Inquiry Response",
513 	"Write Extended Inquiry Response",
514 	"Refresh Encryption Key",
515 	"Reserved",
516 	"Read Simple Pairing Mode",
517 	"Write Simple Pairing Mode",
518 	"Read Local OOB Data",
519 	"Read Inquiry Transmit Power Level",
520 	"Write Inquiry Transmit Power Level",
521 	"Read Default Erroneous Data Reporting",
522 	"Write Default Erroneous Data Reporting",
523 	"Reserved",
524 	"Reserved",
525 	"Reserved",
526 	"Enhanced Flush",
527 	"Send Keypress Notification"
528 };
529 
530 
531 const char* informationalParametersCommands[] = {
532 	"Read Local Version Information",
533 	"Read Local Supported Commands",
534 	"Read Local Supported Features",
535 	"Read Local Extended Features",
536 	"Read Buffer Size",
537 	"Reserved",
538 	"Read Country Code", // not 2.1
539 	"Reserved",
540 	"Read BD ADDR"
541 };
542 
543 
544 const char* statusParametersCommands[] = {
545 	"Read Failed Contact Counter",
546 	"Reset Failed Contact Counter",
547 	"Read Link Quality",
548 	"Reserved",
549 	"Read RSSI",
550 	"Read AFH Channel Map",
551 	"Read Clock",
552 };
553 
554 
555 const char* testingCommands[] = {
556 	"Read Loopback Mode",
557 	"Write Loopback Mode",
558 	"Enable Device Under Test Mode",
559 	"Write Simple Pairing Debug Mode",
560 };
561 
562 
563 const char* bluetoothEvents[] = {
564 	"Inquiry Complete",
565 	"Inquiry Result",
566 	"Conn Complete",
567 	"Conn Request",
568 	"Disconnection Complete",
569 	"Auth Complete",
570 	"Remote Name Request Complete",
571 	"Encrypt Change",
572 	"Change Conn Link Key Complete",
573 	"Master Link Key Compl",
574 	"Rmt Features",
575 	"Rmt Version",
576 	"Qos Setup Complete",
577 	"Command Complete",
578 	"Command Status",
579 	"Hardware Error",
580 	"Flush Occur",
581 	"Role Change",
582 	"Num Comp Pkts",
583 	"Mode Change",
584 	"Return Link Keys",
585 	"Pin Code Req",
586 	"Link Key Req",
587 	"Link Key Notify",
588 	"Loopback Command",
589 	"Data Buffer Overflow",
590 	"Max Slot Change",
591 	"Read Clock Offset Compl",
592 	"Con Pkt Type Changed",
593 	"Qos Violation",
594 	"Reserved",
595 	"Page Scan Rep Mode Change",
596 	"Flow Specification",
597 	"Inquiry Result With Rssi",
598 	"Remote Extended Features",
599 	"Reserved",
600 	"Reserved",
601 	"Reserved",
602 	"Reserved",
603 	"Reserved",
604 	"Reserved",
605 	"Reserved",
606 	"Reserved",
607 	"Synchronous Connection Completed",
608 	"Synchronous Connection Changed",
609 	"Reserved",
610 	"Extended Inquiry Result",
611 	"Encryption Key Refresh Complete",
612 	"Io Capability Request",
613 	"Io Capability Response",
614 	"User Confirmation Request",
615 	"User Passkey Request",
616 	"Oob Data Request",
617 	"Simple Pairing Complete",
618 	"Reserved",
619 	"Link Supervision Timeout Changed",
620 	"Enhanced Flush Complete",
621 	"Reserved",
622 	"Reserved",
623 	"Keypress Notification",
624 	"Remote Host Supported Features Notification"
625 };
626 
627 
628 const char* bluetoothErrors[] = {
629 	"No Error",
630 	"Unknown Command",
631 	"No Connection",
632 	"Hardware Failure",
633 	"Page Timeout",
634 	"Authentication Failure",
635 	"Pin Or Key Missing",
636 	"Memory Full",
637 	"Connection Timeout",
638 	"Max Number Of Connections",
639 	"Max Number Of Sco Connections",
640 	"Acl Connection Exists",
641 	"Command Disallowed",
642 	"Rejected Limited Resources",
643 	"Rejected Security",
644 	"Rejected Personal",
645 	"Host Timeout",
646 	"Unsupported Feature",
647 	"Invalid Parameters",
648 	"Remote User Ended Connection",
649 	"Remote Low Resources",
650 	"Remote Power Off",
651 	"Connection Terminated",
652 	"Repeated Attempts",
653 	"Pairing Not Allowed",
654 	"Unknown Lmp Pdu",
655 	"Unsupported Remote Feature",
656 	"Sco Offset Rejected",
657 	"Sco Interval Rejected",
658 	"Air Mode Rejected",
659 	"Invalid Lmp Parameters",
660 	"Unspecified Error",
661 	"Unsupported Lmp Parameter Value",
662 	"Role Change Not Allowed",
663 	"Lmp Response Timeout",
664 	"Lmp Error Transaction Collision",
665 	"Lmp Pdu Not Allowed",
666 	"Encryption Mode Not Accepted",
667 	"Unit Link Key Used",
668 	"Qos Not Supported",
669 	"Instant Passed",
670 	"Pairing With Unit Key Not Supported",
671 	"Different Transaction Collision",
672 	"Qos Unacceptable Parameter",
673 	"Qos Rejected",
674 	"Classification Not Supported",
675 	"Insufficient Security",
676 	"Parameter Out Of Range",
677 	"Reserved",
678 	"Role Switch Pending",
679 	"Reserved",
680 	"Slot Violation",
681 	"Role Switch Failed",
682 	"Extended Inquiry Response Too Large",
683 	"Simple Pairing Not Supported By Host",
684 	"Host Busy Pairing"
685 };
686 
687 
688 const char* hciVersion[] = { "1.0B" , "1.1 " , "1.2 " , "2.0 " , "2.1 "};
689 const char* lmpVersion[] = { "1.0 " , "1.1 " , "1.2 " , "2.0 " , "2.1 "};
690 
691 
692 #if 0
693 #pragma mark -
694 #endif
695 
696 
697 const char*
698 BluetoothHciVersion(uint16 ver)
699 {
700 	return hciVersion[ver];
701 }
702 
703 
704 const char*
705 BluetoothLmpVersion(uint16 ver)
706 {
707 	return lmpVersion[ver];
708 }
709 
710 
711 const char*
712 BluetoothCommandOpcode(uint16 opcode)
713 {
714 
715 	// NOTE: BT implementations beyond 2.1
716 	// could specify new commands with OCF numbers
717 	// beyond the boundaries of the arrays and crash.
718 	// But only our stack could issue them so its under
719 	// our control.
720 	switch (GET_OPCODE_OGF(opcode)) {
721 		case OGF_LINK_CONTROL:
722 			return linkControlCommands[GET_OPCODE_OCF(opcode) - 1];
723 			break;
724 
725 		case OGF_LINK_POLICY:
726 			return linkPolicyCommands[GET_OPCODE_OCF(opcode) - 1];
727 			break;
728 
729 		case OGF_CONTROL_BASEBAND:
730 			return controllerBasebandCommands[GET_OPCODE_OCF(opcode) - 1];
731 			break;
732 
733 		case OGF_INFORMATIONAL_PARAM:
734 			return informationalParametersCommands[GET_OPCODE_OCF(opcode) - 1];
735 			break;
736 
737 		case OGF_STATUS_PARAM:
738 			return statusParametersCommands[GET_OPCODE_OCF(opcode) - 1];
739 			break;
740 
741 		case OGF_TESTING_CMD:
742 			return testingCommands[GET_OPCODE_OCF(opcode) - 1];
743 			break;
744 		case OGF_VENDOR_CMD:
745 			return "Vendor specific command";
746 			break;
747 		default:
748 			return "Unknown command";
749 			break;
750 	}
751 
752 }
753 
754 
755 const char*
756 BluetoothEvent(uint8 event)
757 {
758 	if (event < sizeof(bluetoothEvents) / sizeof(const char*))
759 		return bluetoothEvents[event - 1];
760 	else
761 		return "Event out of Range!";
762 }
763 
764 
765 const char*
766 BluetoothManufacturer(uint16 manufacturer)
767 {
768 	if (manufacturer < sizeof(bluetoothManufacturers) / sizeof(const char*))
769 		return bluetoothManufacturers[manufacturer];
770 	else if (manufacturer == 0xFFFF)
771 		return "internal use";
772 	else
773 		return "not assigned";
774 }
775 
776 
777 const char*
778 BluetoothError(uint8 error)
779 {
780 	if (error < sizeof(bluetoothErrors) / sizeof(const char*))
781 		return bluetoothErrors[error];
782 	else
783 		return "not specified";
784 }
785