summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--include/libirecovery.h167
-rw-r--r--src/libirecovery.c165
2 files changed, 70 insertions, 262 deletions
diff --git a/include/libirecovery.h b/include/libirecovery.h
index e7cd30d..fb18ce1 100644
--- a/include/libirecovery.h
+++ b/include/libirecovery.h
@@ -38,86 +38,8 @@ extern "C" {
38#endif 38#endif
39 39
40#define APPLE_VENDOR_ID 0x05AC 40#define APPLE_VENDOR_ID 0x05AC
41 41#define CPID_UNKNOWN -1
42#define CPID_UNKNOWN -1 42#define BDID_UNKNOWN -1
43#define CPID_IPHONE2G 0x8900
44#define CPID_IPOD1G 0x8900
45#define CPID_IPHONE3G 0x8900
46#define CPID_IPOD2G 0x8720
47#define CPID_IPHONE3GS 0x8920
48#define CPID_IPOD3G 0x8922
49#define CPID_IPAD1G 0x8930
50#define CPID_IPHONE4 0x8930
51#define CPID_IPOD4G 0x8930
52#define CPID_APPLETV2 0x8930
53#define CPID_IPHONE42 0x8930
54#define CPID_IPAD21 0x8940
55#define CPID_IPAD22 0x8940
56#define CPID_IPAD23 0x8940
57#define CPID_IPHONE4S 0x8940
58#define CPID_APPLETV31 0x8942
59#define CPID_IPAD24 0x8942
60#define CPID_IPAD25 0x8942
61#define CPID_IPOD5G 0x8942
62#define CPID_IPAD31 0x8945
63#define CPID_IPAD32 0x8945
64#define CPID_IPAD33 0x8945
65#define CPID_IPHONE5 0x8950
66#define CPID_IPAD34 0x8955
67
68#define BDID_UNKNOWN -1
69#define BDID_IPHONE2G 0x00
70#define BDID_IPOD1G 0x02
71#define BDID_IPHONE3G 0x04
72#define BDID_IPOD2G 0x00
73#define BDID_IPHONE3GS 0x00
74#define BDID_IPOD3G 0x02
75#define BDID_IPAD1G 0x02
76#define BDID_IPHONE4 0x00
77#define BDID_IPOD4G 0x08
78#define BDID_APPLETV2 0x10
79#define BDID_IPHONE42 0x06
80#define BDID_IPAD21 0x04
81#define BDID_IPAD22 0x06
82#define BDID_IPAD23 0x02
83#define BDID_IPHONE4S 0x08
84#define BDID_APPLETV31 0x08
85#define BDID_IPAD24 0x06
86#define BDID_IPAD25 0x0a
87#define BDID_IPOD5G 0x00
88#define BDID_IPAD31 0x00
89#define BDID_IPAD32 0x02
90#define BDID_IPAD33 0x04
91#define BDID_IPHONE51 0x00
92#define BDID_IPHONE52 0x02
93#define BDID_IPAD34 0x00
94
95#define DEVICE_UNKNOWN -1
96#define DEVICE_IPHONE2G 0
97#define DEVICE_IPOD1G 1
98#define DEVICE_IPHONE3G 2
99#define DEVICE_IPOD2G 3
100#define DEVICE_IPHONE3GS 4
101#define DEVICE_IPOD3G 5
102#define DEVICE_IPAD1G 6
103#define DEVICE_IPHONE4 7
104#define DEVICE_IPOD4G 8
105#define DEVICE_APPLETV2 9
106#define DEVICE_IPHONE42 10
107#define DEVICE_IPAD21 11
108#define DEVICE_IPAD22 12
109#define DEVICE_IPAD23 13
110#define DEVICE_IPHONE4S 14
111#define DEVICE_APPLETV31 15
112#define DEVICE_IPAD24 16
113#define DEVICE_IPAD31 17
114#define DEVICE_IPAD32 18
115#define DEVICE_IPAD33 19
116#define DEVICE_IPHONE51 20
117#define DEVICE_IPHONE52 21
118#define DEVICE_IPOD5G 22
119#define DEVICE_IPAD25 23
120#define DEVICE_IPAD34 24
121 43
122enum { 44enum {
123 kRecoveryMode1 = 0x1280, 45 kRecoveryMode1 = 0x1280,
@@ -191,6 +113,38 @@ struct irecv_client {
191 irecv_event_cb_t disconnected_callback; 113 irecv_event_cb_t disconnected_callback;
192}; 114};
193 115
116#define DEVICE_UNKNOWN -1
117#define DEVICE_IPHONE2G 0
118#define DEVICE_IPHONE3G 1
119#define DEVICE_IPHONE3GS 2
120#define DEVICE_IPHONE4 3
121#define DEVICE_IPHONE4REVA 4
122#define DEVICE_IPHONE4CDMA 5
123#define DEVICE_IPHONE4S 6
124#define DEVICE_IPHONE51 7
125#define DEVICE_IPHONE52 8
126#define DEVICE_IPOD1G 9
127#define DEVICE_IPOD2G 10
128#define DEVICE_IPOD3G 11
129#define DEVICE_IPOD4G 12
130#define DEVICE_IPOD5G 13
131#define DEVICE_IPAD1G 14
132#define DEVICE_IPAD21 15
133#define DEVICE_IPAD22 16
134#define DEVICE_IPAD23 17
135#define DEVICE_IPAD24 18
136#define DEVICE_IPAD25 19
137#define DEVICE_IPAD26 20
138#define DEVICE_IPAD27 21
139#define DEVICE_IPAD31 22
140#define DEVICE_IPAD32 23
141#define DEVICE_IPAD33 24
142#define DEVICE_IPAD34 25
143#define DEVICE_IPAD35 26
144#define DEVICE_IPAD36 27
145#define DEVICE_APPLETV2 28
146#define DEVICE_APPLETV31 29
147
194struct irecv_device { 148struct irecv_device {
195 int index; 149 int index;
196 const char* product; 150 const char* product;
@@ -201,30 +155,35 @@ struct irecv_device {
201 155
202static struct irecv_device irecv_devices[] = { 156static struct irecv_device irecv_devices[] = {
203 { 0, "iPhone1,1", "m68ap", 0x00, 0x8900 }, 157 { 0, "iPhone1,1", "m68ap", 0x00, 0x8900 },
204 { 1, "iPod1,1", "n45ap", 0x02, 0x8900 }, 158 { 1, "iPhone1,2", "n82ap", 0x04, 0x8900 },
205 { 2, "iPhone1,2", "n82ap", 0x04, 0x8900 }, 159 { 2, "iPhone2,1", "n88ap", 0x00, 0x8920 },
206 { 3, "iPod2,1", "n72ap", 0x00, 0x8720 }, 160 { 3, "iPhone3,1", "n90ap", 0x00, 0x8930 },
207 { 4, "iPhone2,1", "n88ap", 0x00, 0x8920 }, 161 { 4, "iPhone3,2", "n90bap", 0x04, 0x8930 },
208 { 5, "iPod3,1", "n18ap", 0x02, 0x8922 }, 162 { 5, "iPhone3,3", "n92ap", 0x06, 0x8930 },
209 { 6, "iPad1,1", "k48ap", 0x02, 0x8930 }, 163 { 6, "iPhone4,1", "n94ap", 0x08, 0x8940 },
210 { 7, "iPhone3,1", "n90ap", 0x00, 0x8930 }, 164 { 7, "iPhone5,1", "n41ap", 0x00, 0x8950 },
211 { 8, "iPod4,1", "n81ap", 0x08, 0x8930 }, 165 { 8, "iPhone5,2", "n42ap", 0x02, 0x8950 },
212 { 9, "AppleTV2,1", "k66ap", 0x10, 0x8930 }, 166 { 9, "iPod1,1", "n45ap", 0x02, 0x8900 },
213 { 10, "iPhone3,3", "n92ap", 0x06, 0x8930 }, 167 { 10, "iPod2,1", "n72ap", 0x00, 0x8720 },
214 { 11, "iPad2,1", "k93ap", 0x04, 0x8940 }, 168 { 11, "iPod3,1", "n18ap", 0x02, 0x8922 },
215 { 12, "iPad2,2", "k94ap", 0x06, 0x8940 }, 169 { 12, "iPod4,1", "n81ap", 0x08, 0x8930 },
216 { 13, "iPad2,3", "k95ap", 0x02, 0x8940 }, 170 { 13, "iPod5,1", "n78ap", 0x00, 0x8942 },
217 { 14, "iPhone4,1", "n94ap", 0x08, 0x8940 }, 171 { 14, "iPad1,1", "k48ap", 0x02, 0x8930 },
218 { 15, "AppleTV3,1", "j33ap", 0x08, 0x8942 }, 172 { 15, "iPad2,1", "k93ap", 0x04, 0x8940 },
219 { 16, "iPad2,4", "k93aap",0x06, 0x8942 }, 173 { 16, "iPad2,2", "k94ap", 0x06, 0x8940 },
220 { 17, "iPad3,1", "j1ap", 0x00, 0x8945 }, 174 { 17, "iPad2,3", "k95ap", 0x02, 0x8940 },
221 { 18, "iPad3,2", "j2ap", 0x02, 0x8945 }, 175 { 18, "iPad2,4", "k93aap", 0x06, 0x8942 },
222 { 19, "iPad3,3", "j2aap", 0x04, 0x8945 }, 176 { 19, "iPad2,5", "p105ap", 0x0a, 0x8942 },
223 { 20, "iPhone5,1", "n41ap", 0x00, 0x8950 }, 177 { 20, "iPad2,6", "p106ap", 0x0c, 0x8942 },
224 { 21, "iPhone5,2", "n42ap", 0x02, 0x8950 }, 178 { 21, "iPad2,7", "p107ap", 0x0e, 0x8942 },
225 { 22, "iPod5,1", "n78ap", 0x00, 0x8942 }, 179 { 22, "iPad3,1", "j1ap", 0x00, 0x8945 },
226 { 23, "iPad2,5", "p105ap", 0x0a, 0x8942 }, 180 { 23, "iPad3,2", "j2ap", 0x02, 0x8945 },
227 { 24, "iPad3,4", "p101ap", 0x00, 0x8955 }, 181 { 24, "iPad3,3", "j2aap", 0x04, 0x8945 },
182 { 25, "iPad3,4", "p101ap", 0x00, 0x8955 },
183 { 26, "iPad3,5", "p102ap", 0x02, 0x8955 },
184 { 27, "iPad3,6", "p103ap", 0x04, 0x8955 },
185 { 28, "AppleTV2,1", "k66ap", 0x10, 0x8930 },
186 { 29, "AppleTV3,1", "j33ap", 0x08, 0x8942 },
228 { -1, NULL, NULL, -1, -1 } 187 { -1, NULL, NULL, -1, -1 }
229}; 188};
230 189
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];