#include "common.h"
#include "util.h"
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#define XML_BUFSIZE 0x10000
static void dump_xml_fragment(uint8_t *buf, uint32_t len)
{
static int endianness = 0;
uint32_t bp = 0;
while (bp < len) {
if (buf[bp+0] == 0xFF && buf[bp+1] == 0xFE) {
endianness = 0;
} else if (buf[bp+0] == 0xFE && buf[bp+1] == 0xff) {
endianness = 1;
} else {
uint16_t tmp;
if (endianness == 0) {
tmp = buf[bp+1] << 8 | buf[bp+0];
} else {
tmp = buf[bp+0] << 8 | buf[bp+1];
}
printf("%c", (uint8_t) tmp);
}
bp += 2;
}
printf("\n");
}
int main (int argc, char **argv)
{
int numrawdevices;
int i;
int opt;
extern int optind;
extern char *optarg;
while ((opt = getopt(argc, argv, "d")) != -1 ) {
switch (opt) {
case 'd':
break;
}
}
argc -= optind;
argv += optind;
fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
fprintf(stdout, "Listing raw device(s)\n");
switch(err) {
case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
fprintf(stdout, " No raw devices found.\n");
return 0;
case LIBMTP_ERROR_CONNECTING:
fprintf(stderr, "Detect: There has been an error connecting. Exiting\n");
return 1;
case LIBMTP_ERROR_MEMORY_ALLOCATION:
fprintf(stderr, "Detect: Encountered a Memory Allocation Error. Exiting\n");
return 1;
case LIBMTP_ERROR_NONE:
{
int i;
fprintf(stdout, " Found %d device(s):\n", numrawdevices);
for (i = 0; i < numrawdevices; i++) {
if (rawdevices[i].device_entry.vendor != NULL ||
fprintf(stdout, " %s: %s (%04x:%04x) @ bus %d, dev %d\n",
rawdevices[i].device_entry.vendor,
} else {
fprintf(stdout, " %04x:%04x @ bus %d, dev %d\n",
rawdevices[i].device_entry.vendor_id,
}
}
}
break;
case LIBMTP_ERROR_GENERAL:
default:
fprintf(stderr, "Unknown connection error.\n");
return 1;
}
fprintf(stdout, "Attempting to connect device(s)\n");
for (i = 0; i < numrawdevices; i++) {
char *friendlyname;
char *syncpartner;
char *sectime;
char *devcert;
uint16_t *filetypes;
uint16_t filetypes_len;
uint8_t maxbattlevel;
uint8_t currbattlevel;
int ret;
if (device == NULL) {
fprintf(stderr, "Unable to open raw device %d\n", i);
continue;
}
printf("MTP-specific device properties:\n");
if (friendlyname == NULL) {
fprintf(stdout, " Friendly name: (NULL)\n");
} else {
fprintf(stdout, " Friendly name: %s\n", friendlyname);
free(friendlyname);
}
if (syncpartner == NULL) {
fprintf(stdout, " Synchronization partner: (NULL)\n");
} else {
fprintf(stdout, " Synchronization partner: %s\n", syncpartner);
free(syncpartner);
}
if (ret == 0) {
fprintf(stdout, " Battery level %d of %d (%d%%)\n",currbattlevel, maxbattlevel,
(int) ((float) currbattlevel/ (float) maxbattlevel * 100.0));
} else {
}
if (ret == 0) {
uint16_t i;
printf("libmtp supported (playable) filetypes:\n");
for (i = 0; i < filetypes_len; i++) {
}
} else {
}
if (ret == 0 && sectime != NULL) {
fprintf(stdout, "\nSecure Time:\n%s\n", sectime);
free(sectime);
} else {
}
if (rawdevices[i].device_entry.vendor_id == 0x041e) {
if (ret == 0 && devcert != NULL) {
fprintf(stdout, "\nDevice Certificate:\n%s\n", devcert);
free(devcert);
} else {
fprintf(stdout, "Unable to acquire device certificate, perhaps this device "
"does not support this\n");
}
}
for (storage = device->
storage; storage != 0; storage = storage->
next) {
0);
if (files != NULL) {
file = files;
while (file != NULL) {
if (!strcmp(file->
filename,
"WMPInfo.xml") ||
!strcmp(file->
filename,
"WMPinfo.xml") ||
!strcmp(file->
filename,
"default-capabilities.xml")) {
FILE *xmltmp = tmpfile();
int tmpfiledescriptor = fileno(xmltmp);
if (tmpfiledescriptor != -1) {
tmpfiledescriptor,
NULL,
NULL);
if (ret == 0) {
uint8_t *buf = NULL;
uint32_t readbytes;
buf = malloc(XML_BUFSIZE);
if (buf == NULL) {
printf("Could not allocate %08x bytes...\n", XML_BUFSIZE);
free(rawdevices);
return 1;
}
lseek(tmpfiledescriptor, 0, SEEK_SET);
readbytes = read(tmpfiledescriptor, (void*) buf, XML_BUFSIZE);
if (readbytes >= 2 && readbytes < XML_BUFSIZE) {
fprintf(stdout,
"\n%s file contents:\n", file->
filename);
dump_xml_fragment(buf, readbytes);
} else {
perror("Unable to read file");
}
free(buf);
} else {
}
fclose(xmltmp);
}
}
}
tmp = file;
}
}
}
}
free(rawdevices);
printf("OK.\n");
return 0;
}