@@ -151,11 +151,15 @@ FN_INTERNAL libusb_device * fnusb_find_sibling_device(freenect_context* ctx, lib
151
151
return NULL ;
152
152
}
153
153
154
- FN_INTERNAL char * fnusb_get_serial (freenect_context * ctx , libusb_device * device , libusb_device_handle * handle )
154
+ FN_INTERNAL char * usb_get_serial (freenect_context * ctx , libusb_device * device , libusb_device_handle * handle )
155
155
{
156
156
if (ctx == NULL ) return NULL ;
157
157
158
- if (device == NULL && handle != NULL ) {
158
+ if (device == NULL ) {
159
+ if (handle == NULL ) {
160
+ FN_WARNING ("No handle or device for serial\n" );
161
+ return NULL ;
162
+ }
159
163
device = libusb_get_device (handle ); // no need to free or unref
160
164
}
161
165
@@ -170,6 +174,7 @@ FN_INTERNAL char* fnusb_get_serial(freenect_context* ctx, libusb_device* device,
170
174
171
175
// Verify that a serial number exists to query. If not, don't touch the device.
172
176
if (desc .iSerialNumber == 0 ) {
177
+ FN_WARNING ("Device has no serial number\n" );
173
178
return NULL ;
174
179
}
175
180
@@ -184,7 +189,6 @@ FN_INTERNAL char* fnusb_get_serial(freenect_context* ctx, libusb_device* device,
184
189
handle = localHandle ;
185
190
}
186
191
187
- // Read string descriptor referring to serial number.
188
192
unsigned char serial [256 ]; // String descriptors are at most 256 bytes.
189
193
res = libusb_get_string_descriptor_ascii (handle , desc .iSerialNumber , serial , 256 );
190
194
@@ -197,7 +201,17 @@ FN_INTERNAL char* fnusb_get_serial(freenect_context* ctx, libusb_device* device,
197
201
return NULL ;
198
202
}
199
203
200
- return strdup (serial );
204
+ const char * const K4W_1473_SERIAL = "0000000000000000" ;
205
+ if (strncmp ((const char * )serial , K4W_1473_SERIAL , 16 ) == 0 ) {
206
+ return NULL ; // K4W and 1473 provide an empty serial; more easily handled as NULL.
207
+ }
208
+
209
+ return strndup ((const char * )serial , sizeof (serial ));
210
+ }
211
+
212
+ FN_INTERNAL char * fnusb_get_serial (fnusb_dev * device )
213
+ {
214
+ return usb_get_serial (device -> parent -> parent , device -> dev , device -> dev_handle );
201
215
}
202
216
203
217
FN_INTERNAL int fnusb_list_device_attributes (freenect_context * ctx , struct freenect_device_attributes * * attribute_list )
@@ -232,16 +246,13 @@ FN_INTERNAL int fnusb_list_device_attributes(freenect_context *ctx, struct freen
232
246
continue ;
233
247
}
234
248
235
- const char * serial = fnusb_get_serial (ctx , camera_device , NULL );
236
-
237
- // K4W and 1473 don't provide a camera serial; use audio serial instead.
238
- const char * const K4W_1473_SERIAL = "0000000000000000" ;
239
- if (serial == NULL || strncmp ((const char * )serial , K4W_1473_SERIAL , 16 ) == 0 )
249
+ char * serial = usb_get_serial (ctx , camera_device , NULL );
250
+ if (serial == NULL )
240
251
{
241
252
libusb_device * audio_device = fnusb_find_sibling_device (ctx , camera_device , devs , count , & fnusb_is_audio );
242
253
if (audio_device != NULL )
243
254
{
244
- const char * audio_serial = fnusb_get_serial (ctx , audio_device , NULL );
255
+ char * audio_serial = usb_get_serial (ctx , audio_device , NULL );
245
256
if (audio_serial ) {
246
257
free (serial );
247
258
serial = audio_serial ;
0 commit comments