summaryrefslogtreecommitdiff
path: root/rbutil/ipodpatcher/ipodpatcher.c
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/ipodpatcher/ipodpatcher.c')
-rw-r--r--rbutil/ipodpatcher/ipodpatcher.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/rbutil/ipodpatcher/ipodpatcher.c b/rbutil/ipodpatcher/ipodpatcher.c
index dd650506a1..1a5268bb6d 100644
--- a/rbutil/ipodpatcher/ipodpatcher.c
+++ b/rbutil/ipodpatcher/ipodpatcher.c
@@ -1401,6 +1401,86 @@ int write_dos_partition_table(struct ipod_t* ipod)
1401 return 0; 1401 return 0;
1402} 1402}
1403 1403
1404/* Get the XML Device Information, as documented here:
1405
1406 http://www.ipodlinux.org/wiki/Device_Information
1407*/
1408
1409int ipod_get_xmlinfo(struct ipod_t* ipod)
1410{
1411 unsigned char hdr[255];
1412 unsigned char buf[255];
1413 char* p;
1414 int psize;
1415 int npages;
1416 int i;
1417
1418 if (ipod_scsi_inquiry(ipod, 0xc0, buf, sizeof(buf)) < 0)
1419 {
1420 fprintf(stderr,"[ERR] Sending SCSI Command failed.\n");
1421 return -1;
1422 }
1423
1424 /* Reading directly into hdr[] causes problems (for an unknown reason) on
1425 win32 */
1426 memcpy(hdr, buf, sizeof(hdr));
1427
1428 npages = hdr[3];
1429
1430 psize = npages * 0xf8; /* Hopefully this is enough. */
1431
1432 ipod->xmlinfo = malloc(psize);
1433 ipod->xmlinfo_len = 0;
1434
1435 if (ipod->xmlinfo == NULL) {
1436 fprintf(stderr,"[ERR] Could not allocate RAM for xmlinfo\n");
1437 return -1;
1438 }
1439
1440 p = ipod->xmlinfo;
1441
1442 for (i=0; i < npages; i++) {
1443 if (ipod_scsi_inquiry(ipod, hdr[i+4], buf, sizeof(buf)) < 0) {
1444 fprintf(stderr,"[ERR] Sending SCSI Command failed.\n");
1445 return -1;
1446 }
1447
1448 if ((buf[3] + ipod->xmlinfo_len) > psize) {
1449 fprintf(stderr,"[ERR] Ran out of memory reading xmlinfo\n");
1450 free(ipod->xmlinfo);
1451 ipod->xmlinfo = NULL;
1452 ipod->xmlinfo_len = 0;
1453 return -1;
1454 }
1455
1456 memcpy(p, buf + 4, buf[3]);
1457 p += buf[3];
1458 ipod->xmlinfo_len += buf[3];
1459 }
1460
1461 /* NULL-terminate the XML info */
1462 *p = 0;
1463
1464 fprintf(stderr,"[INFO] Read XML info (%d bytes)\n",ipod->xmlinfo_len);
1465
1466 return 0;
1467}
1468
1469void ipod_get_ramsize(struct ipod_t* ipod)
1470{
1471 const char needle[] = "<key>RAM</key>\n<integer>";
1472 char* p;
1473
1474 if (ipod->xmlinfo == NULL)
1475 return;
1476
1477 p = strstr(ipod->xmlinfo, needle);
1478
1479 if (p) {
1480 ipod->ramsize = atoi(p + sizeof(needle) - 1);
1481 }
1482}
1483
1404#ifndef RBUTIL 1484#ifndef RBUTIL
1405 1485
1406static inline uint32_t getuint32le(unsigned char* buf) 1486static inline uint32_t getuint32le(unsigned char* buf)