OLD | NEW |
1 /** | 1 /** |
2 * \file detect.c | 2 * \file detect.c |
3 * Example program to detect a device and list capabilities. | 3 * Example program to detect a device and list capabilities. |
4 * | 4 * |
5 * Copyright (C) 2005-2015 Linus Walleij <triad@df.lth.se> | 5 * Copyright (C) 2005-2008 Linus Walleij <triad@df.lth.se> |
6 * Copyright (C) 2007 Ted Bullock <tbullock@canada.com> | 6 * Copyright (C) 2007 Ted Bullock <tbullock@canada.com> |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Lesser General Public | 9 * modify it under the terms of the GNU Lesser General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
12 * | 12 * |
13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 case LIBMTP_ERROR_GENERAL: | 123 case LIBMTP_ERROR_GENERAL: |
124 default: | 124 default: |
125 fprintf(stderr, "Unknown connection error.\n"); | 125 fprintf(stderr, "Unknown connection error.\n"); |
126 return 1; | 126 return 1; |
127 } | 127 } |
128 | 128 |
129 /* Iterate over connected MTP devices */ | 129 /* Iterate over connected MTP devices */ |
130 fprintf(stdout, "Attempting to connect device(s)\n"); | 130 fprintf(stdout, "Attempting to connect device(s)\n"); |
131 for (i = 0; i < numrawdevices; i++) { | 131 for (i = 0; i < numrawdevices; i++) { |
132 LIBMTP_mtpdevice_t *device; | 132 LIBMTP_mtpdevice_t *device; |
133 LIBMTP_devicestorage_t *storage; | 133 LIBMTP_file_t *files; |
134 char *friendlyname; | 134 char *friendlyname; |
135 char *syncpartner; | 135 char *syncpartner; |
136 char *sectime; | 136 char *sectime; |
137 char *devcert; | 137 char *devcert; |
138 uint16_t *filetypes; | 138 uint16_t *filetypes; |
139 uint16_t filetypes_len; | 139 uint16_t filetypes_len; |
140 uint8_t maxbattlevel; | 140 uint8_t maxbattlevel; |
141 uint8_t currbattlevel; | 141 uint8_t currbattlevel; |
142 int ret; | 142 int ret; |
143 | 143 |
144 device = LIBMTP_Open_Raw_Device_Uncached(&rawdevices[i]); | 144 device = LIBMTP_Open_Raw_Device(&rawdevices[i]); |
145 if (device == NULL) { | 145 if (device == NULL) { |
146 fprintf(stderr, "Unable to open raw device %d\n", i); | 146 fprintf(stderr, "Unable to open raw device %d\n", i); |
147 continue; | 147 continue; |
148 } | 148 } |
149 | 149 |
150 LIBMTP_Dump_Errorstack(device); | 150 LIBMTP_Dump_Errorstack(device); |
151 LIBMTP_Clear_Errorstack(device); | 151 LIBMTP_Clear_Errorstack(device); |
152 LIBMTP_Dump_Device_Info(device); | 152 LIBMTP_Dump_Device_Info(device); |
153 | 153 |
154 printf("MTP-specific device properties:\n"); | 154 printf("MTP-specific device properties:\n"); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 ret = LIBMTP_Get_Secure_Time(device, §ime); | 196 ret = LIBMTP_Get_Secure_Time(device, §ime); |
197 if (ret == 0 && sectime != NULL) { | 197 if (ret == 0 && sectime != NULL) { |
198 fprintf(stdout, "\nSecure Time:\n%s\n", sectime); | 198 fprintf(stdout, "\nSecure Time:\n%s\n", sectime); |
199 free(sectime); | 199 free(sectime); |
200 } else { | 200 } else { |
201 // Silently ignore - there may be devices not supporting secure time. | 201 // Silently ignore - there may be devices not supporting secure time. |
202 LIBMTP_Clear_Errorstack(device); | 202 LIBMTP_Clear_Errorstack(device); |
203 } | 203 } |
204 | 204 |
205 // Device certificate XML fragment | 205 // Device certificate XML fragment |
206 if (rawdevices[i].device_entry.vendor_id == 0x041e) { | 206 #if 0 |
207 /* | 207 /* |
208 * This code is currently disabled except for vendors we | 208 * This code is currently disabled: all devices say that |
209 * know does support it: all devices say that | 209 * they support getting a device certificate but a lot of |
210 * they support getting a device certificate but a lot of | 210 * them obviously doesn't, instead they crash when you try |
211 * them obviously doesn't, instead they crash when you try | 211 * to obtain it. |
212 * to obtain it. | 212 */ |
213 */ | 213 ret = LIBMTP_Get_Device_Certificate(device, &devcert); |
214 ret = LIBMTP_Get_Device_Certificate(device, &devcert); | 214 if (ret == 0 && devcert != NULL) { |
215 if (ret == 0 && devcert != NULL) { | 215 fprintf(stdout, "\nDevice Certificate:\n%s\n", devcert); |
216 » fprintf(stdout, "\nDevice Certificate:\n%s\n", devcert); | 216 free(devcert); |
217 » free(devcert); | 217 } else { |
218 } else { | 218 fprintf(stdout, "Unable to acquire device certificate, perhaps this device
" |
219 » fprintf(stdout, "Unable to acquire device certificate, perhaps this devi
ce " | 219 » "does not support this\n"); |
220 » » "does not support this\n"); | 220 LIBMTP_Dump_Errorstack(device); |
221 » LIBMTP_Dump_Errorstack(device); | 221 LIBMTP_Clear_Errorstack(device); |
222 » LIBMTP_Clear_Errorstack(device); | |
223 } | |
224 } | 222 } |
| 223 #endif |
225 | 224 |
226 /* Try to get Media player device info XML file... */ | 225 // Try to get Media player device info XML file... |
227 /* Loop over storages */ | 226 files = LIBMTP_Get_Filelisting_With_Callback(device, NULL, NULL); |
228 for (storage = device->storage; storage != 0; storage = storage->next) { | 227 if (files != NULL) { |
229 LIBMTP_file_t *files; | 228 LIBMTP_file_t *file, *tmp; |
230 | 229 file = files; |
231 /* Get file listing for the root directory, no other dirs */ | 230 while (file != NULL) { |
232 files = LIBMTP_Get_Files_And_Folders(device, | 231 » if (!strcmp(file->filename, "WMPInfo.xml") || |
233 » » » » » storage->id, | 232 » !strcmp(file->filename, "WMPinfo.xml") || |
234 » » » » » 0); | 233 » !strcmp(file->filename, "default-capabilities.xml")) { |
235 | |
236 if (files != NULL) { | |
237 » LIBMTP_file_t *file, *tmp; | |
238 » file = files; | |
239 » while (file != NULL) { | |
240 » if (!strcmp(file->filename, "WMPInfo.xml") || | |
241 » !strcmp(file->filename, "WMPinfo.xml") || | |
242 » !strcmp(file->filename, "default-capabilities.xml")) { | |
243 if (file->item_id != 0) { | 234 if (file->item_id != 0) { |
244 /* Dump this file */ | 235 /* Dump this file */ |
245 FILE *xmltmp = tmpfile(); | 236 FILE *xmltmp = tmpfile(); |
246 int tmpfiledescriptor = fileno(xmltmp); | 237 int tmpfiledescriptor = fileno(xmltmp); |
247 | 238 |
248 if (tmpfiledescriptor != -1) { | 239 if (tmpfiledescriptor != -1) { |
249 int ret = LIBMTP_Get_Track_To_File_Descriptor(device, | 240 int ret = LIBMTP_Get_Track_To_File_Descriptor(device, |
250 file->item_id, | 241 file->item_id, |
251 tmpfiledescriptor, | 242 tmpfiledescriptor, |
252 NULL, | 243 NULL, |
(...skipping 23 matching lines...) Expand all Loading... |
276 LIBMTP_Clear_Errorstack(device); | 267 LIBMTP_Clear_Errorstack(device); |
277 } | 268 } |
278 free(buf); | 269 free(buf); |
279 } else { | 270 } else { |
280 LIBMTP_Dump_Errorstack(device); | 271 LIBMTP_Dump_Errorstack(device); |
281 LIBMTP_Clear_Errorstack(device); | 272 LIBMTP_Clear_Errorstack(device); |
282 } | 273 } |
283 fclose(xmltmp); | 274 fclose(xmltmp); |
284 } | 275 } |
285 } | 276 } |
286 } | |
287 tmp = file; | |
288 file = file->next; | |
289 LIBMTP_destroy_file_t(tmp); | |
290 } | 277 } |
| 278 tmp = file; |
| 279 file = file->next; |
| 280 LIBMTP_destroy_file_t(tmp); |
291 } | 281 } |
292 } | 282 } |
293 LIBMTP_Release_Device(device); | 283 LIBMTP_Release_Device(device); |
294 } /* End For Loop */ | 284 } /* End For Loop */ |
295 | 285 |
296 free(rawdevices); | 286 free(rawdevices); |
297 | 287 |
298 printf("OK.\n"); | 288 printf("OK.\n"); |
299 | 289 |
300 return 0; | 290 return 0; |
301 } | 291 } |
OLD | NEW |