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) {
int device_id = DEVICE_UNKNOWN;
uint32_t bdid = 0;
uint32_t cpid = 0;
+ int i = 0;
if (irecv_get_cpid(client, &cpid) < 0) {
return IRECV_E_UNKNOWN_ERROR;
}
- switch (cpid) {
- case CPID_IPHONE2G:
- // iPhone1,1 iPhone1,2 and iPod1,1 all share the same ChipID
- // so we need to check the BoardID
- if (irecv_get_bdid(client, &bdid) < 0) {
- break;
- }
-
- switch (bdid) {
- case BDID_IPHONE2G:
- device_id = DEVICE_IPHONE2G;
- break;
-
- case BDID_IPHONE3G:
- device_id = DEVICE_IPHONE3G;
- break;
-
- case BDID_IPOD1G:
- device_id = DEVICE_IPOD1G;
- break;
-
- default:
- device_id = DEVICE_UNKNOWN;
- break;
- }
- break;
-
- case CPID_IPHONE3GS:
- device_id = DEVICE_IPHONE3GS;
- break;
-
- case CPID_IPOD2G:
- device_id = DEVICE_IPOD2G;
- break;
-
- case CPID_IPOD3G:
- device_id = DEVICE_IPOD3G;
- break;
-
- case CPID_IPAD1G:
- // iPhone3,1 iPhone3,3 iPad4,1 and iPad1,1 all share the same ChipID
- // so we need to check the BoardID
- if (irecv_get_bdid(client, &bdid) < 0) {
- break;
- }
-
- switch (bdid) {
- case BDID_IPAD1G:
- device_id = DEVICE_IPAD1G;
- break;
-
- case BDID_IPHONE4:
- device_id = DEVICE_IPHONE4;
- break;
-
- case BDID_IPOD4G:
- device_id = DEVICE_IPOD4G;
- break;
-
- case BDID_APPLETV2:
- device_id = DEVICE_APPLETV2;
- break;
-
- case BDID_IPHONE42:
- device_id = DEVICE_IPHONE42;
- break;
-
- default:
- device_id = DEVICE_UNKNOWN;
- break;
- }
- break;
-
- case CPID_IPAD21:
- // iPad2,1 iPad2,2 iPad2,3 and iPhone4,1 share the same ChipID, so we need to check the BoardID
- if (irecv_get_bdid(client, &bdid) < 0) {
- break;
- }
-
- switch (bdid) {
- case BDID_IPAD21:
- device_id = DEVICE_IPAD21;
- break;
-
- case BDID_IPAD22:
- device_id = DEVICE_IPAD22;
- break;
-
- case BDID_IPAD23:
- device_id = DEVICE_IPAD23;
- break;
-
- case BDID_IPHONE4S:
- device_id = DEVICE_IPHONE4S;
- break;
-
- default:
- device_id = DEVICE_UNKNOWN;
- break;
- }
- break;
-
- case CPID_APPLETV31:
- // AppleTV 3rd gen. iPad2,4, iPad 2,5 and iPod5,1 share the same ChipID, so we need to check the BoardID
- if (irecv_get_bdid(client, &bdid) < 0) {
- break;
- }
- switch (bdid) {
- case BDID_APPLETV31:
- device_id = DEVICE_APPLETV31;
- break;
- case BDID_IPAD24:
- device_id = DEVICE_IPAD24;
- break;
- case BDID_IPAD25:
- device_id = DEVICE_IPAD25;
- break;
- case BDID_IPOD5G:
- device_id = DEVICE_IPOD5G;
- break;
- default:
- device_id = DEVICE_UNKNOWN;
- break;
- }
- break;
-
- case CPID_IPHONE5:
- if (irecv_get_bdid(client, &bdid) < 0) {
- break;
- }
- switch (bdid) {
- case BDID_IPHONE51:
- device_id = DEVICE_IPHONE51;
- break;
- case BDID_IPHONE52:
- device_id = DEVICE_IPHONE52;
- break;
- default:
- device_id = DEVICE_UNKNOWN;
- break;
- }
- break;
+ if (irecv_get_bdid(client, &bdid) < 0) {
+ return IRECV_E_UNKNOWN_ERROR;
+ }
- case CPID_IPAD34:
- if (irecv_get_bdid(client, &bdid) < 0) {
- break;
- }
- switch (bdid) {
- case BDID_IPAD34:
- device_id = DEVICE_IPAD34;
- break;
- default:
- device_id = DEVICE_UNKNOWN;
- break;
+ for (i = 0; irecv_devices[i].model != NULL; i++) {
+ if (irecv_devices[i].chip_id == cpid && irecv_devices[i].board_id == bdid) {
+ device_id = irecv_devices[i].index;
}
- break;
-
- default:
- device_id = DEVICE_UNKNOWN;
- break;
}
*device = &irecv_devices[device_id];