iPXE
iphone.h
Go to the documentation of this file.
1 #ifndef _IPHONE_H
2 #define _IPHONE_H
3 
4 /** @file
5  *
6  * iPhone USB Ethernet driver
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <stdint.h>
14 #include <ipxe/usb.h>
15 #include <ipxe/usbnet.h>
16 #include <ipxe/process.h>
17 #include <ipxe/timer.h>
18 #include <ipxe/retry.h>
19 #include <ipxe/tcp.h>
20 #include <ipxe/x509.h>
21 #include <ipxe/privkey.h>
22 
23 /******************************************************************************
24  *
25  * iPhone pairing certificates
26  *
27  ******************************************************************************
28  */
29 
30 /** An iPhone pairing certificate set */
31 struct icert {
32  /** "Private" key */
33  struct private_key *key;
34  /** Root certificate */
36  /** Host certificate */
38  /** Device certificate */
40 };
41 
42 /******************************************************************************
43  *
44  * iPhone USB multiplexer
45  *
46  ******************************************************************************
47  */
48 
49 /** An iPhone USB multiplexed packet header */
50 struct imux_header {
51  /** Protocol */
53  /** Length (including this header) */
55  /** Reserved */
57  /** Output sequence number */
59  /** Input sequence number */
61 } __attribute__ (( packed ));
62 
63 /** iPhone USB multiplexer protocols */
65  /** Version number */
67  /** Log message */
68  IMUX_LOG = 1,
69  /** TCP packet */
71 };
72 
73 /** An iPhone USB multiplexed version message header */
75  /** Multiplexed packet header */
76  struct imux_header hdr;
77  /** Reserved */
79 } __attribute__ (( packed ));
80 
81 /** An iPhone USB multiplexed log message header */
83  /** Multiplexed packet header */
84  struct imux_header hdr;
85  /** Log level */
87  /** Message */
88  char msg[0];
89 } __attribute__ (( packed ));
90 
91 /** An iPhone USB multiplexed pseudo-TCP message header */
93  /** Multiplexed packet header */
94  struct imux_header hdr;
95  /** Pseudo-TCP header */
96  struct tcp_header tcp;
97 } __attribute__ (( packed ));
98 
99 /** Local port number
100  *
101  * This is a policy decision.
102  */
103 #define IMUX_PORT_LOCAL 0x18ae
104 
105 /** Lockdown daemon port number */
106 #define IMUX_PORT_LOCKDOWND 62078
107 
108 /** Advertised TCP window
109  *
110  * This is a policy decision.
111  */
112 #define IMUX_WINDOW 0x0200
113 
114 /** An iPhone USB multiplexer */
115 struct imux {
116  /** Reference counter */
117  struct refcnt refcnt;
118  /** USB device */
119  struct usb_device *usb;
120  /** USB bus */
121  struct usb_bus *bus;
122  /** USB network device */
124  /** List of USB multiplexers */
125  struct list_head list;
126 
127  /** Polling process */
128  struct process process;
129  /** Pending action
130  *
131  * @v imux USB multiplexer
132  * @ret rc Return status code
133  */
134  int ( * action ) ( struct imux *imux );
135 
136  /** Input sequence */
138  /** Output sequence */
140  /** Pseudo-TCP sequence number */
142  /** Pseudo-TCP acknowledgement number */
144  /** Pseudo-TCP local port number */
146 
147  /** Pseudo-TCP lockdown socket interface */
148  struct interface tcp;
149  /** Pairing flags */
150  unsigned int flags;
151  /** Pairing status */
152  int rc;
153 };
154 
155 /** Multiplexer bulk IN maximum fill level
156  *
157  * This is a policy decision.
158  */
159 #define IMUX_IN_MAX_FILL 1
160 
161 /** Multiplexer bulk IN buffer size
162  *
163  * This is a policy decision.
164  */
165 #define IMUX_IN_MTU 4096
166 
167 /******************************************************************************
168  *
169  * iPhone pairing client
170  *
171  ******************************************************************************
172  */
173 
174 /** An iPhone USB multiplexed pseudo-TCP XML message header */
175 struct ipair_header {
176  /** Message length */
178  /** Message */
179  char msg[0];
180 } __attribute__ (( packed ));
181 
182 /** An iPhone pairing client */
183 struct ipair {
184  /** Reference counter */
185  struct refcnt refcnt;
186  /** Data transfer interface */
187  struct interface xfer;
188 
189  /** Pairing timer */
191  /** Transmit message
192  *
193  * @v ipair Pairing client
194  * @ret rc Return status code
195  */
196  int ( * tx ) ( struct ipair *ipair );
197  /** Receive message
198  *
199  * @v ipair Pairing client
200  * @v msg XML message
201  * @ret rc Return status code
202  */
203  int ( * rx ) ( struct ipair *ipair, char *msg );
204  /** State flags */
205  unsigned int flags;
206 
207  /** Pairing certificates */
208  struct icert icert;
209 };
210 
211 /** Pairing client state flags */
213  /** Request a new pairing */
214  IPAIR_REQUEST = 0x0001,
215  /** Standalone length has been received */
216  IPAIR_RX_LEN = 0x0002,
217  /** TLS session has been started */
218  IPAIR_TLS = 0x0004,
219 };
220 
221 /** Pairing retry delay
222  *
223  * This is a policy decision.
224  */
225 #define IPAIR_RETRY_DELAY ( 1 * TICKS_PER_SEC )
226 
227 /******************************************************************************
228  *
229  * iPhone USB networking
230  *
231  ******************************************************************************
232  */
233 
234 /** Get MAC address */
235 #define IPHONE_GET_MAC \
236  ( USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \
237  USB_REQUEST_TYPE ( 0x00 ) )
238 
239 /** Get link status */
240 #define IPHONE_GET_LINK \
241  ( USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \
242  USB_REQUEST_TYPE ( 0x45 ) )
243 
244 /** An iPhone link status */
246  /** Personal Hotspot is disabled */
248  /** Link up */
250  /** Link not yet determined */
252 };
253 
254 /** An iPhone network device */
255 struct iphone {
256  /** USB device */
257  struct usb_device *usb;
258  /** USB bus */
259  struct usb_bus *bus;
260  /** Network device */
262  /** USB network device */
264 
265  /** List of iPhone network devices */
266  struct list_head list;
267  /** Link status check timer */
269 };
270 
271 /** Bulk IN padding */
272 #define IPHONE_IN_PAD 2
273 
274 /** Bulk IN buffer size
275  *
276  * This is a policy decision.
277  */
278 #define IPHONE_IN_MTU ( ETH_FRAME_LEN + IPHONE_IN_PAD )
279 
280 /** Bulk IN maximum fill level
281  *
282  * This is a policy decision.
283  */
284 #define IPHONE_IN_MAX_FILL 8
285 
286 /** Link check interval
287  *
288  * This is a policy decision.
289  */
290 #define IPHONE_LINK_CHECK_INTERVAL ( 5 * TICKS_PER_SEC )
291 
292 #endif /* _IPHONE_H */
A process.
Definition: process.h:18
#define __attribute__(x)
Definition: compiler.h:10
ipair_flags
Pairing client state flags.
Definition: iphone.h:212
uint32_t tcp_ack
Pseudo-TCP acknowledgement number.
Definition: iphone.h:143
unsigned short uint16_t
Definition: stdint.h:11
uint16_t out_seq
Output sequence number.
Definition: iphone.h:58
void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: message.c:62
int(* tx)(struct ipair *ipair)
Transmit message.
Definition: iphone.h:196
An iPhone USB multiplexed packet header.
Definition: iphone.h:50
FILE_SECBOOT(PERMITTED)
int(* action)(struct imux *imux)
Pending action.
Definition: iphone.h:134
Retry timers.
TCP packet.
Definition: iphone.h:70
struct interface tcp
Pseudo-TCP lockdown socket interface.
Definition: iphone.h:148
char msg[0]
Message.
Definition: iphone.h:88
uint16_t out_seq
Output sequence.
Definition: iphone.h:139
uint16_t in_seq
Input sequence number.
Definition: iphone.h:60
struct interface xfer
Data transfer interface.
Definition: iphone.h:187
A retry timer.
Definition: retry.h:22
An iPhone USB multiplexed pseudo-TCP message header.
Definition: iphone.h:92
uint32_t protocol
Protocol.
Definition: iphone.h:52
iPXE timers
An iPhone USB multiplexed log message header.
Definition: iphone.h:82
struct x509_certificate * device
Device certificate.
Definition: iphone.h:39
Log message.
Definition: iphone.h:68
struct imux_header hdr
Multiplexed packet header.
Definition: iphone.h:94
A doubly-linked list entry (or list head)
Definition: list.h:19
An iPhone pairing client.
Definition: iphone.h:183
A reference counter.
Definition: refcnt.h:27
A timer.
Definition: timer.h:29
Private key.
struct x509_certificate * host
Host certificate.
Definition: iphone.h:37
imux_protocol
iPhone USB multiplexer protocols
Definition: iphone.h:64
Standalone length has been received.
Definition: iphone.h:216
iphone_link_status
An iPhone link status.
Definition: iphone.h:245
An object interface.
Definition: interface.h:125
struct tcp_header tcp
Pseudo-TCP header.
Definition: iphone.h:96
Personal Hotspot is disabled.
Definition: iphone.h:247
A TCP header.
Definition: tcp.h:20
An iPhone USB multiplexed version message header.
Definition: iphone.h:74
A USB device.
Definition: usb.h:723
Request a new pairing.
Definition: iphone.h:214
An X.509 certificate.
Definition: x509.h:216
A USB network device.
Definition: usbnet.h:16
Link not yet determined.
Definition: iphone.h:251
uint32_t len
Length (including this header)
Definition: iphone.h:54
uint32_t reserved
Reserved.
Definition: iphone.h:78
A network device.
Definition: netdevice.h:353
Processes.
struct usb_device * usb
USB device.
Definition: iphone.h:257
unsigned char uint8_t
Definition: stdint.h:10
struct usb_bus * bus
USB bus.
Definition: iphone.h:121
uint16_t in_seq
Input sequence.
Definition: iphone.h:137
X.509 certificates.
uint32_t reserved
Reserved.
Definition: iphone.h:56
An iPhone USB multiplexer.
Definition: iphone.h:115
unsigned int uint32_t
Definition: stdint.h:12
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:123
struct x509_certificate * root
Root certificate.
Definition: iphone.h:35
struct usb_device * usb
USB device.
Definition: iphone.h:119
uint32_t len
Message length.
Definition: iphone.h:177
USB network devices.
uint32_t tcp_seq
Pseudo-TCP sequence number.
Definition: iphone.h:141
Version number.
Definition: iphone.h:66
unsigned int flags
Pairing flags.
Definition: iphone.h:150
uint8_t level
Log level.
Definition: iphone.h:86
An iPhone network device.
Definition: iphone.h:255
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
Universal Serial Bus (USB)
struct private_key * key
"Private" key
Definition: iphone.h:33
struct imux_header hdr
Multiplexed packet header.
Definition: iphone.h:84
uint16_t port
Pseudo-TCP local port number.
Definition: iphone.h:145
A private key.
Definition: privkey.h:17
int(* rx)(struct ipair *ipair, char *msg)
Receive message.
Definition: iphone.h:203
struct imux_header hdr
Multiplexed packet header.
Definition: iphone.h:76
An iPhone USB multiplexed pseudo-TCP XML message header.
Definition: iphone.h:175
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:263
int rc
Pairing status.
Definition: iphone.h:152
TCP protocol.
Link up.
Definition: iphone.h:249
TLS session has been started.
Definition: iphone.h:218
#define IP_TCP
Definition: in.h:14
A USB bus.
Definition: usb.h:966
char msg[0]
Message.
Definition: iphone.h:179
unsigned int flags
State flags.
Definition: iphone.h:205
struct usb_bus * bus
USB bus.
Definition: iphone.h:259
struct net_device * netdev
Network device.
Definition: iphone.h:261
An iPhone pairing certificate set.
Definition: iphone.h:31
struct list_head list
List of USB multiplexers.
Definition: iphone.h:125
struct list_head list
List of iPhone network devices.
Definition: iphone.h:266