diff options
| author | 2009-04-17 13:48:39 +0200 | |
|---|---|---|
| committer | 2009-04-17 13:48:39 +0200 | |
| commit | 8cc8ac0157aaa901a43b70c1dfb3d1f4c7b443fe (patch) | |
| tree | 176e662858aeed20e200498106d7d51c5fb4af15 | |
| parent | a5245005b41cbae1ccee805fbef8d3e343c9b312 (diff) | |
| download | usbmuxd-8cc8ac0157aaa901a43b70c1dfb3d1f4c7b443fe.tar.gz usbmuxd-8cc8ac0157aaa901a43b70c1dfb3d1f4c7b443fe.tar.bz2 | |
Fixed datatypes and added a comment for 'recv_from_phone_timeout'
| -rw-r--r-- | iphone.c | 64 |
1 files changed, 34 insertions, 30 deletions
| @@ -30,16 +30,12 @@ | |||
| 30 | #define BULKOUT 0x04 | 30 | #define BULKOUT 0x04 |
| 31 | #define HEADERLEN 28 | 31 | #define HEADERLEN 28 |
| 32 | 32 | ||
| 33 | typedef uint16_t uint16; | 33 | static const uint8_t TCP_FIN = 1; |
| 34 | typedef uint32_t uint32; | 34 | static const uint8_t TCP_SYN = 1 << 1; |
| 35 | typedef uint8_t uint8; | 35 | static const uint8_t TCP_RST = 1 << 2; |
| 36 | 36 | static const uint8_t TCP_PSH = 1 << 3; | |
| 37 | static const uint8 TCP_FIN = 1; | 37 | static const uint8_t TCP_ACK = 1 << 4; |
| 38 | static const uint8 TCP_SYN = 1 << 1; | 38 | static const uint8_t TCP_URG = 1 << 5; |
| 39 | static const uint8 TCP_RST = 1 << 2; | ||
| 40 | static const uint8 TCP_PSH = 1 << 3; | ||
| 41 | static const uint8 TCP_ACK = 1 << 4; | ||
| 42 | static const uint8 TCP_URG = 1 << 5; | ||
| 43 | 39 | ||
| 44 | // I have trouble figuring out how to properly manage the windowing to | 40 | // I have trouble figuring out how to properly manage the windowing to |
| 45 | // the iPhone. It keeps sending back 512 and seems to drop off a cliff | 41 | // the iPhone. It keeps sending back 512 and seems to drop off a cliff |
| @@ -50,8 +46,8 @@ static const uint8 TCP_URG = 1 << 5; | |||
| 50 | // Since I'm not sure how in the hell to interpret the window sizes that | 46 | // Since I'm not sure how in the hell to interpret the window sizes that |
| 51 | // the phone is sending back to us, I've figured out some magic number | 47 | // the phone is sending back to us, I've figured out some magic number |
| 52 | // constants which seem to work okay. | 48 | // constants which seem to work okay. |
| 53 | static const uint32 WINDOW_MAX = 5 * 1024; | 49 | static const uint32_t WINDOW_MAX = 5 * 1024; |
| 54 | static const uint32 WINDOW_INCREMENT = 512; | 50 | static const uint32_t WINDOW_INCREMENT = 512; |
| 55 | 51 | ||
| 56 | typedef struct { | 52 | typedef struct { |
| 57 | char* buffer; | 53 | char* buffer; |
| @@ -67,15 +63,15 @@ struct iphone_device_int { | |||
| 67 | }; | 63 | }; |
| 68 | 64 | ||
| 69 | typedef struct { | 65 | typedef struct { |
| 70 | uint32 type, length, major, minor, allnull; | 66 | uint32_t type, length, major, minor, allnull; |
| 71 | } usbmux_version_header; | 67 | } usbmux_version_header; |
| 72 | 68 | ||
| 73 | typedef struct { | 69 | typedef struct { |
| 74 | uint32 type, length; | 70 | uint32_t type, length; |
| 75 | uint16 sport, dport; | 71 | uint16_t sport, dport; |
| 76 | uint32 scnt, ocnt; | 72 | uint32_t scnt, ocnt; |
| 77 | uint8 offset, tcp_flags; | 73 | uint8_t offset, tcp_flags; |
| 78 | uint16 window, nullnull, length16; | 74 | uint16_t window, nullnull, length16; |
| 79 | } usbmux_tcp_header; | 75 | } usbmux_tcp_header; |
| 80 | 76 | ||
| 81 | struct iphone_umux_client_int { | 77 | struct iphone_umux_client_int { |
| @@ -93,7 +89,7 @@ struct iphone_umux_client_int { | |||
| 93 | // just record the most recent scnt that we are expecting to hear | 89 | // just record the most recent scnt that we are expecting to hear |
| 94 | // back on. We will actually halt progress by limiting the number | 90 | // back on. We will actually halt progress by limiting the number |
| 95 | // of outstanding un-acked bulk sends that we have beamed out. | 91 | // of outstanding un-acked bulk sends that we have beamed out. |
| 96 | uint32 wr_pending_scnt; | 92 | uint32_t wr_pending_scnt; |
| 97 | long wr_window; | 93 | long wr_window; |
| 98 | 94 | ||
| 99 | pthread_mutex_t mutex; | 95 | pthread_mutex_t mutex; |
| @@ -526,7 +522,15 @@ int send_to_phone(iphone_device_t phone, char *data, int datalen) | |||
| 526 | return bytes; | 522 | return bytes; |
| 527 | } | 523 | } |
| 528 | 524 | ||
| 529 | /** | 525 | /** Receives data from the phone |
| 526 | * This function is a low-level (i.e. direct from iPhone) function. | ||
| 527 | * | ||
| 528 | * @param phone The iPhone to receive data from | ||
| 529 | * @param data Where to put data read | ||
| 530 | * @param datalen How much data to read in | ||
| 531 | * @param timeout How many milliseconds to wait for data | ||
| 532 | * | ||
| 533 | * @return How many bytes were read in, or -1 on error. | ||
| 530 | */ | 534 | */ |
| 531 | int recv_from_phone_timeout(iphone_device_t phone, char *data, int datalen, int timeoutmillis) | 535 | int recv_from_phone_timeout(iphone_device_t phone, char *data, int datalen, int timeoutmillis) |
| 532 | { | 536 | { |
| @@ -589,7 +593,7 @@ int recv_from_phone(iphone_device_t phone, char *data, int datalen) { | |||
| 589 | * | 593 | * |
| 590 | * @return A USBMux packet | 594 | * @return A USBMux packet |
| 591 | */ | 595 | */ |
| 592 | usbmux_tcp_header *new_mux_packet(uint16 s_port, uint16 d_port) | 596 | usbmux_tcp_header *new_mux_packet(uint16_t s_port, uint16_t d_port) |
| 593 | { | 597 | { |
| 594 | usbmux_tcp_header *conn = (usbmux_tcp_header *) malloc(sizeof(usbmux_tcp_header)); | 598 | usbmux_tcp_header *conn = (usbmux_tcp_header *) malloc(sizeof(usbmux_tcp_header)); |
| 595 | conn->type = htonl(6); | 599 | conn->type = htonl(6); |
| @@ -828,7 +832,7 @@ iphone_error_t iphone_mux_send(iphone_umux_client_t client, const char *data, ui | |||
| 828 | pthread_mutex_lock(&client->mutex); | 832 | pthread_mutex_lock(&client->mutex); |
| 829 | 833 | ||
| 830 | int sendresult = 0; | 834 | int sendresult = 0; |
| 831 | uint32 blocksize = 0; | 835 | uint32_t blocksize = 0; |
| 832 | if (client->wr_window <= 0) { | 836 | if (client->wr_window <= 0) { |
| 833 | struct timespec ts; | 837 | struct timespec ts; |
| 834 | clock_gettime(CLOCK_REALTIME, &ts); | 838 | clock_gettime(CLOCK_REALTIME, &ts); |
| @@ -903,14 +907,14 @@ iphone_error_t iphone_mux_send(iphone_umux_client_t client, const char *data, ui | |||
| 903 | * | 907 | * |
| 904 | * @return number of bytes consumed (header + data) | 908 | * @return number of bytes consumed (header + data) |
| 905 | */ | 909 | */ |
| 906 | uint32 append_receive_buffer(iphone_umux_client_t client, char* packet) | 910 | uint32_t append_receive_buffer(iphone_umux_client_t client, char* packet) |
| 907 | { | 911 | { |
| 908 | if (client == NULL || packet == NULL) return 0; | 912 | if (client == NULL || packet == NULL) return 0; |
| 909 | 913 | ||
| 910 | usbmux_tcp_header *header = (usbmux_tcp_header *) packet; | 914 | usbmux_tcp_header *header = (usbmux_tcp_header *) packet; |
| 911 | char* data = &packet[HEADERLEN]; | 915 | char* data = &packet[HEADERLEN]; |
| 912 | uint32 packetlen = ntohl(header->length); | 916 | uint32_t packetlen = ntohl(header->length); |
| 913 | uint32 datalen = packetlen-HEADERLEN; | 917 | uint32_t datalen = packetlen-HEADERLEN; |
| 914 | 918 | ||
| 915 | int dobroadcast = 0; | 919 | int dobroadcast = 0; |
| 916 | 920 | ||
| @@ -1053,14 +1057,14 @@ iphone_umux_client_t find_client(usbmux_tcp_header* recv_header) | |||
| 1053 | iphone_umux_client_t retval = NULL; | 1057 | iphone_umux_client_t retval = NULL; |
| 1054 | 1058 | ||
| 1055 | // just for debugging check, I'm going to convert the numbers to host-endian. | 1059 | // just for debugging check, I'm going to convert the numbers to host-endian. |
| 1056 | uint16 hsport = ntohs(recv_header->sport); | 1060 | uint16_t hsport = ntohs(recv_header->sport); |
| 1057 | uint16 hdport = ntohs(recv_header->dport); | 1061 | uint16_t hdport = ntohs(recv_header->dport); |
| 1058 | 1062 | ||
| 1059 | pthread_mutex_lock(&iphonemutex); | 1063 | pthread_mutex_lock(&iphonemutex); |
| 1060 | int i; | 1064 | int i; |
| 1061 | for (i = 0; i < clients; i++) { | 1065 | for (i = 0; i < clients; i++) { |
| 1062 | uint16 csport = ntohs(connlist[i]->header->sport); | 1066 | uint16_t csport = ntohs(connlist[i]->header->sport); |
| 1063 | uint16 cdport = ntohs(connlist[i]->header->dport); | 1067 | uint16_t cdport = ntohs(connlist[i]->header->dport); |
| 1064 | 1068 | ||
| 1065 | if (hsport == cdport && hdport == csport) { | 1069 | if (hsport == cdport && hdport == csport) { |
| 1066 | retval = connlist[i]; | 1070 | retval = connlist[i]; |
| @@ -1118,7 +1122,7 @@ int iphone_mux_pullbulk(iphone_device_t phone) | |||
| 1118 | 1122 | ||
| 1119 | // now that we have a header, check if there is sufficient data | 1123 | // now that we have a header, check if there is sufficient data |
| 1120 | // to construct a full packet, including its data | 1124 | // to construct a full packet, including its data |
| 1121 | uint32 packetlen = ntohl(header->length); | 1125 | uint32_t packetlen = ntohl(header->length); |
| 1122 | if (phone->usbReceive.leftover < packetlen) { | 1126 | if (phone->usbReceive.leftover < packetlen) { |
| 1123 | fprintf(stderr, "%s: not enough data to construct a full packet\n", __func__); | 1127 | fprintf(stderr, "%s: not enough data to construct a full packet\n", __func__); |
| 1124 | break; | 1128 | break; |
