summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/AFC.c17
-rw-r--r--src/AFC.h2
-rw-r--r--src/Makefile.am12
-rw-r--r--src/afccheck.c136
4 files changed, 159 insertions, 8 deletions
diff --git a/src/AFC.c b/src/AFC.c
index 4d6b269..144efe1 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -34,10 +34,11 @@ const int MAXIMUM_PACKET_SIZE = (2 << 15) - 32;
34static void afc_lock(iphone_afc_client_t client) 34static void afc_lock(iphone_afc_client_t client)
35{ 35{
36 log_debug_msg("Locked\n"); 36 log_debug_msg("Locked\n");
37 while (client->lock) { 37 /*while (client->lock) {
38 usleep(500); // they say it's obsolete, but whatever 38 usleep(500); // they say it's obsolete, but whatever
39 } 39 }
40 client->lock = 1; 40 client->lock = 1; */
41 g_mutex_lock(client->mutex);
41} 42}
42 43
43/** Unlocks an AFC client, done for thread safety stuff. 44/** Unlocks an AFC client, done for thread safety stuff.
@@ -47,7 +48,8 @@ static void afc_lock(iphone_afc_client_t client)
47static void afc_unlock(iphone_afc_client_t client) 48static void afc_unlock(iphone_afc_client_t client)
48{ // just to be pretty 49{ // just to be pretty
49 log_debug_msg("Unlocked\n"); 50 log_debug_msg("Unlocked\n");
50 client->lock = 0; 51 //client->lock = 0;
52 g_mutex_unlock(client->mutex);
51} 53}
52 54
53/** Makes a connection to the AFC service on the phone. 55/** Makes a connection to the AFC service on the phone.
@@ -61,6 +63,10 @@ static void afc_unlock(iphone_afc_client_t client)
61iphone_error_t iphone_afc_new_client(iphone_device_t device, int src_port, int dst_port, iphone_afc_client_t * client) 63iphone_error_t iphone_afc_new_client(iphone_device_t device, int src_port, int dst_port, iphone_afc_client_t * client)
62{ 64{
63 int ret = IPHONE_E_SUCCESS; 65 int ret = IPHONE_E_SUCCESS;
66
67 //makes sure thread environment is available
68 if (!g_thread_supported())
69 g_thread_init(NULL);
64 iphone_afc_client_t client_loc = (iphone_afc_client_t) malloc(sizeof(struct iphone_afc_client_int)); 70 iphone_afc_client_t client_loc = (iphone_afc_client_t) malloc(sizeof(struct iphone_afc_client_int));
65 71
66 if (!device) 72 if (!device)
@@ -92,6 +98,7 @@ iphone_error_t iphone_afc_new_client(iphone_device_t device, int src_port, int d
92 client_loc->afc_packet->header2 = 0x4141504C; 98 client_loc->afc_packet->header2 = 0x4141504C;
93 client_loc->file_handle = 0; 99 client_loc->file_handle = 0;
94 client_loc->lock = 0; 100 client_loc->lock = 0;
101 client_loc->mutex = g_mutex_new();
95 102
96 *client = client_loc; 103 *client = client_loc;
97 return IPHONE_E_SUCCESS; 104 return IPHONE_E_SUCCESS;
diff --git a/src/AFC.h b/src/AFC.h
index f05d831..463c13e 100644
--- a/src/AFC.h
+++ b/src/AFC.h
@@ -26,6 +26,7 @@
26#include <stdio.h> 26#include <stdio.h>
27#include <stdlib.h> 27#include <stdlib.h>
28#include <sys/stat.h> 28#include <sys/stat.h>
29#include <glib.h>
29 30
30typedef struct { 31typedef struct {
31 uint32 header1, header2; 32 uint32 header1, header2;
@@ -46,6 +47,7 @@ struct iphone_afc_client_int {
46 AFCPacket *afc_packet; 47 AFCPacket *afc_packet;
47 int file_handle; 48 int file_handle;
48 int lock; 49 int lock;
50 GMutex *mutex;
49}; 51};
50 52
51struct iphone_afc_file_int { 53struct iphone_afc_file_int {
diff --git a/src/Makefile.am b/src/Makefile.am
index a8f7cbf..24fc4aa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,12 +1,12 @@
1INCLUDES = -I$(top_srcdir)/include 1INCLUDES = -I$(top_srcdir)/include
2 2
3AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) -g 3AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) -g
4AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) 4AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS)
5 5
6bin_PROGRAMS = libiphone-initconf 6bin_PROGRAMS = libiphone-initconf
7 7
8if BUILD_DEV_TOOLS 8if BUILD_DEV_TOOLS
9 bin_PROGRAMS = iphoneclient libiphone-initconf lckd-client 9 bin_PROGRAMS = iphoneclient libiphone-initconf lckd-client afccheck
10 iphoneclient_SOURCES = main.c 10 iphoneclient_SOURCES = main.c
11 iphoneclient_LDADD = libiphone.la 11 iphoneclient_LDADD = libiphone.la
12 12
@@ -14,11 +14,17 @@ if BUILD_DEV_TOOLS
14 lckd_client_CFLAGS = $(AM_CFLAGS) 14 lckd_client_CFLAGS = $(AM_CFLAGS)
15 lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS) 15 lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS)
16 lckd_client_LDADD = libiphone.la 16 lckd_client_LDADD = libiphone.la
17
18 afccheck_SOURCES = afccheck.c
19 afccheck_CFLAGS = $(AM_CFLAGS)
20 afccheck_LDFLAGS = $(AM_LDFLAGS)
21 afccheck_LDADD = libiphone.la
17endif 22endif
18 23
19libiphone_initconf_SOURCES = initconf.c userpref.c lockdown.c plist.c usbmux.c iphone.c utils.c 24libiphone_initconf_SOURCES = initconf.c userpref.c lockdown.c plist.c usbmux.c iphone.c utils.c
20libiphone_initconf_CFLAGS = $(libgthread2_CFLAGS) $(AM_CFLAGS) 25libiphone_initconf_CFLAGS = $(libgthread2_CFLAGS) $(AM_CFLAGS)
21libiphone_initconf_LDFLAGS = $(libgthread2_LIBS) $(AM_LDFLAGS) 26libiphone_initconf_LDFLAGS = $(libgthread2_LIBS) $(AM_LDFLAGS)
22 27
28
23lib_LTLIBRARIES = libiphone.la 29lib_LTLIBRARIES = libiphone.la
24libiphone_la_SOURCES = usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c utils.c 30libiphone_la_SOURCES = usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c utils.c
diff --git a/src/afccheck.c b/src/afccheck.c
new file mode 100644
index 0000000..e772d99
--- /dev/null
+++ b/src/afccheck.c
@@ -0,0 +1,136 @@
1/*
2 * afccheck.c
3 * creates threads and check communication through AFC is done rigth
4 *
5 * Copyright (c) 2008 Jonathan Beck All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdio.h>
23#include <string.h>
24#include <glib.h>
25
26#include "usbmux.h"
27#include "iphone.h"
28#include <libiphone/libiphone.h>
29
30#define BUFFER_SIZE 20000
31#define NB_THREADS 10
32
33int debug = 0;
34
35typedef struct {
36 iphone_afc_client_t afc;
37 int id;
38} param;
39
40
41void check_afc(gpointer data)
42{
43 //prepare a buffer
44 int buffersize = BUFFER_SIZE * sizeof(int);
45 int *buf = (int *) malloc(buffersize);
46 int *buf2 = (int *) malloc(buffersize);
47 int bytes = 0;
48 //fill buffer
49 int i = 0;
50 for (i = 0; i < BUFFER_SIZE; i++) {
51 buf[i] = ((param *) data)->id * i;
52 }
53
54 //now writes buffer on iphone
55 iphone_afc_file_t file = NULL;
56 char path[50];
57 sprintf(path, "/Buf%i", ((param *) data)->id);
58 iphone_afc_open_file(((param *) data)->afc, path, IPHONE_AFC_FILE_WRITE, &file);
59 iphone_afc_write_file(((param *) data)->afc, file, (char *) buf, buffersize, &bytes);
60 iphone_afc_close_file(((param *) data)->afc, file);
61 file = NULL;
62 if (bytes != buffersize)
63 printf("Write operation failed\n");
64
65 //now read it
66 bytes = 0;
67 iphone_afc_open_file(((param *) data)->afc, path, IPHONE_AFC_FILE_READ, &file);
68 iphone_afc_read_file(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes);
69 iphone_afc_close_file(((param *) data)->afc, file);
70 if (bytes != buffersize)
71 printf("Read operation failed\n");
72
73 //compare buffers
74 for (i = 0; i < BUFFER_SIZE; i++) {
75 if (buf[i] != buf2[i]) {
76 printf("Buffers are differents, stream corrupted\n");
77 break;
78 }
79 }
80
81 //cleanup
82 iphone_afc_delete_file(((param *) data)->afc, path);
83 g_thread_exit(0);
84}
85
86int main(int argc, char *argv[])
87{
88 iphone_lckd_client_t control = NULL;
89 iphone_device_t phone = NULL;
90 GError *err;
91 int port = 0;
92 iphone_afc_client_t afc = NULL;
93
94 if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) {
95 printf("No iPhone found, is it plugged in?\n");
96 return 1;
97 }
98
99 if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) {
100 iphone_free_device(phone);
101 return 1;
102 }
103
104 if (IPHONE_E_SUCCESS == iphone_lckd_start_service(control, "com.apple.afc", &port) && !port) {
105 iphone_lckd_free_client(control);
106 iphone_free_device(phone);
107 fprintf(stderr, "Something went wrong when starting AFC.");
108 return 1;
109 }
110
111 iphone_afc_new_client(phone, 3432, port, &afc);
112
113 //makes sure thread environment is available
114 if (!g_thread_supported())
115 g_thread_init(NULL);
116
117 GThread *threads[NB_THREADS];
118 param data[NB_THREADS];
119
120 int i = 0;
121 for (i = 0; i < NB_THREADS; i++) {
122 data[i].afc = afc;
123 data[i].id = i + 1;
124 threads[i] = g_thread_create((GThreadFunc) check_afc, data + i, TRUE, &err);
125 }
126
127 for (i = 0; i < NB_THREADS; i++) {
128 g_thread_join(threads[i]);
129 }
130
131
132 iphone_lckd_free_client(control);
133 iphone_free_device(phone);
134
135 return 0;
136}