diff options
| author | 2010-01-08 20:22:47 +0100 | |
|---|---|---|
| committer | 2010-01-08 20:22:47 +0100 | |
| commit | 3d157a4762119e28433003e42f4af469e32ba860 (patch) | |
| tree | 5ab48137b18036dc87a11451168d4116e8f0b8c5 | |
| parent | 9cc97faebcaabd6af2f9cc9280ba6a0f8cd85e60 (diff) | |
| download | libimobiledevice-3d157a4762119e28433003e42f4af469e32ba860.tar.gz libimobiledevice-3d157a4762119e28433003e42f4af469e32ba860.tar.bz2 | |
Implement lockdown activate and deactive
Passing the right activiation record allows activating a phone using
this functionality.
| -rw-r--r-- | include/libiphone/lockdown.h | 3 | ||||
| -rw-r--r-- | src/lockdown.c | 88 |
2 files changed, 91 insertions, 0 deletions
diff --git a/include/libiphone/lockdown.h b/include/libiphone/lockdown.h index da684c6..f076cf2 100644 --- a/include/libiphone/lockdown.h +++ b/include/libiphone/lockdown.h | |||
| @@ -44,6 +44,7 @@ extern "C" { | |||
| 44 | #define LOCKDOWN_E_GET_VALUE_PROHIBITED -10 | 44 | #define LOCKDOWN_E_GET_VALUE_PROHIBITED -10 |
| 45 | #define LOCKDOWN_E_REMOVE_VALUE_PROHIBITED -11 | 45 | #define LOCKDOWN_E_REMOVE_VALUE_PROHIBITED -11 |
| 46 | #define LOCKDOWN_E_MUX_ERROR -12 | 46 | #define LOCKDOWN_E_MUX_ERROR -12 |
| 47 | #define LOCKDOWN_E_ACTIVATION_FAILED -13 | ||
| 47 | 48 | ||
| 48 | #define LOCKDOWN_E_UNKNOWN_ERROR -256 | 49 | #define LOCKDOWN_E_UNKNOWN_ERROR -256 |
| 49 | 50 | ||
| @@ -67,6 +68,8 @@ lockdownd_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist); | |||
| 67 | lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *host_id); | 68 | lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *host_id); |
| 68 | lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, char *host_id); | 69 | lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, char *host_id); |
| 69 | lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, char *host_id); | 70 | lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, char *host_id); |
| 71 | lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record); | ||
| 72 | lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client); | ||
| 70 | lockdownd_error_t lockdownd_get_device_uuid(lockdownd_client_t control, char **uuid); | 73 | lockdownd_error_t lockdownd_get_device_uuid(lockdownd_client_t control, char **uuid); |
| 71 | lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name); | 74 | lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name); |
| 72 | lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client); | 75 | lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client); |
diff --git a/src/lockdown.c b/src/lockdown.c index c27cd59..6ddd7c0 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -1385,3 +1385,91 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char | |||
| 1385 | return ret; | 1385 | return ret; |
| 1386 | } | 1386 | } |
| 1387 | 1387 | ||
| 1388 | /** | ||
| 1389 | * Activates the device. Only works within an open session. | ||
| 1390 | * The ActivationRecord plist dictionary must be obtained using the | ||
| 1391 | * activation protocol requesting from Apple's https webservice. | ||
| 1392 | * | ||
| 1393 | * @see http://iphone-docs.org/doku.php?id=docs:protocols:activation | ||
| 1394 | * | ||
| 1395 | * @param control The lockdown client | ||
| 1396 | * @param activation_record The activation record plist dictionary | ||
| 1397 | * | ||
| 1398 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | ||
| 1399 | */ | ||
| 1400 | lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record) | ||
| 1401 | { | ||
| 1402 | if (!client) | ||
| 1403 | return LOCKDOWN_E_INVALID_ARG; | ||
| 1404 | |||
| 1405 | if (!activation_record) | ||
| 1406 | return LOCKDOWN_E_INVALID_ARG; | ||
| 1407 | |||
| 1408 | lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; | ||
| 1409 | |||
| 1410 | plist_t dict = plist_new_dict(); | ||
| 1411 | plist_dict_add_label(dict, client->label); | ||
| 1412 | plist_dict_insert_item(dict,"Request", plist_new_string("Activate")); | ||
| 1413 | plist_dict_insert_item(dict,"ActivationRecord", activation_record); | ||
| 1414 | |||
| 1415 | ret = lockdownd_send(client, dict); | ||
| 1416 | plist_free(dict); | ||
| 1417 | dict = NULL; | ||
| 1418 | |||
| 1419 | ret = lockdownd_recv(client, &dict); | ||
| 1420 | if (!dict) { | ||
| 1421 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: LOCKDOWN_E_PLIST_ERROR\n", __func__); | ||
| 1422 | return LOCKDOWN_E_PLIST_ERROR; | ||
| 1423 | } | ||
| 1424 | |||
| 1425 | ret = LOCKDOWN_E_ACTIVATION_FAILED; | ||
| 1426 | if (lockdown_check_result(dict, "Activate") == RESULT_SUCCESS) { | ||
| 1427 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); | ||
| 1428 | ret = LOCKDOWN_E_SUCCESS; | ||
| 1429 | } | ||
| 1430 | plist_free(dict); | ||
| 1431 | dict = NULL; | ||
| 1432 | |||
| 1433 | return ret; | ||
| 1434 | } | ||
| 1435 | |||
| 1436 | /** | ||
| 1437 | * Deactivates the device, returning it to the locked | ||
| 1438 | * “Activate with iTunes” screen. | ||
| 1439 | * | ||
| 1440 | * @param control The lockdown client | ||
| 1441 | * | ||
| 1442 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | ||
| 1443 | */ | ||
| 1444 | lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client) | ||
| 1445 | { | ||
| 1446 | if (!client) | ||
| 1447 | return LOCKDOWN_E_INVALID_ARG; | ||
| 1448 | |||
| 1449 | lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; | ||
| 1450 | |||
| 1451 | plist_t dict = plist_new_dict(); | ||
| 1452 | plist_dict_add_label(dict, client->label); | ||
| 1453 | plist_dict_insert_item(dict,"Request", plist_new_string("Deactivate")); | ||
| 1454 | |||
| 1455 | ret = lockdownd_send(client, dict); | ||
| 1456 | plist_free(dict); | ||
| 1457 | dict = NULL; | ||
| 1458 | |||
| 1459 | ret = lockdownd_recv(client, &dict); | ||
| 1460 | if (!dict) { | ||
| 1461 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: LOCKDOWN_E_PLIST_ERROR\n", __func__); | ||
| 1462 | return LOCKDOWN_E_PLIST_ERROR; | ||
| 1463 | } | ||
| 1464 | |||
| 1465 | ret = LOCKDOWN_E_UNKNOWN_ERROR; | ||
| 1466 | if (lockdown_check_result(dict, "Deactivate") == RESULT_SUCCESS) { | ||
| 1467 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); | ||
| 1468 | ret = LOCKDOWN_E_SUCCESS; | ||
| 1469 | } | ||
| 1470 | plist_free(dict); | ||
| 1471 | dict = NULL; | ||
| 1472 | |||
| 1473 | return ret; | ||
| 1474 | } | ||
| 1475 | |||
