|
0
|
1 |
/*
|
|
|
2 |
* Copyright (c) 2000 - 2006 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
3 |
* All rights reserved.
|
|
|
4 |
* This component and the accompanying materials are made available
|
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
|
6 |
* which accompanies this distribution, and is available
|
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
|
8 |
*
|
|
|
9 |
* Initial Contributors:
|
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
|
11 |
*
|
|
|
12 |
* Contributors:
|
|
|
13 |
*
|
|
|
14 |
* Description: Test utility
|
|
|
15 |
*
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
#include "s_lib.h"
|
|
|
20 |
#include "bt_ioctl.h"
|
|
|
21 |
#include "vid.h"
|
|
|
22 |
|
|
|
23 |
static char pname[] = "sbt";
|
|
|
24 |
static char BtControlDeviceName[] = "\\\\.\\HciUsbControl";
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Opens a handle to the driver's control device object.
|
|
|
28 |
* Prints error message in case of failure, which usually indicates
|
|
|
29 |
* that driver is not loaded.
|
|
|
30 |
*/
|
|
|
31 |
STATIC HANDLE SBT_OpenDriver()
|
|
|
32 |
{
|
|
|
33 |
HANDLE hDriver = CreateFile(BtControlDeviceName,
|
|
|
34 |
FILE_GENERIC_READ | FILE_GENERIC_WRITE,
|
|
|
35 |
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
36 |
NULL, OPEN_EXISTING, 0, NULL);
|
|
|
37 |
if (hDriver == INVALID_HANDLE_VALUE) {
|
|
|
38 |
PRINT_Verbose("%s: failed to open %s, error %d\n",pname,
|
|
|
39 |
BtControlDeviceName, GetLastError());
|
|
|
40 |
PRINT_Error("%s: driver is not loaded\n",pname);
|
|
|
41 |
} else {
|
|
|
42 |
BtVersion v;
|
|
|
43 |
ULONG nbytes = 0;
|
|
|
44 |
ZeroMemory(&v, sizeof(v));
|
|
|
45 |
if (DeviceIoControl(hDriver, IOCTL_S60BT_VERSION, NULL, 0,
|
|
|
46 |
&v, sizeof(v), &nbytes, NULL)) {
|
|
|
47 |
ASSERT(nbytes == sizeof(v));
|
|
|
48 |
PRINT_Verbose("%s: driver version %d.%d.%d\n",pname,
|
|
|
49 |
v.major, v.minor, v.micro);
|
|
|
50 |
} else {
|
|
|
51 |
PRINT_Error("%s: failed to query driver version\n",pname);
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
return hDriver;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* Lists the ports created by the driver and their status.
|
|
|
59 |
*/
|
|
|
60 |
STATIC void SBT_ListPorts(HANDLE hDriver)
|
|
|
61 |
{
|
|
|
62 |
ULONG nbytes = 0;
|
|
|
63 |
BtPortList* list = MEM_New(BtPortList);
|
|
|
64 |
if (list) {
|
|
|
65 |
ZeroMemory(list, sizeof(*list));
|
|
|
66 |
if (DeviceIoControl(hDriver, IOCTL_S60BT_GET_PORT_LIST, NULL, 0,
|
|
|
67 |
list, sizeof(*list), &nbytes, NULL)) {
|
|
|
68 |
|
|
|
69 |
BtUint32 i;
|
|
|
70 |
while (list && list->totalCount > list->infoCount) {
|
|
|
71 |
int n = list->totalCount;
|
|
|
72 |
int size = sizeof(BtPortList) + n*sizeof(BtPortInfo);
|
|
|
73 |
MEM_Free(list);
|
|
|
74 |
list = MEM_Alloc(size);
|
|
|
75 |
if (list) {
|
|
|
76 |
ZeroMemory(list, sizeof(BtPortList));
|
|
|
77 |
nbytes = 0;
|
|
|
78 |
DeviceIoControl(hDriver, IOCTL_S60BT_GET_PORT_LIST, NULL, 0,
|
|
|
79 |
list, size, &nbytes, NULL);
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
if (list) {
|
|
|
84 |
PRINT_Output("%s: found %d port%s\n", pname, list->totalCount,
|
|
|
85 |
((list->totalCount % 10) == 1)? "" : "s");
|
|
|
86 |
for (i=0; i<list->totalCount; i++) {
|
|
|
87 |
BtPortInfo* p = ((BtPortInfo*)(list+1)) + i;
|
|
|
88 |
PRINT_Output("COM%d: %savailable\n", p->portNum,
|
|
|
89 |
p->openCount ? "not " : "");
|
|
|
90 |
if (PRINT_GetMask() & TRACE_VERBOSE) {
|
|
|
91 |
Str vendorName = VID_GetVendorName(p->vid);
|
|
|
92 |
if (vendorName) {
|
|
|
93 |
PRINT_Verbose(" USB Vendor ID: 0x%04X (%s)\n",
|
|
|
94 |
p->vid, vendorName);
|
|
|
95 |
} else {
|
|
|
96 |
PRINT_Verbose(" USB Vendor ID: 0x%04X\n",
|
|
|
97 |
p->vid);
|
|
|
98 |
}
|
|
|
99 |
PRINT_Verbose(" USB Product ID: 0x%04X\n", p->pid);
|
|
|
100 |
if (p->manufacturer[0]) {
|
|
|
101 |
PRINT_Verbose(" Manufacturer: %ls\n",
|
|
|
102 |
p->manufacturer);
|
|
|
103 |
}
|
|
|
104 |
if (p->productName[0]) {
|
|
|
105 |
PRINT_Verbose(" Product name: %ls\n",
|
|
|
106 |
p->productName);
|
|
|
107 |
}
|
|
|
108 |
if (p->serialNumber[0]) {
|
|
|
109 |
PRINT_Verbose(" Serial number: %ls\n",
|
|
|
110 |
p->serialNumber);
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
MEM_Free(list);
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
} else {
|
|
|
118 |
PRINT_Verbose("%s: DeviceIoControl error %d\n",pname,
|
|
|
119 |
GetLastError());
|
|
|
120 |
PRINT_Error("%s: failed to query port list\n",pname);
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
/**
|
|
|
126 |
* The program entry point.
|
|
|
127 |
*/
|
|
|
128 |
int main(int argc, char* argv[])
|
|
|
129 |
{
|
|
|
130 |
CmdLine * c;
|
|
|
131 |
SLIB_InitModules();
|
|
|
132 |
|
|
|
133 |
/* Parse the comment line */
|
|
|
134 |
c = CMDLINE_Create(pname);
|
|
|
135 |
if (c) {
|
|
|
136 |
Bool help = False;
|
|
|
137 |
Bool verbose = False;
|
|
|
138 |
CMDLINE_AddTrueOpt(c,'h',"help","print this help and exit",&help);
|
|
|
139 |
CMDLINE_AddTrueOpt(c,'v',"verbose","produce verbose output",&verbose);
|
|
|
140 |
CMDLINE_SetMaxArgs(c, 0);
|
|
|
141 |
CMDLINE_SetApp(c, pname);
|
|
|
142 |
if (CMDLINE_Parse(c, argv+1, argc-1, PARSE_NO_DUP, NULL) && !help) {
|
|
|
143 |
HANDLE hDriver;
|
|
|
144 |
|
|
|
145 |
/* Set TRACE_ALL flags if verbose mode is selected */
|
|
|
146 |
if (verbose) PRINT_SetMask(TRACE_ALL);
|
|
|
147 |
|
|
|
148 |
/* Open the driver */
|
|
|
149 |
hDriver = SBT_OpenDriver();
|
|
|
150 |
if (hDriver != INVALID_HANDLE_VALUE) {
|
|
|
151 |
SBT_ListPorts(hDriver);
|
|
|
152 |
CloseHandle(hDriver);
|
|
|
153 |
}
|
|
|
154 |
} else {
|
|
|
155 |
|
|
|
156 |
/* Print the usage summary. */
|
|
|
157 |
CMDLINE_Usage(c, NULL, 0);
|
|
|
158 |
}
|
|
|
159 |
}
|
|
|
160 |
SLIB_Shutdown();
|
|
|
161 |
}
|