summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2013-01-09 15:32:15 +0100
committerGravatar Martin Szulecki2013-01-09 15:32:15 +0100
commit3de0951516e462d8d438db4a0c3099c5ef308192 (patch)
tree88716639bd4da4d185d5c4011ae513af2d43d9f8 /src
parent21ba76975546cbe1f95ea9c0fe98a9fd2adec35a (diff)
downloadlibirecovery-3de0951516e462d8d438db4a0c3099c5ef308192.tar.gz
libirecovery-3de0951516e462d8d438db4a0c3099c5ef308192.tar.bz2
Improve maintainability of devices and add support for all current models
This removes all CPID_* and BDID_* defines which appear useless as the same information is already stored in the irecv_devices[] struct. Furthermore this removes a big inefficient switch() to determine a device in favor of a simple loop on the irecv_devices[] struct. Overall this means much less maintainance to add new device models in the future.
Diffstat (limited to 'src')
-rw-r--r--src/libirecovery.c165
1 files changed, 7 insertions, 158 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c
index f2c8798..fa16f70 100644
--- a/src/libirecovery.c
+++ b/src/libirecovery.c
@@ -1501,171 +1501,20 @@ irecv_error_t irecv_get_device(irecv_client_t client, irecv_device_t* device) {
1501 int device_id = DEVICE_UNKNOWN; 1501 int device_id = DEVICE_UNKNOWN;
1502 uint32_t bdid = 0; 1502 uint32_t bdid = 0;
1503 uint32_t cpid = 0; 1503 uint32_t cpid = 0;
1504 int i = 0;
1504 1505
1505 if (irecv_get_cpid(client, &cpid) < 0) { 1506 if (irecv_get_cpid(client, &cpid) < 0) {
1506 return IRECV_E_UNKNOWN_ERROR; 1507 return IRECV_E_UNKNOWN_ERROR;
1507 } 1508 }
1508 1509
1509 switch (cpid) { 1510 if (irecv_get_bdid(client, &bdid) < 0) {
1510 case CPID_IPHONE2G: 1511 return IRECV_E_UNKNOWN_ERROR;
1511 // iPhone1,1 iPhone1,2 and iPod1,1 all share the same ChipID 1512 }
1512 // so we need to check the BoardID
1513 if (irecv_get_bdid(client, &bdid) < 0) {
1514 break;
1515 }
1516
1517 switch (bdid) {
1518 case BDID_IPHONE2G:
1519 device_id = DEVICE_IPHONE2G;
1520 break;
1521
1522 case BDID_IPHONE3G:
1523 device_id = DEVICE_IPHONE3G;
1524 break;
1525
1526 case BDID_IPOD1G:
1527 device_id = DEVICE_IPOD1G;
1528 break;
1529
1530 default:
1531 device_id = DEVICE_UNKNOWN;
1532 break;
1533 }
1534 break;
1535
1536 case CPID_IPHONE3GS:
1537 device_id = DEVICE_IPHONE3GS;
1538 break;
1539
1540 case CPID_IPOD2G:
1541 device_id = DEVICE_IPOD2G;
1542 break;
1543
1544 case CPID_IPOD3G:
1545 device_id = DEVICE_IPOD3G;
1546 break;
1547
1548 case CPID_IPAD1G:
1549 // iPhone3,1 iPhone3,3 iPad4,1 and iPad1,1 all share the same ChipID
1550 // so we need to check the BoardID
1551 if (irecv_get_bdid(client, &bdid) < 0) {
1552 break;
1553 }
1554
1555 switch (bdid) {
1556 case BDID_IPAD1G:
1557 device_id = DEVICE_IPAD1G;
1558 break;
1559
1560 case BDID_IPHONE4:
1561 device_id = DEVICE_IPHONE4;
1562 break;
1563
1564 case BDID_IPOD4G:
1565 device_id = DEVICE_IPOD4G;
1566 break;
1567
1568 case BDID_APPLETV2:
1569 device_id = DEVICE_APPLETV2;
1570 break;
1571
1572 case BDID_IPHONE42:
1573 device_id = DEVICE_IPHONE42;
1574 break;
1575
1576 default:
1577 device_id = DEVICE_UNKNOWN;
1578 break;
1579 }
1580 break;
1581
1582 case CPID_IPAD21:
1583 // iPad2,1 iPad2,2 iPad2,3 and iPhone4,1 share the same ChipID, so we need to check the BoardID
1584 if (irecv_get_bdid(client, &bdid) < 0) {
1585 break;
1586 }
1587
1588 switch (bdid) {
1589 case BDID_IPAD21:
1590 device_id = DEVICE_IPAD21;
1591 break;
1592
1593 case BDID_IPAD22:
1594 device_id = DEVICE_IPAD22;
1595 break;
1596
1597 case BDID_IPAD23:
1598 device_id = DEVICE_IPAD23;
1599 break;
1600
1601 case BDID_IPHONE4S:
1602 device_id = DEVICE_IPHONE4S;
1603 break;
1604
1605 default:
1606 device_id = DEVICE_UNKNOWN;
1607 break;
1608 }
1609 break;
1610
1611 case CPID_APPLETV31:
1612 // AppleTV 3rd gen. iPad2,4, iPad 2,5 and iPod5,1 share the same ChipID, so we need to check the BoardID
1613 if (irecv_get_bdid(client, &bdid) < 0) {
1614 break;
1615 }
1616 switch (bdid) {
1617 case BDID_APPLETV31:
1618 device_id = DEVICE_APPLETV31;
1619 break;
1620 case BDID_IPAD24:
1621 device_id = DEVICE_IPAD24;
1622 break;
1623 case BDID_IPAD25:
1624 device_id = DEVICE_IPAD25;
1625 break;
1626 case BDID_IPOD5G:
1627 device_id = DEVICE_IPOD5G;
1628 break;
1629 default:
1630 device_id = DEVICE_UNKNOWN;
1631 break;
1632 }
1633 break;
1634
1635 case CPID_IPHONE5:
1636 if (irecv_get_bdid(client, &bdid) < 0) {
1637 break;
1638 }
1639 switch (bdid) {
1640 case BDID_IPHONE51:
1641 device_id = DEVICE_IPHONE51;
1642 break;
1643 case BDID_IPHONE52:
1644 device_id = DEVICE_IPHONE52;
1645 break;
1646 default:
1647 device_id = DEVICE_UNKNOWN;
1648 break;
1649 }
1650 break;
1651 1513
1652 case CPID_IPAD34: 1514 for (i = 0; irecv_devices[i].model != NULL; i++) {
1653 if (irecv_get_bdid(client, &bdid) < 0) { 1515 if (irecv_devices[i].chip_id == cpid && irecv_devices[i].board_id == bdid) {
1654 break; 1516 device_id = irecv_devices[i].index;
1655 }
1656 switch (bdid) {
1657 case BDID_IPAD34:
1658 device_id = DEVICE_IPAD34;
1659 break;
1660 default:
1661 device_id = DEVICE_UNKNOWN;
1662 break;
1663 } 1517 }
1664 break;
1665
1666 default:
1667 device_id = DEVICE_UNKNOWN;
1668 break;
1669 } 1518 }
1670 1519
1671 *device = &irecv_devices[device_id]; 1520 *device = &irecv_devices[device_id];