iPXE
Macros | Functions | Variables
iphone.c File Reference

iPhone USB Ethernet driver More...

#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/profile.h>
#include <ipxe/base64.h>
#include <ipxe/sha256.h>
#include <ipxe/rsa.h>
#include <ipxe/x509.h>
#include <ipxe/pem.h>
#include <ipxe/xfer.h>
#include <ipxe/tls.h>
#include <ipxe/usb.h>
#include "iphone.h"

Go to the source code of this file.

Macros

#define EPIPE_NO_MUX   __einfo_error ( EINFO_EPIPE_NO_MUX )
 
#define EINFO_EPIPE_NO_MUX
 
#define EINPROGRESS_PAIRING   __einfo_error ( EINFO_EINPROGRESS_PAIRING )
 
#define EINFO_EINPROGRESS_PAIRING
 
#define ENOTCONN_DISABLED   __einfo_error ( EINFO_ENOTCONN_DISABLED )
 
#define EINFO_ENOTCONN_DISABLED
 
#define ENOTCONN_STATUS(status)
 
#define icert_key_suffix   a
 Key pair selection. More...
 
#define icert_key_variable(prefix)   _C2 ( prefix, icert_key_suffix )
 
#define icert_public   icert_key_variable ( icert_public_ )
 
#define icert_private   icert_key_variable ( icert_private_ )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int ipair_create (struct interface *xfer, unsigned int flags)
 Create a pairing client. More...
 
static LIST_HEAD (imuxes)
 List of USB multiplexers. More...
 
static LIST_HEAD (iphones)
 List of iPhone network devices. More...
 
static void icert_free (struct icert *icert)
 Free pairing certificates. More...
 
static int icert_cert (struct icert *icert, struct asn1_cursor *subject, struct asn1_cursor *issuer, struct asn1_cursor *private, struct asn1_cursor *public, struct asn1_cursor *exts, struct x509_certificate **cert)
 Construct certificate. More...
 
static int icert_certs (struct icert *icert, struct asn1_cursor *key)
 Construct certificates. More...
 
static int icert_encode (struct icert *icert, struct x509_certificate *cert, char **encenc)
 Construct doubly base64-encoded certificate. More...
 
static int imux_tx (struct imux *imux, struct io_buffer *iobuf)
 Transmit message. More...
 
static int imux_tx_version (struct imux *imux)
 Transmit version message. More...
 
static int imux_tx_tcp (struct imux *imux, struct io_buffer *iobuf)
 Transmit pseudo-TCP message. More...
 
static int imux_tx_syn (struct imux *imux)
 Transmit pseudo-TCP SYN. More...
 
static int imux_start_pair (struct imux *imux)
 Open pairing client. More...
 
static void imux_rx_version (struct imux *imux)
 Receive version message. More...
 
static void imux_rx_log (struct imux *imux, struct imux_header *hdr, size_t len)
 Receive log message. More...
 
static void imux_rx_syn (struct imux *imux)
 Receive pseudo-TCP SYN+ACK. More...
 
static void imux_rx_tcp (struct imux *imux, struct io_buffer *iobuf)
 Receive pseudo-TCP message. More...
 
static void imux_in_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete bulk IN transfer. More...
 
static void imux_out_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete bulk OUT transfer. More...
 
static void imux_shutdown (struct imux *imux)
 Shut down USB multiplexer. More...
 
static void imux_close (struct imux *imux, int rc)
 Close USB multiplexer. More...
 
static struct io_bufferimux_alloc_iob (struct imux *imux __unused, size_t len)
 Allocate I/O buffer for pseudo-TCP socket. More...
 
static int imux_deliver (struct imux *imux, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
 Transmit packet via pseudo-TCP socket. More...
 
static void imux_step (struct imux *imux)
 Multiplexer process. More...
 
static int imux_probe (struct usb_function *func, struct usb_configuration_descriptor *config)
 Probe device. More...
 
static void imux_remove (struct usb_function *func)
 Remove device. More...
 
static int ipair_tx_pubkey (struct ipair *ipair)
 Transmit DevicePublicKey message. More...
 
static int ipair_rx_pubkey (struct ipair *ipair, char *msg)
 Receive DevicePublicKey message. More...
 
static int ipair_tx_pair (struct ipair *ipair)
 Transmit Pair message. More...
 
static int ipair_rx_pair (struct ipair *ipair, char *msg)
 Receive Pair message. More...
 
static int ipair_tx_session (struct ipair *ipair)
 Transmit StartSession message. More...
 
static int ipair_rx_session (struct ipair *ipair, char *msg)
 Receive StartSession message. More...
 
static void ipair_free (struct refcnt *refcnt)
 Free pairing client. More...
 
static void ipair_close (struct ipair *ipair, int rc)
 Shut down pairing client. More...
 
static int ipair_tx (struct ipair *ipair, const char *fmt,...)
 Transmit XML message. More...
 
static int ipair_rx (struct ipair *ipair, char *msg, size_t len)
 Receive XML message payload. More...
 
static int ipair_tag (struct ipair *ipair, const char *msg, const char *tag, char **start, char **end)
 Locate XML tag. More...
 
static int ipair_key (struct ipair *ipair, const char *msg, const char *key, const char *type, char **start, char **end)
 Locate XML property list dictionary value. More...
 
static int ipair_rx_pair_error (struct ipair *ipair, char *error)
 Receive Pair message error. More...
 
static int ipair_rx_session_error (struct ipair *ipair, char *error)
 Receive StartSession message error. More...
 
static void ipair_window_changed (struct ipair *ipair)
 Handle window change notification. More...
 
static int ipair_deliver (struct ipair *ipair, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
 Handle received data. More...
 
static void ipair_expired (struct retry_timer *timer, int over __unused)
 Pairing transmission timer. More...
 
static void iphone_in_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete bulk IN transfer. More...
 
static int iphone_out_transmit (struct iphone *iphone, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void iphone_out_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete bulk OUT transfer. More...
 
static int iphone_check_pair (struct iphone *iphone)
 Check pairing status. More...
 
static void iphone_check_link (struct net_device *netdev)
 Check link status. More...
 
static void iphone_expired (struct retry_timer *timer, int over __unused)
 Periodically update link status. More...
 
static int iphone_open (struct net_device *netdev)
 Open network device. More...
 
static void iphone_close (struct net_device *netdev)
 Close network device. More...
 
static int iphone_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void iphone_poll (struct net_device *netdev)
 Poll for completed and received packets. More...
 
static int iphone_probe (struct usb_function *func, struct usb_configuration_descriptor *config)
 Probe device. More...
 
static void iphone_remove (struct usb_function *func)
 Remove device. More...
 
 REQUIRING_SYMBOL (iphone_driver)
 
 REQUIRE_OBJECT (rsa_sha256)
 

Variables

static struct profiler iphone_in_profiler __profiler
 Bulk IN completion profiler. More...
 
static uint8_t icert_root_fingerprint [SHA256_DIGEST_SIZE]
 iPhone root certificate fingerprint More...
 
static struct x509_root icert_root
 Root of trust for iPhone certificates. More...
 
static const uint8_t icert_nul [] = { 0x00 }
 Single zero byte used in constructed certificates. More...
 
static const uint8_t icert_rsa []
 "RSA algorithm" identifier used in constructed certificates More...
 
static const uint8_t icert_sha256_rsa []
 "SHA-256 with RSA algorithm" identifier used in constructed certificates More...
 
static const uint8_t icert_root_exts_data []
 Extensions used in constructed root certificate. More...
 
static struct asn1_cursor icert_root_exts
 Extensions used in constructed root certificate. More...
 
static const uint8_t icert_leaf_exts_data []
 Extensions used in constructed leaf certificates. More...
 
static struct asn1_cursor icert_leaf_exts
 Extensions used in constructed leaf certificates. More...
 
static const uint8_t icert_tbs_prefix []
 "TBSCertificate" prefix in constructed certificates More...
 
static const uint8_t icert_validity []
 Validity period in constructed certificates. More...
 
static const uint8_t icert_name_root_data []
 "Root" subject name More...
 
static struct asn1_cursor icert_name_root
 "Root" subject name More...
 
static const uint8_t icert_name_ipxe_data []
 "iPXE" subject name More...
 
static struct asn1_cursor icert_name_ipxe
 "iPXE" subject name More...
 
static const uint8_t icert_name_iphone_data []
 "iPhone" subject name More...
 
static struct asn1_cursor icert_name_iphone
 "iPhone" subject name More...
 
static const uint8_t icert_public_a [] __unused
 Public key(s) used for pairing. More...
 
static const char icert_begin [] = "-----BEGIN CERTIFICATE-----\n"
 PEM certificate prefix. More...
 
static const char icert_end [] = "\n-----END CERTIFICATE-----\n"
 PEM certificate suffix. More...
 
static struct usb_endpoint_driver_operations imux_in_operations
 Bulk IN endpoint operations. More...
 
static struct usb_endpoint_driver_operations imux_out_operations
 Bulk OUT endpoint operations. More...
 
static struct interface_operation imux_tcp_operations []
 Pseudo-TCP socket interface operations. More...
 
static struct interface_descriptor imux_tcp_desc
 Pseudo-TCP socket interface descriptor. More...
 
static struct process_descriptor imux_process_desc
 Multiplexer process descriptor. More...
 
static struct usb_device_id imux_ids []
 USB multiplexer device IDs. More...
 
struct usb_driver imux_driver __usb_driver
 USB multiplexer driver. More...
 
static const char ipair_prefix []
 Common prefix for all pairing messages. More...
 
static const char ipair_suffix []
 Common suffix for all pairing messages. More...
 
static const char ipair_system_buid [] = "E4DB92D2-248A-469A-AC34-92045D07E695"
 Arbitrary system BUID used for pairing. More...
 
static const char ipair_host_id [] = "93CEBC27-8457-4804-9108-F42549DF6143"
 Arbitrary host ID used for pairing. More...
 
static struct interface_operation ipair_xfer_operations []
 Pairing client interface operations. More...
 
static struct interface_descriptor ipair_xfer_desc
 Pairing client interface descriptor. More...
 
static struct usb_endpoint_driver_operations iphone_in_operations
 Bulk IN endpoint operations. More...
 
static struct usb_endpoint_driver_operations iphone_out_operations
 Bulk OUT endpoint operations. More...
 
static struct net_device_operations iphone_operations
 iPhone network device operations More...
 
static struct usb_device_id iphone_ids []
 iPhone device IDs More...
 

Detailed Description

iPhone USB Ethernet driver

Definition in file iphone.c.

Macro Definition Documentation

◆ EPIPE_NO_MUX

#define EPIPE_NO_MUX   __einfo_error ( EINFO_EPIPE_NO_MUX )

Definition at line 51 of file iphone.c.

◆ EINFO_EPIPE_NO_MUX

#define EINFO_EPIPE_NO_MUX
Value:
"No USB multiplexer" )
#define EINFO_EPIPE
Definition: errno.h:620
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 52 of file iphone.c.

◆ EINPROGRESS_PAIRING

#define EINPROGRESS_PAIRING   __einfo_error ( EINFO_EINPROGRESS_PAIRING )

Definition at line 55 of file iphone.c.

◆ EINFO_EINPROGRESS_PAIRING

#define EINFO_EINPROGRESS_PAIRING
Value:
"Pairing in progress" )
#define EINFO_EINPROGRESS
Definition: errno.h:419
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 56 of file iphone.c.

◆ ENOTCONN_DISABLED

#define ENOTCONN_DISABLED   __einfo_error ( EINFO_ENOTCONN_DISABLED )

Definition at line 59 of file iphone.c.

◆ EINFO_ENOTCONN_DISABLED

#define EINFO_ENOTCONN_DISABLED
Value:
"Personal Hotspot disabled" )
Personal Hotspot is disabled.
Definition: iphone.h:246
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180
#define EINFO_ENOTCONN
Definition: errno.h:570

Definition at line 60 of file iphone.c.

◆ ENOTCONN_STATUS

#define ENOTCONN_STATUS (   status)
Value:
EUNIQ ( EINFO_ENOTCONN, ( (status) & 0x1f ), \
uint8_t status
Status.
Definition: ena.h:16
#define EUNIQ(einfo_base, uniq,...)
Disambiguate a base error based on non-constant information.
Definition: errno.h:225
#define EINFO_ENOTCONN
Definition: errno.h:570
#define ENOTCONN_DISABLED
Definition: iphone.c:59

Definition at line 63 of file iphone.c.

◆ icert_key_suffix

#define icert_key_suffix   a

Key pair selection.

This exists only to allow for testing of the process for handling a failed TLS negotiation.

Definition at line 314 of file iphone.c.

◆ icert_key_variable

#define icert_key_variable (   prefix)    _C2 ( prefix, icert_key_suffix )

Definition at line 315 of file iphone.c.

◆ icert_public

#define icert_public   icert_key_variable ( icert_public_ )

Definition at line 316 of file iphone.c.

◆ icert_private

#define icert_private   icert_key_variable ( icert_private_ )

Definition at line 317 of file iphone.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ipair_create()

static int ipair_create ( struct interface xfer,
unsigned int  flags 
)
static

Create a pairing client.

Parameters
xferData transfer interface
flagsInitial state flags
Return values
rcReturn status code

Definition at line 1855 of file iphone.c.

1855  {
1856  struct ipair *ipair;
1857  int rc;
1858 
1859  /* Allocate and initialise structure */
1860  ipair = zalloc ( sizeof ( *ipair ) );
1861  if ( ! ipair ) {
1862  rc = -ENOMEM;
1863  goto err_alloc;
1864  }
1867  timer_init ( &ipair->timer, ipair_expired, &ipair->refcnt );
1870  ipair->flags = flags;
1871 
1872  /* Schedule initial transmission */
1874 
1875  /* Attach to parent interface, mortalise self, and return */
1876  intf_plug_plug ( &ipair->xfer, xfer );
1877  ref_put ( &ipair->refcnt );
1878  return 0;
1879 
1880  ref_put ( &ipair->refcnt );
1881  err_alloc:
1882  return rc;
1883 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void start_timer_nodelay(struct retry_timer *timer)
Start timer with no delay.
Definition: retry.h:99
int(* tx)(struct ipair *ipair)
Transmit message.
Definition: iphone.h:195
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
static void ipair_expired(struct retry_timer *timer, int over __unused)
Pairing transmission timer.
Definition: iphone.c:1820
struct interface xfer
Data transfer interface.
Definition: iphone.h:186
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
An iPhone pairing client.
Definition: iphone.h:182
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct refcnt refcnt
Reference counter.
Definition: iphone.h:184
static struct interface_descriptor ipair_xfer_desc
Pairing client interface descriptor.
Definition: iphone.c:1845
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static int ipair_tx_pubkey(struct ipair *ipair)
Transmit DevicePublicKey message.
Definition: iphone.c:1432
static int ipair_rx_pubkey(struct ipair *ipair, char *msg)
Receive DevicePublicKey message.
Definition: iphone.c:1455
static void ipair_free(struct refcnt *refcnt)
Free pairing client.
Definition: iphone.c:1253
int(* rx)(struct ipair *ipair, char *msg)
Receive message.
Definition: iphone.h:202
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
unsigned int flags
State flags.
Definition: iphone.h:204
struct retry_timer timer
Pairing timer.
Definition: iphone.h:189
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
uint8_t flags
Flags.
Definition: ena.h:18

References ENOMEM, flags, ipair::flags, intf_init(), intf_plug_plug(), ipair_expired(), ipair_free(), ipair_rx_pubkey(), ipair_tx_pubkey(), ipair_xfer_desc, rc, ref_init, ref_put, ipair::refcnt, ipair::rx, start_timer_nodelay(), ipair::timer, ipair::tx, ipair::xfer, and zalloc().

Referenced by imux_start_pair().

◆ LIST_HEAD() [1/2]

static LIST_HEAD ( imuxes  )
static

List of USB multiplexers.

◆ LIST_HEAD() [2/2]

static LIST_HEAD ( iphones  )
static

List of iPhone network devices.

◆ icert_free()

static void icert_free ( struct icert icert)
static

Free pairing certificates.

Parameters
icertPairing certificates

Definition at line 330 of file iphone.c.

330  {
331 
332  privkey_put ( icert->key );
333  x509_put ( icert->root );
334  x509_put ( icert->host );
335  x509_put ( icert->device );
336  memset ( icert, 0, sizeof ( *icert ) );
337 }
static void privkey_put(struct private_key *key)
Drop reference to private key.
Definition: privkey.h:41
struct x509_certificate * device
Device certificate.
Definition: iphone.h:38
struct x509_certificate * host
Host certificate.
Definition: iphone.h:36
struct x509_certificate * root
Root certificate.
Definition: iphone.h:34
static void x509_put(struct x509_certificate *cert)
Drop reference to X.509 certificate.
Definition: x509.h:269
struct private_key * key
"Private" key
Definition: iphone.h:32
An iPhone pairing certificate set.
Definition: iphone.h:30
void * memset(void *dest, int character, size_t len) __nonnull

References icert::device, icert::host, icert::key, memset(), privkey_put(), icert::root, and x509_put().

Referenced by icert_certs(), and ipair_free().

◆ icert_cert()

static int icert_cert ( struct icert icert,
struct asn1_cursor subject,
struct asn1_cursor issuer,
struct asn1_cursor private,
struct asn1_cursor public,
struct asn1_cursor exts,
struct x509_certificate **  cert 
)
static

Construct certificate.

Parameters
icertPairing certificates
subjectSubject name
issuerIssuer name
privatePrivate key
publicPublic key
extsCertificate extensions
certCertificate to fill in
Return values
rcReturn status code

On success, the caller is responsible for eventually calling x509_put() on the allocated encoded certificate.

Definition at line 354 of file iphone.c.

357  {
359  struct pubkey_algorithm *pubkey = &rsa_algorithm;
360  struct asn1_builder spki = { NULL, 0 };
361  struct asn1_builder tbs = { NULL, 0 };
362  struct asn1_builder raw = { NULL, 0 };
363  uint8_t digest_ctx[SHA256_CTX_SIZE];
364  uint8_t digest_out[SHA256_DIGEST_SIZE];
365  uint8_t pubkey_ctx[RSA_CTX_SIZE];
366  int len;
367  int rc;
368 
369  /* Initialise "private" key */
370  if ( ( rc = pubkey_init ( pubkey, pubkey_ctx, private->data,
371  private->len ) ) != 0 ) {
372  DBGC ( icert, "ICERT %p could not initialise private key: "
373  "%s\n", icert, strerror ( rc ) );
374  goto err_pubkey_init;
375  }
376 
377  /* Construct subjectPublicKeyInfo */
378  if ( ( rc = ( asn1_prepend_raw ( &spki, public->data, public->len ),
379  asn1_prepend_raw ( &spki, icert_nul,
380  sizeof ( icert_nul ) ),
381  asn1_wrap ( &spki, ASN1_BIT_STRING ),
382  asn1_prepend_raw ( &spki, icert_rsa,
383  sizeof ( icert_rsa ) ),
384  asn1_wrap ( &spki, ASN1_SEQUENCE ) ) ) != 0 ) {
385  DBGC ( icert, "ICERT %p could not build subjectPublicKeyInfo: "
386  "%s\n", icert, strerror ( rc ) );
387  goto err_spki;
388  }
389 
390  /* Construct tbsCertificate */
391  if ( ( rc = ( asn1_prepend_raw ( &tbs, exts->data, exts->len ),
392  asn1_prepend_raw ( &tbs, spki.data, spki.len ),
393  asn1_prepend_raw ( &tbs, subject->data, subject->len ),
395  sizeof ( icert_validity ) ),
396  asn1_prepend_raw ( &tbs, issuer->data, issuer->len ),
398  sizeof ( icert_tbs_prefix ) ),
399  asn1_wrap ( &tbs, ASN1_SEQUENCE ) ) ) != 0 ) {
400  DBGC ( icert, "ICERT %p could not build tbsCertificate: %s\n",
401  icert, strerror ( rc ) );
402  goto err_tbs;
403  }
404 
405  /* Calculate certificate digest */
406  digest_init ( digest, digest_ctx );
407  digest_update ( digest, digest_ctx, tbs.data, tbs.len );
408  digest_final ( digest, digest_ctx, digest_out );
409 
410  /* Construct signature */
411  if ( ( rc = asn1_grow ( &raw, pubkey_max_len ( pubkey,
412  pubkey_ctx ) ) ) != 0 ) {
413  DBGC ( icert, "ICERT %p could not build signature: %s\n",
414  icert, strerror ( rc ) );
415  goto err_grow;
416  }
417  if ( ( len = pubkey_sign ( pubkey, pubkey_ctx, digest, digest_out,
418  raw.data ) ) < 0 ) {
419  rc = len;
420  DBGC ( icert, "ICERT %p could not sign: %s\n",
421  icert, strerror ( rc ) );
422  goto err_pubkey_sign;
423  }
424  assert ( ( ( size_t ) len ) == raw.len );
425 
426  /* Construct raw certificate data */
427  if ( ( rc = ( asn1_prepend_raw ( &raw, icert_nul,
428  sizeof ( icert_nul ) ),
431  sizeof ( icert_sha256_rsa ) ),
432  asn1_prepend_raw ( &raw, tbs.data, tbs.len ),
433  asn1_wrap ( &raw, ASN1_SEQUENCE ) ) ) != 0 ) {
434  DBGC ( icert, "ICERT %p could not build certificate: %s\n",
435  icert, strerror ( rc ) );
436  goto err_raw;
437  }
438 
439  /* Parse certificate */
440  if ( ( rc = x509_certificate ( raw.data, raw.len, cert ) ) != 0 ) {
441  DBGC ( icert, "ICERT %p invalid certificate: %s\n",
442  icert, strerror ( rc ) );
443  DBGC_HDA ( icert, 0, raw.data, raw.len );
444  goto err_x509;
445  }
446 
447  err_x509:
448  err_raw:
449  err_pubkey_sign:
450  free ( raw.data );
451  err_grow:
452  free ( tbs.data );
453  err_tbs:
454  free ( spki.data );
455  err_spki:
456  pubkey_final ( pubkey, pubkey_ctx );
457  err_pubkey_init:
458  return rc;
459 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * data
Data.
Definition: asn1.h:35
#define SHA256_DIGEST_SIZE
Definition: Tpm20.h:29
#define SHA256_CTX_SIZE
SHA-256 context size.
Definition: sha256.h:71
int asn1_prepend_raw(struct asn1_builder *builder, const void *data, size_t len)
Prepend raw data to ASN.1 builder.
Definition: asn1.c:801
const void * data
Start of data.
Definition: asn1.h:22
#define DBGC(...)
Definition: compiler.h:505
size_t len
Length of data.
Definition: asn1.h:24
static const uint8_t icert_sha256_rsa[]
"SHA-256 with RSA algorithm" identifier used in constructed certificates
Definition: iphone.c:113
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void struct digest_algorithm * digest
HMAC-MD5 digest.
Definition: crypto.h:308
#define DBGC_HDA(...)
Definition: compiler.h:506
#define RSA_CTX_SIZE
RSA context size.
Definition: rsa.h:81
static const uint8_t icert_validity[]
Validity period in constructed certificates.
Definition: iphone.c:186
int asn1_grow(struct asn1_builder *builder, size_t extra)
Grow ASN.1 builder.
Definition: asn1.c:768
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
An X.509 certificate.
Definition: x509.h:207
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
An ASN.1 object builder.
Definition: asn1.h:28
unsigned char uint8_t
Definition: stdint.h:10
int asn1_wrap(struct asn1_builder *builder, unsigned int type)
Wrap ASN.1 builder.
Definition: asn1.c:851
#define ASN1_SEQUENCE
ASN.1 sequence.
Definition: asn1.h:89
static const uint8_t icert_rsa[]
"RSA algorithm" identifier used in constructed certificates
Definition: iphone.c:105
struct digest_algorithm sha256_algorithm
SHA-256 algorithm.
Definition: sha256.c:264
uint32_t len
Length.
Definition: ena.h:14
struct pubkey_algorithm rsa_algorithm
RSA public-key algorithm.
Definition: rsa.c:632
A message digest algorithm.
Definition: crypto.h:17
__be32 raw[7]
Definition: CIB_PRM.h:28
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
size_t len
Length of data.
Definition: asn1.h:37
A public key algorithm.
Definition: crypto.h:120
static const uint8_t icert_tbs_prefix[]
"TBSCertificate" prefix in constructed certificates
Definition: iphone.c:174
#define ASN1_BIT_STRING
ASN.1 bit string.
Definition: asn1.h:65
An iPhone pairing certificate set.
Definition: iphone.h:30
static const uint8_t icert_nul[]
Single zero byte used in constructed certificates.
Definition: iphone.c:102

References ASN1_BIT_STRING, asn1_grow(), asn1_prepend_raw(), ASN1_SEQUENCE, asn1_wrap(), assert(), asn1_cursor::data, asn1_builder::data, DBGC, DBGC_HDA, digest, free, icert_nul, icert_rsa, icert_sha256_rsa, icert_tbs_prefix, icert_validity, len, asn1_cursor::len, asn1_builder::len, NULL, raw, rc, rsa_algorithm, RSA_CTX_SIZE, sha256_algorithm, SHA256_CTX_SIZE, SHA256_DIGEST_SIZE, and strerror().

Referenced by icert_certs().

◆ icert_certs()

static int icert_certs ( struct icert icert,
struct asn1_cursor key 
)
static

Construct certificates.

Parameters
icertCertificate set
pubkeyDevice public key
Return values
rcReturn status code

Definition at line 468 of file iphone.c.

468  {
470  struct asn1_builder public = { NULL, 0 };
471  struct asn1_builder *private;
472  int rc;
473 
474  /* Free any existing key and certificates */
475  icert_free ( icert );
476 
477  /* Allocate "private" key */
478  icert->key = zalloc ( sizeof ( *icert->key ) );
479  if ( ! icert->key ) {
480  rc = -ENOMEM;
481  goto error;
482  }
483  privkey_init ( icert->key );
484  private = &icert->key->builder;
485 
486  /* Construct our "private" key */
487  if ( ( rc = ( asn1_prepend_raw ( private, icert_private,
488  sizeof ( icert_private ) ),
489  asn1_prepend_raw ( private, icert_public,
490  sizeof ( icert_public ) ),
491  asn1_prepend ( private, ASN1_INTEGER, icert_nul,
492  sizeof ( icert_nul ) ),
493  asn1_wrap ( private, ASN1_SEQUENCE ) ) ) != 0 ) {
494  DBGC ( icert, "ICERT %p could not build private key: %s\n",
495  icert, strerror ( rc ) );
496  goto error;
497  }
498 
499  /* Construct our own public key */
500  if ( ( rc = ( asn1_prepend_raw ( &public, icert_public,
501  sizeof ( icert_public ) ),
502  asn1_wrap ( &public, ASN1_SEQUENCE ) ) ) != 0 ) {
503  DBGC ( icert, "ICERT %p could not build public key: %s\n",
504  icert, strerror ( rc ) );
505  goto error;
506  }
507 
508  /* Construct root certificate */
510  asn1_built ( private ), asn1_built ( &public ),
511  &icert_root_exts, &icert->root ) ) != 0 )
512  goto error;
513 
514  /* Construct host certificate */
516  asn1_built ( private ), asn1_built ( &public ),
517  &icert_leaf_exts, &icert->host ) ) != 0 )
518  goto error;
519 
520  /* Construct device certificate */
522  asn1_built ( private ), key,
523  &icert_leaf_exts, &icert->device ) ) != 0 )
524  goto error;
525 
526  /* Construct root of trust */
527  assert ( digest->digestsize == sizeof ( icert_root_fingerprint ) );
529 
530  /* Free constructed keys */
531  free ( public.data );
532  return 0;
533 
534  error:
535  icert_free ( icert );
536  free ( public.data );
537  return rc;
538 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define icert_public
Definition: iphone.c:316
static struct asn1_cursor icert_name_ipxe
"iPXE" subject name
Definition: iphone.c:220
static struct asn1_cursor icert_leaf_exts
Extensions used in constructed leaf certificates.
Definition: iphone.c:170
struct arbelprm_completion_with_error error
Definition: arbel.h:12
int asn1_prepend_raw(struct asn1_builder *builder, const void *data, size_t len)
Prepend raw data to ASN.1 builder.
Definition: asn1.c:801
static struct x509_root icert_root
Root of trust for iPhone certificates.
Definition: iphone.c:94
#define DBGC(...)
Definition: compiler.h:505
struct x509_certificate * device
Device certificate.
Definition: iphone.h:38
static struct asn1_cursor icert_name_iphone
"iPhone" subject name
Definition: iphone.c:233
struct x509_certificate * host
Host certificate.
Definition: iphone.h:36
struct asn1_builder builder
ASN.1 object builder.
Definition: privkey.h:20
#define ENOMEM
Not enough space.
Definition: errno.h:534
static struct asn1_cursor icert_root_exts
Extensions used in constructed root certificate.
Definition: iphone.c:137
static struct asn1_cursor icert_name_root
"Root" subject name
Definition: iphone.c:208
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static uint8_t icert_root_fingerprint[SHA256_DIGEST_SIZE]
iPhone root certificate fingerprint
Definition: iphone.c:91
static void struct digest_algorithm * digest
HMAC-MD5 digest.
Definition: crypto.h:308
struct digest_algorithm * digest
Fingerprint digest algorithm.
Definition: x509.h:370
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
An ASN.1 object builder.
Definition: asn1.h:28
int asn1_wrap(struct asn1_builder *builder, unsigned int type)
Wrap ASN.1 builder.
Definition: asn1.c:851
#define ASN1_SEQUENCE
ASN.1 sequence.
Definition: asn1.h:89
void x509_fingerprint(struct x509_certificate *cert, struct digest_algorithm *digest, void *fingerprint)
Calculate X.509 certificate fingerprint.
Definition: x509.c:1242
#define ASN1_INTEGER
ASN.1 integer.
Definition: asn1.h:62
struct x509_certificate * root
Root certificate.
Definition: iphone.h:34
size_t digestsize
Digest size.
Definition: crypto.h:25
struct private_key * key
"Private" key
Definition: iphone.h:32
int asn1_prepend(struct asn1_builder *builder, unsigned int type, const void *data, size_t len)
Prepend data to ASN.1 builder.
Definition: asn1.c:824
A message digest algorithm.
Definition: crypto.h:17
static int icert_cert(struct icert *icert, struct asn1_cursor *subject, struct asn1_cursor *issuer, struct asn1_cursor *private, struct asn1_cursor *public, struct asn1_cursor *exts, struct x509_certificate **cert)
Construct certificate.
Definition: iphone.c:354
uint8_t data[48]
Additional event data.
Definition: ena.h:22
static struct asn1_cursor * asn1_built(struct asn1_builder *builder)
Get cursor for built object.
Definition: asn1.h:393
static void privkey_init(struct private_key *key)
Initialise empty private key.
Definition: privkey.h:63
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
union @382 key
Sense key.
Definition: crypto.h:284
An iPhone pairing certificate set.
Definition: iphone.h:30
static void icert_free(struct icert *icert)
Free pairing certificates.
Definition: iphone.c:330
static const uint8_t icert_nul[]
Single zero byte used in constructed certificates.
Definition: iphone.c:102
#define icert_private
Definition: iphone.c:317

References asn1_built(), ASN1_INTEGER, asn1_prepend(), asn1_prepend_raw(), ASN1_SEQUENCE, asn1_wrap(), assert(), private_key::builder, data, DBGC, icert::device, digest, x509_root::digest, digest_algorithm::digestsize, ENOMEM, error, free, icert::host, icert_cert(), icert_free(), icert_leaf_exts, icert_name_iphone, icert_name_ipxe, icert_name_root, icert_nul, icert_private, icert_public, icert_root, icert_root_exts, icert_root_fingerprint, icert::key, key, NULL, privkey_init(), rc, icert::root, strerror(), x509_fingerprint(), and zalloc().

Referenced by ipair_rx_pubkey().

◆ icert_encode()

static int icert_encode ( struct icert icert,
struct x509_certificate cert,
char **  encenc 
)
static

Construct doubly base64-encoded certificate.

Parameters
icertPairing certificates
certX.509 certificate
encencDoubly base64-encoded certificate to construct
Return values
rcReturn status code

On success, the caller is responsible for eventually calling free() on the allocated doubly encoded encoded certificate.

Definition at line 551 of file iphone.c.

552  {
553  size_t encencoded_len;
554  size_t encoded_len;
555  size_t pem_len;
556  char *pem;
557  int rc;
558 
559  /* Sanity check */
560  assert ( cert != NULL );
561 
562  /* Create PEM */
563  encoded_len = ( base64_encoded_len ( cert->raw.len ) + 1 /* NUL */ );
564  pem_len = ( ( sizeof ( icert_begin ) - 1 /* NUL */ ) +
565  ( encoded_len - 1 /* NUL */ ) +
566  ( sizeof ( icert_end ) - 1 /* NUL */ ) +
567  1 /* NUL */ );
568  pem = malloc ( pem_len );
569  if ( ! pem ) {
570  rc = -ENOMEM;
571  goto err_alloc_pem;
572  }
573  strcpy ( pem, icert_begin );
574  base64_encode ( cert->raw.data, cert->raw.len,
575  ( pem + sizeof ( icert_begin ) - 1 /* NUL */ ),
576  encoded_len );
577  strcpy ( ( pem +
578  ( sizeof ( icert_begin ) - 1 /* NUL */ ) +
579  ( encoded_len - 1 /* NUL */ ) ), icert_end );
580  DBGC2 ( icert, "ICERT %p \"%s\" certificate:\n%s",
581  icert, x509_name ( cert ), pem );
582 
583  /* Base64-encode the PEM (sic) */
584  encencoded_len = ( base64_encoded_len ( pem_len - 1 /* NUL */ )
585  + 1 /* NUL */ );
586  *encenc = malloc ( encencoded_len );
587  if ( ! *encenc ) {
588  rc = -ENOMEM;
589  goto err_alloc_encenc;
590  }
591  base64_encode ( pem, ( pem_len - 1 /* NUL */ ), *encenc,
592  encencoded_len );
593 
594  /* Success */
595  rc = 0;
596 
597  err_alloc_encenc:
598  free ( pem );
599  err_alloc_pem:
600  return rc;
601 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static const char icert_end[]
PEM certificate suffix.
Definition: iphone.c:323
const void * data
Start of data.
Definition: asn1.h:22
static const char icert_begin[]
PEM certificate prefix.
Definition: iphone.c:320
size_t len
Length of data.
Definition: asn1.h:24
static size_t base64_encoded_len(size_t raw_len)
Calculate length of base64-encoded data.
Definition: base64.h:21
#define ENOMEM
Not enough space.
Definition: errno.h:534
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
char * strcpy(char *dest, const char *src)
Copy string.
Definition: string.c:326
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
const char * x509_name(struct x509_certificate *cert)
Get X.509 certificate display name.
Definition: x509.c:145
#define DBGC2(...)
Definition: compiler.h:522
struct asn1_cursor raw
Raw certificate.
Definition: x509.h:222
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
An iPhone pairing certificate set.
Definition: iphone.h:30
size_t base64_encode(const void *raw, size_t raw_len, char *data, size_t len)
Base64-encode data.
Definition: base64.c:51

References assert(), base64_encode(), base64_encoded_len(), asn1_cursor::data, DBGC2, ENOMEM, free, icert_begin, icert_end, asn1_cursor::len, malloc(), NULL, x509_certificate::raw, rc, strcpy(), and x509_name().

Referenced by ipair_tx_pair().

◆ imux_tx()

static int imux_tx ( struct imux imux,
struct io_buffer iobuf 
)
static

Transmit message.

Parameters
imuxUSB multiplexer
iobufI/O buffer
Return values
rcReturn status code

Definition at line 621 of file iphone.c.

621  {
622  struct imux_header *hdr = iobuf->data;
623  size_t len = iob_len ( iobuf );
624  int rc;
625 
626  /* Populate header */
627  assert ( len >= sizeof ( *hdr ) );
628  hdr->len = htonl ( len );
629  hdr->in_seq = htons ( imux->in_seq );
630  hdr->out_seq = htons ( imux->out_seq );
631  DBGCP ( imux, "IMUX %p transmitting:\n", imux );
632  DBGCP_HDA ( imux, 0, hdr, len );
633 
634  /* Transmit message */
635  if ( ( rc = usb_stream ( &imux->usbnet.out, iobuf, 1 ) ) != 0 )
636  goto err;
637 
638  /* Increment sequence number */
639  imux->out_seq++;
640 
641  return 0;
642 
643  err:
644  free_iob ( iobuf );
645  return rc;
646 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An iPhone USB multiplexed packet header.
Definition: iphone.h:49
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
uint16_t out_seq
Output sequence.
Definition: iphone.h:138
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition: usb.c:545
#define htonl(value)
Definition: byteswap.h:133
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
#define DBGCP_HDA(...)
Definition: compiler.h:540
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
uint16_t in_seq
Input sequence.
Definition: iphone.h:136
An iPhone USB multiplexer.
Definition: iphone.h:114
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:122
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:48
#define DBGCP(...)
Definition: compiler.h:539
#define htons(value)
Definition: byteswap.h:135

References assert(), io_buffer::data, DBGCP, DBGCP_HDA, free_iob(), hdr, htonl, htons, imux::in_seq, iob_len(), len, usbnet_device::out, imux::out_seq, rc, usb_stream(), and imux::usbnet.

Referenced by imux_tx_tcp(), and imux_tx_version().

◆ imux_tx_version()

static int imux_tx_version ( struct imux imux)
static

Transmit version message.

Parameters
imuxUSB multiplexer
Return values
rcReturn status code

Definition at line 654 of file iphone.c.

654  {
655  struct io_buffer *iobuf;
656  struct imux_header_version *vers;
657  int rc;
658 
659  /* Allocate I/O buffer */
660  iobuf = alloc_iob ( sizeof ( *vers ) );
661  if ( ! iobuf )
662  return -ENOMEM;
663  vers = iob_put ( iobuf, sizeof ( *vers ) );
664 
665  /* Construct version message */
666  memset ( vers, 0, sizeof ( *vers ) );
667  vers->hdr.protocol = htonl ( IMUX_VERSION );
668 
669  /* Transmit message */
670  if ( ( rc = imux_tx ( imux, iob_disown ( iobuf ) ) ) != 0 )
671  return rc;
672 
673  return 0;
674 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:120
uint32_t protocol
Protocol.
Definition: iphone.h:51
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
#define htonl(value)
Definition: byteswap.h:133
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
An iPhone USB multiplexed version message header.
Definition: iphone.h:73
An iPhone USB multiplexer.
Definition: iphone.h:114
Version number.
Definition: iphone.h:65
static int imux_tx(struct imux *imux, struct io_buffer *iobuf)
Transmit message.
Definition: iphone.c:621
struct imux_header hdr
Multiplexed packet header.
Definition: iphone.h:75
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:33

References alloc_iob(), ENOMEM, imux_header_version::hdr, htonl, imux_tx(), IMUX_VERSION, iob_disown, iob_put, memset(), imux_header::protocol, and rc.

Referenced by imux_probe().

◆ imux_tx_tcp()

static int imux_tx_tcp ( struct imux imux,
struct io_buffer iobuf 
)
static

Transmit pseudo-TCP message.

Parameters
imuxUSB multiplexer
iobufI/O buffer
Return values
rcReturn status code

Definition at line 683 of file iphone.c.

683  {
684  struct imux_header_tcp *tcp = iobuf->data;
685  size_t len = iob_len ( iobuf );
686  int rc;
687 
688  /* Populate TCP header */
689  assert ( len >= sizeof ( *tcp ) );
690  tcp->hdr.protocol = htonl ( IMUX_TCP );
691  tcp->tcp.src = htons ( imux->port );
692  tcp->tcp.dest = htons ( IMUX_PORT_LOCKDOWND );
693  tcp->tcp.seq = htonl ( imux->tcp_seq );
694  tcp->tcp.ack = htonl ( imux->tcp_ack );
695  tcp->tcp.hlen = ( ( sizeof ( tcp->tcp ) / 4 ) << 4 );
696  tcp->tcp.win = htons ( IMUX_WINDOW );
697 
698  /* Transmit message */
699  if ( ( rc = imux_tx ( imux, iob_disown ( iobuf ) ) ) != 0 )
700  return rc;
701 
702  /* Update TCP sequence */
703  imux->tcp_seq += ( len - sizeof ( *tcp ) );
704 
705  return 0;
706 }
uint32_t tcp_ack
Pseudo-TCP acknowledgement number.
Definition: iphone.h:142
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
TCP packet.
Definition: iphone.h:69
uint32_t seq
Definition: tcp.h:22
An iPhone USB multiplexed pseudo-TCP message header.
Definition: iphone.h:91
#define IMUX_WINDOW
Advertised TCP window.
Definition: iphone.h:111
#define htonl(value)
Definition: byteswap.h:133
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
uint32_t ack
Definition: tcp.h:23
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct tcp_header tcp
Pseudo-TCP header.
Definition: iphone.h:95
uint16_t win
Definition: tcp.h:26
uint16_t dest
Definition: tcp.h:21
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
An iPhone USB multiplexer.
Definition: iphone.h:114
uint32_t tcp_seq
Pseudo-TCP sequence number.
Definition: iphone.h:140
#define IMUX_PORT_LOCKDOWND
Lockdown daemon port number.
Definition: iphone.h:105
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:48
static int imux_tx(struct imux *imux, struct io_buffer *iobuf)
Transmit message.
Definition: iphone.c:621
uint16_t port
Pseudo-TCP local port number.
Definition: iphone.h:144
uint16_t src
Definition: tcp.h:20
#define htons(value)
Definition: byteswap.h:135
uint8_t hlen
Definition: tcp.h:24

References tcp_header::ack, assert(), io_buffer::data, tcp_header::dest, tcp_header::hlen, htonl, htons, IMUX_PORT_LOCKDOWND, IMUX_TCP, imux_tx(), IMUX_WINDOW, iob_disown, iob_len(), len, imux::port, rc, tcp_header::seq, tcp_header::src, imux_header_tcp::tcp, imux::tcp_ack, imux::tcp_seq, and tcp_header::win.

Referenced by imux_deliver(), and imux_tx_syn().

◆ imux_tx_syn()

static int imux_tx_syn ( struct imux imux)
static

Transmit pseudo-TCP SYN.

Parameters
imuxUSB multiplexer
Return values
rcReturn status code

Definition at line 714 of file iphone.c.

714  {
715  struct io_buffer *iobuf;
716  struct imux_header_tcp *syn;
717  int rc;
718 
719  /* Allocate I/O buffer */
720  iobuf = alloc_iob ( sizeof ( *syn ) );
721  if ( ! iobuf )
722  return -ENOMEM;
723  syn = iob_put ( iobuf, sizeof ( *syn ) );
724 
725  /* Construct TCP SYN message */
726  memset ( syn, 0, sizeof ( *syn ) );
727  syn->tcp.flags = TCP_SYN;
728 
729  /* Transmit message */
730  if ( ( rc = imux_tx_tcp ( imux, iob_disown ( iobuf ) ) ) != 0 )
731  return rc;
732 
733  /* Increment TCP sequence to compensate for SYN */
734  imux->tcp_seq++;
735 
736  return 0;
737 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:120
uint8_t flags
Definition: tcp.h:25
An iPhone USB multiplexed pseudo-TCP message header.
Definition: iphone.h:91
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
#define TCP_SYN
Definition: tcp.h:162
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
struct tcp_header tcp
Pseudo-TCP header.
Definition: iphone.h:95
An iPhone USB multiplexer.
Definition: iphone.h:114
static int imux_tx_tcp(struct imux *imux, struct io_buffer *iobuf)
Transmit pseudo-TCP message.
Definition: iphone.c:683
uint32_t tcp_seq
Pseudo-TCP sequence number.
Definition: iphone.h:140
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:33

References alloc_iob(), ENOMEM, tcp_header::flags, imux_tx_tcp(), iob_disown, iob_put, memset(), rc, imux_header_tcp::tcp, imux::tcp_seq, and TCP_SYN.

Referenced by imux_close(), and imux_rx_version().

◆ imux_start_pair()

static int imux_start_pair ( struct imux imux)
static

Open pairing client.

Parameters
imuxUSB multiplexer
Return values
rcReturn status code

Definition at line 745 of file iphone.c.

745  {
746  int rc;
747 
748  /* Disconnect any existing pairing client */
749  intf_restart ( &imux->tcp, -EPIPE );
750 
751  /* Create pairing client */
752  if ( ( rc = ipair_create ( &imux->tcp, imux->flags ) ) != 0 )
753  return rc;
754 
755  return 0;
756 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:343
static int ipair_create(struct interface *xfer, unsigned int flags)
Create a pairing client.
Definition: iphone.c:1855
#define EPIPE
Broken pipe.
Definition: errno.h:619
struct interface tcp
Pseudo-TCP lockdown socket interface.
Definition: iphone.h:147
An iPhone USB multiplexer.
Definition: iphone.h:114
unsigned int flags
Pairing flags.
Definition: iphone.h:149

References EPIPE, imux::flags, intf_restart(), ipair_create(), rc, and imux::tcp.

Referenced by imux_rx_syn().

◆ imux_rx_version()

static void imux_rx_version ( struct imux imux)
static

Receive version message.

Parameters
imuxUSB multiplexer

Definition at line 763 of file iphone.c.

763  {
764 
765  /* Reset output sequence */
766  imux->out_seq = 0;
767 
768  /* Send TCP SYN */
770 }
static int imux_tx_syn(struct imux *imux)
Transmit pseudo-TCP SYN.
Definition: iphone.c:714
int(* action)(struct imux *imux)
Pending action.
Definition: iphone.h:133
uint16_t out_seq
Output sequence.
Definition: iphone.h:138
An iPhone USB multiplexer.
Definition: iphone.h:114

References imux::action, imux_tx_syn(), and imux::out_seq.

Referenced by imux_in_complete().

◆ imux_rx_log()

static void imux_rx_log ( struct imux imux,
struct imux_header hdr,
size_t  len 
)
static

Receive log message.

Parameters
imuxUSB multiplexer
hdrMessage header
lenLength of message

Definition at line 779 of file iphone.c.

780  {
781  struct imux_header_log *log =
782  container_of ( hdr, struct imux_header_log, hdr );
783  unsigned int level;
784  size_t msg_len;
785  char *tmp;
786 
787  /* Sanity check */
788  if ( len < sizeof ( *log ) ) {
789  DBGC ( imux, "IMUX %p malformed log message:\n", imux );
790  DBGC_HDA ( imux, 0, log, len );
791  return;
792  }
793 
794  /* First byte is the log level, followed by a printable
795  * message with no NUL terminator. Extract the log level,
796  * then shuffle the message down within the buffer and append
797  * a NUL terminator.
798  */
799  msg_len = ( len - sizeof ( *hdr ) );
800  level = log->level;
801  tmp = ( ( void * ) &log->level );
802  memmove ( tmp, &log->msg, msg_len );
803  tmp[msg_len] = '\0';
804 
805  /* Print log message */
806  DBGC ( imux, "IMUX %p <%d>: %s\n", imux, level, tmp );
807 }
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
char msg[0]
Message.
Definition: iphone.h:87
#define DBGC(...)
Definition: compiler.h:505
An iPhone USB multiplexed log message header.
Definition: iphone.h:81
unsigned long tmp
Definition: linux_pci.h:53
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define DBGC_HDA(...)
Definition: compiler.h:506
An iPhone USB multiplexer.
Definition: iphone.h:114
void * memmove(void *dest, const void *src, size_t len) __nonnull
uint8_t level
Log level.
Definition: iphone.h:85
uint32_t len
Length.
Definition: ena.h:14

References container_of, DBGC, DBGC_HDA, hdr, len, imux_header_log::level, memmove(), imux_header_log::msg, and tmp.

Referenced by imux_in_complete().

◆ imux_rx_syn()

static void imux_rx_syn ( struct imux imux)
static

Receive pseudo-TCP SYN+ACK.

Parameters
imuxUSB multiplexer

Definition at line 814 of file iphone.c.

814  {
815 
816  /* Increment TCP acknowledgement to compensate for SYN */
817  imux->tcp_ack++;
818 
819  /* Start pairing client */
821 }
uint32_t tcp_ack
Pseudo-TCP acknowledgement number.
Definition: iphone.h:142
int(* action)(struct imux *imux)
Pending action.
Definition: iphone.h:133
An iPhone USB multiplexer.
Definition: iphone.h:114
static int imux_start_pair(struct imux *imux)
Open pairing client.
Definition: iphone.c:745

References imux::action, imux_start_pair(), and imux::tcp_ack.

Referenced by imux_rx_tcp().

◆ imux_rx_tcp()

static void imux_rx_tcp ( struct imux imux,
struct io_buffer iobuf 
)
static

Receive pseudo-TCP message.

Parameters
imuxUSB multiplexer
iobufI/O buffer

Definition at line 829 of file iphone.c.

829  {
830  struct imux_header_tcp *tcp = iobuf->data;
831  size_t len = iob_len ( iobuf );
832  int rc;
833 
834  /* Sanity check */
835  if ( len < sizeof ( *tcp ) ) {
836  DBGC ( imux, "IMUX %p malformed TCP message:\n", imux );
837  DBGC_HDA ( imux, 0, tcp, len );
838  goto error;
839  }
840 
841  /* Ignore unexpected packets */
842  if ( tcp->tcp.dest != htons ( imux->port ) ) {
843  DBGC ( imux, "IMUX %p ignoring unexpected TCP port %d:\n",
844  imux, ntohs ( tcp->tcp.dest ) );
845  DBGC_HDA ( imux, 0, tcp, len );
846  goto error;
847  }
848 
849  /* Ignore resets */
850  if ( tcp->tcp.flags & TCP_RST ) {
851  DBGC ( imux, "IMUX %p ignoring TCP RST\n", imux );
852  DBGC2_HDA ( imux, 0, tcp, len );
853  goto error;
854  }
855 
856  /* Record ACK number */
857  imux->tcp_ack = ( ntohl ( tcp->tcp.seq ) + len - sizeof ( *tcp ) );
858 
859  /* Handle received message */
860  if ( tcp->tcp.flags & TCP_SYN ) {
861 
862  /* Received SYN+ACK */
863  imux_rx_syn ( imux );
864 
865  } else {
866 
867  /* Strip header */
868  iob_pull ( iobuf, sizeof ( *tcp ) );
869 
870  /* Deliver via socket */
871  if ( ( rc = xfer_deliver_iob ( &imux->tcp,
872  iob_disown ( iobuf ) ) ) != 0 )
873  goto error;
874  }
875 
876  error:
877  free_iob ( iobuf );
878 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
uint32_t tcp_ack
Pseudo-TCP acknowledgement number.
Definition: iphone.h:142
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int xfer_deliver_iob(struct interface *intf, struct io_buffer *iobuf)
Deliver datagram as I/O buffer without metadata.
Definition: xfer.c:255
static void imux_rx_syn(struct imux *imux)
Receive pseudo-TCP SYN+ACK.
Definition: iphone.c:814
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
struct arbelprm_completion_with_error error
Definition: arbel.h:12
struct interface tcp
Pseudo-TCP lockdown socket interface.
Definition: iphone.h:147
#define DBGC(...)
Definition: compiler.h:505
uint8_t flags
Definition: tcp.h:25
uint32_t seq
Definition: tcp.h:22
An iPhone USB multiplexed pseudo-TCP message header.
Definition: iphone.h:91
#define ntohl(value)
Definition: byteswap.h:134
#define ntohs(value)
Definition: byteswap.h:136
#define TCP_RST
Definition: tcp.h:161
#define TCP_SYN
Definition: tcp.h:162
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
struct tcp_header tcp
Pseudo-TCP header.
Definition: iphone.h:95
#define DBGC_HDA(...)
Definition: compiler.h:506
uint16_t dest
Definition: tcp.h:21
#define DBGC2_HDA(...)
Definition: compiler.h:523
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
An iPhone USB multiplexer.
Definition: iphone.h:114
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:48
uint16_t port
Pseudo-TCP local port number.
Definition: iphone.h:144
#define htons(value)
Definition: byteswap.h:135

References io_buffer::data, DBGC, DBGC2_HDA, DBGC_HDA, tcp_header::dest, error, tcp_header::flags, free_iob(), htons, imux_rx_syn(), iob_disown, iob_len(), iob_pull, len, ntohl, ntohs, imux::port, rc, tcp_header::seq, imux_header_tcp::tcp, imux::tcp, imux::tcp_ack, TCP_RST, TCP_SYN, and xfer_deliver_iob().

Referenced by imux_in_complete().

◆ imux_in_complete()

static void imux_in_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
)
static

Complete bulk IN transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 887 of file iphone.c.

888  {
889  struct imux *imux = container_of ( ep, struct imux, usbnet.in );
890  struct imux_header *hdr = iobuf->data;
891  size_t len = iob_len ( iobuf );
892 
893  /* Ignore packets cancelled when the endpoint closes */
894  if ( ! ep->open )
895  goto drop;
896 
897  /* Report USB errors */
898  if ( rc != 0 ) {
899  DBGC ( imux, "IMUX %p bulk IN failed: %s\n",
900  imux, strerror ( rc ) );
901  goto drop;
902  }
903 
904  /* Sanity check */
905  if ( len < sizeof ( *hdr ) ) {
906  DBGC ( imux, "IMUX %p malformed message:\n", imux );
907  DBGC_HDA ( imux, 0, hdr, len );
908  goto drop;
909  }
910 
911  /* Record input sequence */
912  imux->in_seq = ntohs ( hdr->in_seq );
913 
914  /* Handle according to protocol */
915  DBGCP ( imux, "IMUX %p received:\n", imux );
916  DBGCP_HDA ( imux, 0, hdr, len );
917  switch ( hdr->protocol ) {
918  case htonl ( IMUX_VERSION ):
919  imux_rx_version ( imux );
920  break;
921  case htonl ( IMUX_LOG ):
922  imux_rx_log ( imux, hdr, len );
923  break;
924  case htonl ( IMUX_TCP ):
925  imux_rx_tcp ( imux, iob_disown ( iobuf ) );
926  break;
927  default:
928  DBGC ( imux, "IMUX %p unknown message type %d:\n",
929  imux, ntohl ( hdr->protocol ) );
930  DBGC_HDA ( imux, 0, hdr, len );
931  break;
932  }
933 
934  drop:
935  free_iob ( iobuf );
936 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void imux_rx_log(struct imux *imux, struct imux_header *hdr, size_t len)
Receive log message.
Definition: iphone.c:779
An iPhone USB multiplexed packet header.
Definition: iphone.h:49
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
static void imux_rx_version(struct imux *imux)
Receive version message.
Definition: iphone.c:763
TCP packet.
Definition: iphone.h:69
#define DBGC(...)
Definition: compiler.h:505
#define ntohl(value)
Definition: byteswap.h:134
#define ntohs(value)
Definition: byteswap.h:136
int open
Endpoint is open.
Definition: usb.h:404
#define htonl(value)
Definition: byteswap.h:133
static void imux_rx_tcp(struct imux *imux, struct io_buffer *iobuf)
Receive pseudo-TCP message.
Definition: iphone.c:829
Log message.
Definition: iphone.h:67
#define DBGCP_HDA(...)
Definition: compiler.h:540
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define DBGC_HDA(...)
Definition: compiler.h:506
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:29
uint16_t in_seq
Input sequence.
Definition: iphone.h:136
An iPhone USB multiplexer.
Definition: iphone.h:114
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:122
Version number.
Definition: iphone.h:65
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:48
#define DBGCP(...)
Definition: compiler.h:539

References container_of, io_buffer::data, DBGC, DBGC_HDA, DBGCP, DBGCP_HDA, free_iob(), hdr, htonl, IMUX_LOG, imux_rx_log(), imux_rx_tcp(), imux_rx_version(), IMUX_TCP, IMUX_VERSION, usbnet_device::in, imux::in_seq, iob_disown, iob_len(), len, ntohl, ntohs, usb_endpoint::open, rc, strerror(), and imux::usbnet.

◆ imux_out_complete()

static void imux_out_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
)
static

Complete bulk OUT transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 950 of file iphone.c.

951  {
952  struct imux *imux = container_of ( ep, struct imux, usbnet.out );
953 
954  /* Report USB errors */
955  if ( rc != 0 ) {
956  DBGC ( imux, "IMUX %p bulk OUT failed: %s\n",
957  imux, strerror ( rc ) );
958  goto error;
959  }
960 
961  error:
962  free_iob ( iobuf );
963 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
struct arbelprm_completion_with_error error
Definition: arbel.h:12
#define DBGC(...)
Definition: compiler.h:505
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
An iPhone USB multiplexer.
Definition: iphone.h:114
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:122

References container_of, DBGC, error, free_iob(), usbnet_device::out, rc, strerror(), and imux::usbnet.

◆ imux_shutdown()

static void imux_shutdown ( struct imux imux)
static

Shut down USB multiplexer.

Parameters
imuxUSB multiplexer

Definition at line 975 of file iphone.c.

975  {
976 
977  /* Shut down interfaces */
979 
980  /* Close USB network device, if open */
981  if ( process_running ( &imux->process ) ) {
982  process_del ( &imux->process );
983  usbnet_close ( &imux->usbnet );
984  }
985 }
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:278
struct interface tcp
Pseudo-TCP lockdown socket interface.
Definition: iphone.h:147
void process_del(struct process *process)
Remove process from process list.
Definition: process.c:79
#define ECANCELED
Operation canceled.
Definition: errno.h:343
An iPhone USB multiplexer.
Definition: iphone.h:114
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:122
static int process_running(struct process *process)
Check if process is running.
Definition: process.h:175
struct process process
Polling process.
Definition: iphone.h:127
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition: usbnet.c:127

References ECANCELED, intf_shutdown(), imux::process, process_del(), process_running(), imux::tcp, imux::usbnet, and usbnet_close().

Referenced by imux_close(), imux_probe(), and imux_remove().

◆ imux_close()

static void imux_close ( struct imux imux,
int  rc 
)
static

Close USB multiplexer.

Parameters
imuxUSB multiplexer
rcReason for close

Definition at line 993 of file iphone.c.

993  {
994  struct iphone *iphone;
995 
996  /* Restart interfaces */
997  intf_restart ( &imux->tcp, rc );
998 
999  /* Record pairing status */
1000  imux->rc = rc;
1001 
1002  /* Trigger link check on any associated iPhones */
1003  list_for_each_entry ( iphone, &iphones, list ) {
1004  if ( iphone->usb == imux->usb )
1006  }
1007 
1008  /* Retry pairing on any error */
1009  if ( rc != 0 ) {
1010 
1011  /* Increment port number */
1012  imux->port++;
1013 
1014  /* Request pairing on any retry attempt */
1016 
1017  /* Send new pseudo-TCP SYN */
1018  imux->action = imux_tx_syn;
1019 
1020  DBGC ( imux, "IMUX %p retrying pairing: %s\n",
1021  imux, strerror ( rc ) );
1022  return;
1023  }
1024 
1025  /* Shut down multiplexer on pairing success */
1026  imux_shutdown ( imux );
1027 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:343
static int imux_tx_syn(struct imux *imux)
Transmit pseudo-TCP SYN.
Definition: iphone.c:714
static void start_timer_nodelay(struct retry_timer *timer)
Start timer with no delay.
Definition: retry.h:99
int(* action)(struct imux *imux)
Pending action.
Definition: iphone.h:133
struct interface tcp
Pseudo-TCP lockdown socket interface.
Definition: iphone.h:147
#define DBGC(...)
Definition: compiler.h:505
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
Request a new pairing.
Definition: iphone.h:213
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct usb_device * usb
USB device.
Definition: iphone.h:256
An iPhone USB multiplexer.
Definition: iphone.h:114
struct usb_device * usb
USB device.
Definition: iphone.h:118
unsigned int flags
Pairing flags.
Definition: iphone.h:149
An iPhone network device.
Definition: iphone.h:254
uint16_t port
Pseudo-TCP local port number.
Definition: iphone.h:144
struct retry_timer timer
Link status check timer.
Definition: iphone.h:267
static void imux_shutdown(struct imux *imux)
Shut down USB multiplexer.
Definition: iphone.c:975
int rc
Pairing status.
Definition: iphone.h:151
struct list_head list
List of iPhone network devices.
Definition: iphone.h:265

References imux::action, DBGC, imux::flags, imux_shutdown(), imux_tx_syn(), intf_restart(), IPAIR_REQUEST, iphone::list, list_for_each_entry, imux::port, imux::rc, rc, start_timer_nodelay(), strerror(), imux::tcp, iphone::timer, imux::usb, and iphone::usb.

Referenced by imux_step().

◆ imux_alloc_iob()

static struct io_buffer* imux_alloc_iob ( struct imux *imux  __unused,
size_t  len 
)
static

Allocate I/O buffer for pseudo-TCP socket.

Parameters
imuxUSB multiplexer
lenI/O buffer payload length
Return values
iobufI/O buffer

Definition at line 1036 of file iphone.c.

1037  {
1038  struct imux_header_tcp *tcp;
1039  struct io_buffer *iobuf;
1040 
1041  /* Allocate I/O buffer */
1042  iobuf = alloc_iob ( sizeof ( *tcp ) + len );
1043  if ( ! iobuf )
1044  return NULL;
1045 
1046  /* Reserve space for pseudo-TCP message header */
1047  iob_reserve ( iobuf, sizeof ( *tcp ) );
1048 
1049  return iobuf;
1050 }
An iPhone USB multiplexed pseudo-TCP message header.
Definition: iphone.h:91
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
struct tcp_header tcp
Pseudo-TCP header.
Definition: iphone.h:95
#define iob_reserve(iobuf, len)
Definition: iobuf.h:67
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A persistent I/O buffer.
Definition: iobuf.h:33

References alloc_iob(), iob_reserve, len, NULL, and imux_header_tcp::tcp.

◆ imux_deliver()

static int imux_deliver ( struct imux imux,
struct io_buffer iobuf,
struct xfer_metadata *meta  __unused 
)
static

Transmit packet via pseudo-TCP socket.

Parameters
imuxUSB multiplexer
iobufI/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 1060 of file iphone.c.

1061  {
1062  struct imux_header_tcp *tcp;
1063 
1064  /* Prepend pseudo-TCP header */
1065  tcp = iob_push ( iobuf, sizeof ( *tcp ) );
1066  memset ( tcp, 0, sizeof ( *tcp ) );
1067  tcp->tcp.flags = TCP_ACK;
1068 
1069  /* Transmit pseudo-TCP packet */
1070  return imux_tx_tcp ( imux, iob_disown ( iobuf ) );
1071 }
#define TCP_ACK
Definition: tcp.h:159
#define iob_push(iobuf, len)
Definition: iobuf.h:84
uint8_t flags
Definition: tcp.h:25
An iPhone USB multiplexed pseudo-TCP message header.
Definition: iphone.h:91
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
struct tcp_header tcp
Pseudo-TCP header.
Definition: iphone.h:95
An iPhone USB multiplexer.
Definition: iphone.h:114
static int imux_tx_tcp(struct imux *imux, struct io_buffer *iobuf)
Transmit pseudo-TCP message.
Definition: iphone.c:683
void * memset(void *dest, int character, size_t len) __nonnull

References tcp_header::flags, imux_tx_tcp(), iob_disown, iob_push, memset(), imux_header_tcp::tcp, and TCP_ACK.

◆ imux_step()

static void imux_step ( struct imux imux)
static

Multiplexer process.

Parameters
imuxUSB multiplexer

Definition at line 1089 of file iphone.c.

1089  {
1090  int rc;
1091 
1092  /* Poll USB bus */
1093  usb_poll ( imux->bus );
1094 
1095  /* Do nothing more if multiplexer has been closed */
1096  if ( ! process_running ( &imux->process ) )
1097  return;
1098 
1099  /* Refill endpoints */
1100  if ( ( rc = usbnet_refill ( &imux->usbnet ) ) != 0 ) {
1101  /* Wait for next poll */
1102  return;
1103  }
1104 
1105  /* Perform pending action, if any */
1106  if ( imux->action ) {
1107  if ( ( rc = imux->action ( imux ) ) != 0 )
1108  imux_close ( imux, rc );
1109  imux->action = NULL;
1110  }
1111 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int(* action)(struct imux *imux)
Pending action.
Definition: iphone.h:133
int usbnet_refill(struct usbnet_device *usbnet)
Refill USB network device bulk IN and interrupt endpoints.
Definition: usbnet.c:151
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1051
struct usb_bus * bus
USB bus.
Definition: iphone.h:120
An iPhone USB multiplexer.
Definition: iphone.h:114
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:122
static int process_running(struct process *process)
Check if process is running.
Definition: process.h:175
static void imux_close(struct imux *imux, int rc)
Close USB multiplexer.
Definition: iphone.c:993
struct process process
Polling process.
Definition: iphone.h:127
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References imux::action, imux::bus, imux_close(), NULL, imux::process, process_running(), rc, usb_poll(), imux::usbnet, and usbnet_refill().

◆ imux_probe()

static int imux_probe ( struct usb_function func,
struct usb_configuration_descriptor config 
)
static

Probe device.

Parameters
funcUSB function
configConfiguration descriptor
Return values
rcReturn status code

Definition at line 1124 of file iphone.c.

1125  {
1126  struct usb_device *usb = func->usb;
1127  struct imux *imux;
1128  int rc;
1129 
1130  /* Allocate and initialise structure */
1131  imux = zalloc ( sizeof ( *imux ) );
1132  if ( ! imux ) {
1133  rc = -ENOMEM;
1134  goto err_alloc;
1135  }
1136  ref_init ( &imux->refcnt, NULL );
1137  imux->usb = usb;
1138  imux->bus = usb->port->hub->bus;
1147 
1148  /* Describe USB network device */
1149  if ( ( rc = usbnet_describe ( &imux->usbnet, config ) ) != 0 ) {
1150  DBGC ( imux, "IMUX %p could not describe: %s\n",
1151  imux, strerror ( rc ) );
1152  goto err_describe;
1153  }
1154 
1155  /* Open USB network device */
1156  if ( ( rc = usbnet_open ( &imux->usbnet ) ) != 0 ) {
1157  DBGC ( imux, "IMUX %p could not open: %s\n",
1158  imux, strerror ( rc ) );
1159  goto err_open;
1160  }
1161 
1162  /* Start polling process */
1163  process_add ( &imux->process );
1164 
1165  /* Add to list of multiplexers */
1166  list_add ( &imux->list, &imuxes );
1167 
1168  usb_func_set_drvdata ( func, imux );
1169  return 0;
1170 
1171  list_del ( &imux->list );
1172  imux_shutdown ( imux );
1173  err_open:
1174  err_describe:
1175  ref_put ( &imux->refcnt );
1176  err_alloc:
1177  return rc;
1178 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define IMUX_IN_MAX_FILL
Multiplexer bulk IN maximum fill level.
Definition: iphone.h:158
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
int(* action)(struct imux *imux)
Pending action.
Definition: iphone.h:133
static void process_init(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process and add to process list.
Definition: process.h:161
struct interface tcp
Pseudo-TCP lockdown socket interface.
Definition: iphone.h:147
#define DBGC(...)
Definition: compiler.h:505
static struct usb_endpoint_driver_operations imux_out_operations
Bulk OUT endpoint operations.
Definition: iphone.c:966
#define IMUX_PORT_LOCAL
Local port number.
Definition: iphone.h:102
static struct interface_descriptor imux_tcp_desc
Pseudo-TCP socket interface descriptor.
Definition: iphone.c:1081
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define EINPROGRESS_PAIRING
Definition: iphone.c:55
struct usb_port * port
USB port.
Definition: usb.h:712
static int imux_tx_version(struct imux *imux)
Transmit version message.
Definition: iphone.c:654
static void usb_refill_init(struct usb_endpoint *ep, size_t reserve, size_t len, unsigned int max)
Initialise USB endpoint refill.
Definition: usb.h:602
static void usb_func_set_drvdata(struct usb_function *func, void *priv)
Set USB function driver private data.
Definition: usb.h:692
A USB device.
Definition: usb.h:708
void process_add(struct process *process)
Add process to process list.
Definition: process.c:59
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:29
struct usb_bus * bus
USB bus.
Definition: iphone.h:120
An iPhone USB multiplexer.
Definition: iphone.h:114
struct usb_device * usb
USB device.
Definition: usb.h:663
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:122
struct usb_device * usb
USB device.
Definition: iphone.h:118
struct process process
Polling process.
Definition: iphone.h:127
#define IMUX_IN_MTU
Multiplexer bulk IN buffer size.
Definition: iphone.h:164
static void usbnet_init(struct usbnet_device *usbnet, struct usb_function *func, struct usb_endpoint_driver_operations *intr, struct usb_endpoint_driver_operations *in, struct usb_endpoint_driver_operations *out)
Initialise USB network device.
Definition: usbnet.h:44
struct usb_hub * hub
USB hub.
Definition: usb.h:800
uint16_t port
Pseudo-TCP local port number.
Definition: iphone.h:144
struct refcnt refcnt
Reference counter.
Definition: iphone.h:116
int usbnet_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe USB network device interfaces.
Definition: usbnet.c:277
static struct process_descriptor imux_process_desc
Multiplexer process descriptor.
Definition: iphone.c:1114
static void imux_shutdown(struct imux *imux)
Shut down USB multiplexer.
Definition: iphone.c:975
static struct usb_endpoint_driver_operations imux_in_operations
Bulk IN endpoint operations.
Definition: iphone.c:939
int rc
Pairing status.
Definition: iphone.h:151
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
struct usb_bus * bus
USB bus.
Definition: usb.h:830
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
struct list_head list
List of USB multiplexers.
Definition: iphone.h:124
int usbnet_open(struct usbnet_device *usbnet)
Open USB network device.
Definition: usbnet.c:54

References imux::action, imux::bus, usb_hub::bus, DBGC, EINPROGRESS_PAIRING, ENOMEM, usb_port::hub, IMUX_IN_MAX_FILL, IMUX_IN_MTU, imux_in_operations, imux_out_operations, IMUX_PORT_LOCAL, imux_process_desc, imux_shutdown(), imux_tcp_desc, imux_tx_version(), usbnet_device::in, intf_init(), imux::list, list_add, list_del, NULL, imux::port, usb_device::port, imux::process, process_add(), process_init(), imux::rc, rc, ref_init, ref_put, imux::refcnt, strerror(), imux::tcp, imux::usb, usb_function::usb, usb_func_set_drvdata(), usb_refill_init(), imux::usbnet, usbnet_describe(), usbnet_init(), usbnet_open(), and zalloc().

◆ imux_remove()

static void imux_remove ( struct usb_function func)
static

Remove device.

Parameters
funcUSB function

Definition at line 1185 of file iphone.c.

1185  {
1186  struct imux *imux = usb_func_get_drvdata ( func );
1187 
1188  list_del ( &imux->list );
1189  imux_shutdown ( imux );
1190  ref_put ( &imux->refcnt );
1191 }
static void * usb_func_get_drvdata(struct usb_function *func)
Get USB function driver private data.
Definition: usb.h:703
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
An iPhone USB multiplexer.
Definition: iphone.h:114
struct refcnt refcnt
Reference counter.
Definition: iphone.h:116
static void imux_shutdown(struct imux *imux)
Shut down USB multiplexer.
Definition: iphone.c:975
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
struct list_head list
List of USB multiplexers.
Definition: iphone.h:124

References imux_shutdown(), imux::list, list_del, ref_put, imux::refcnt, and usb_func_get_drvdata().

◆ ipair_tx_pubkey()

static int ipair_tx_pubkey ( struct ipair ipair)
static

Transmit DevicePublicKey message.

Parameters
ipairPairing client
Return values
rcReturn status code

Definition at line 1432 of file iphone.c.

1432  {
1433  int rc;
1434 
1435  /* Transmit message */
1436  if ( ( rc = ipair_tx ( ipair,
1437  "%s"
1438  "<string>GetValue</string>\n"
1439  "<key>Key</key>\n"
1440  "<string>DevicePublicKey</string>\n"
1441  "%s",
1442  ipair_prefix, ipair_suffix ) ) != 0 )
1443  return rc;
1444 
1445  return 0;
1446 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int ipair_tx(struct ipair *ipair, const char *fmt,...)
Transmit XML message.
Definition: iphone.c:1284
static const char ipair_prefix[]
Common prefix for all pairing messages.
Definition: iphone.c:1220
An iPhone pairing client.
Definition: iphone.h:182
static const char ipair_suffix[]
Common suffix for all pairing messages.
Definition: iphone.c:1231

References ipair_prefix, ipair_suffix, ipair_tx(), and rc.

Referenced by ipair_create().

◆ ipair_rx_pubkey()

static int ipair_rx_pubkey ( struct ipair ipair,
char *  msg 
)
static

Receive DevicePublicKey message.

Parameters
ipairPairing client
msgXML message
Return values
rcReturn status code

Definition at line 1455 of file iphone.c.

1455  {
1456  struct asn1_cursor *key;
1457  char *data;
1458  char *end;
1459  char *decoded;
1460  size_t max_len;
1461  int len;
1462  int next;
1463  int rc;
1464 
1465  /* Locate "Value" value */
1466  if ( ( rc = ipair_key ( ipair, msg, "Value", "data", &data,
1467  &end ) ) != 0 ) {
1468  DBGC ( ipair, "IPAIR %p unexpected public key message:\n%s\n",
1469  ipair, msg );
1470  goto err_tag;
1471  }
1472  *end = '\0';
1473 
1474  /* Decode outer layer of Base64 */
1476  decoded = malloc ( max_len );
1477  if ( ! decoded ) {
1478  rc = -ENOMEM;
1479  goto err_alloc;
1480  }
1481  len = base64_decode ( data, decoded, max_len );
1482  if ( len < 0 ) {
1483  rc = len;
1484  DBGC ( ipair, "IPAIR %p invalid outer public key:\n%s\n",
1485  ipair, data );
1486  goto err_decode;
1487  }
1488 
1489  /* Decode inner layer of Base64 */
1490  next = pem_asn1 ( virt_to_user ( decoded ), len, 0, &key );
1491  if ( next < 0 ) {
1492  rc = next;
1493  DBGC ( ipair, "IPAIR %p invalid inner public key:\n%s\n",
1494  ipair, decoded );
1495  goto err_asn1;
1496  }
1497  DBGC ( ipair, "IPAIR %p received public key\n", ipair );
1498  DBGC2_HDA ( ipair, 0, key->data, key->len );
1499 
1500  /* Construct certificates */
1501  if ( ( rc = icert_certs ( &ipair->icert, key ) ) != 0 )
1502  goto err_certs;
1503 
1504  /* Send session request or pair request as applicable */
1505  if ( ipair->flags & IPAIR_REQUEST ) {
1506  ipair->tx = ipair_tx_pair;
1507  ipair->rx = ipair_rx_pair;
1508  } else {
1511  }
1513 
1514  /* Free key */
1515  free ( key );
1516 
1517  /* Free intermediate Base64 */
1518  free ( decoded );
1519 
1520  return 0;
1521 
1522  err_certs:
1523  free ( key );
1524  err_asn1:
1525  err_decode:
1526  free ( decoded );
1527  err_alloc:
1528  err_tag:
1529  return rc;
1530 }
static int ipair_key(struct ipair *ipair, const char *msg, const char *key, const char *type, char **start, char **end)
Locate XML property list dictionary value.
Definition: iphone.c:1404
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void start_timer_nodelay(struct retry_timer *timer)
Start timer with no delay.
Definition: retry.h:99
int(* tx)(struct ipair *ipair)
Transmit message.
Definition: iphone.h:195
uint32_t next
Next descriptor address.
Definition: myson.h:18
uint16_t max_len
Maximum length (in bytes)
Definition: ntlm.h:18
static int ipair_rx_pair(struct ipair *ipair, char *msg)
Receive Pair message.
Definition: iphone.c:1627
#define DBGC(...)
Definition: compiler.h:505
int base64_decode(const char *encoded, void *data, size_t len)
Base64-decode string.
Definition: base64.c:91
static int ipair_rx_session(struct ipair *ipair, char *msg)
Receive StartSession message.
Definition: iphone.c:1714
static int icert_certs(struct icert *icert, struct asn1_cursor *key)
Construct certificates.
Definition: iphone.c:468
An iPhone pairing client.
Definition: iphone.h:182
#define ENOMEM
Not enough space.
Definition: errno.h:534
static size_t base64_decoded_max_len(const char *encoded)
Calculate maximum length of base64-decoded string.
Definition: base64.h:34
#define DBGC2_HDA(...)
Definition: compiler.h:523
Request a new pairing.
Definition: iphone.h:213
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
struct icert icert
Pairing certificates.
Definition: iphone.h:207
static int ipair_tx_session(struct ipair *ipair)
Transmit StartSession message.
Definition: iphone.c:1663
uint32_t len
Length.
Definition: ena.h:14
int pem_asn1(userptr_t data, size_t len, size_t offset, struct asn1_cursor **cursor)
Extract ASN.1 object from PEM data.
Definition: pem.c:105
static int ipair_tx_pair(struct ipair *ipair)
Transmit Pair message.
Definition: iphone.c:1538
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
uint32_t end
Ending offset.
Definition: netvsc.h:18
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int(* rx)(struct ipair *ipair, char *msg)
Receive message.
Definition: iphone.h:202
unsigned int flags
State flags.
Definition: iphone.h:204
An ASN.1 object cursor.
Definition: asn1.h:20
union @382 key
Sense key.
Definition: crypto.h:284
struct retry_timer timer
Pairing timer.
Definition: iphone.h:189
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285

References base64_decode(), base64_decoded_max_len(), data, DBGC, DBGC2_HDA, end, ENOMEM, ipair::flags, free, ipair::icert, icert_certs(), ipair_key(), IPAIR_REQUEST, ipair_rx_pair(), ipair_rx_session(), ipair_tx_pair(), ipair_tx_session(), key, len, malloc(), max_len, msg(), next, pem_asn1(), rc, ipair::rx, start_timer_nodelay(), ipair::timer, ipair::tx, and virt_to_user().

Referenced by ipair_create().

◆ ipair_tx_pair()

static int ipair_tx_pair ( struct ipair ipair)
static

Transmit Pair message.

Parameters
ipairPairing client
Return values
rcReturn status code

Definition at line 1538 of file iphone.c.

1538  {
1539  char *root;
1540  char *host;
1541  char *device;
1542  int rc;
1543 
1544  /* Construct doubly encoded certificates */
1545  if ( ( rc = icert_encode ( &ipair->icert, ipair->icert.root,
1546  &root ) ) != 0 )
1547  goto err_root;
1548  if ( ( rc = icert_encode ( &ipair->icert, ipair->icert.host,
1549  &host ) ) != 0 )
1550  goto err_host;
1551  if ( ( rc = icert_encode ( &ipair->icert, ipair->icert.device,
1552  &device ) ) != 0 )
1553  goto err_device;
1554 
1555  /* Transmit message */
1556  if ( ( rc = ipair_tx ( ipair,
1557  "%s"
1558  "<string>Pair</string>\n"
1559  "<key>PairRecord</key>\n"
1560  "<dict>\n"
1561  "<key>RootCertificate</key>\n"
1562  "<data>%s</data>\n"
1563  "<key>HostCertificate</key>\n"
1564  "<data>%s</data>\n"
1565  "<key>DeviceCertificate</key>\n"
1566  "<data>%s</data>\n"
1567  "<key>SystemBUID</key>\n"
1568  "<string>%s</string>\n"
1569  "<key>HostID</key>\n"
1570  "<string>%s</string>\n"
1571  "</dict>\n"
1572  "<key>ProtocolVersion</key>\n"
1573  "<string>2</string>\n"
1574  "<key>PairingOptions</key>\n"
1575  "<dict>\n"
1576  "<key>ExtendedPairingErrors</key>\n"
1577  "<true/>\n"
1578  "</dict>\n"
1579  "%s",
1580  ipair_prefix, root, host, device,
1582  ipair_suffix
1583  ) ) != 0 )
1584  goto err_tx;
1585 
1586  err_tx:
1587  free ( device );
1588  err_device:
1589  free ( host );
1590  err_host:
1591  free ( root );
1592  err_root:
1593  return rc;
1594 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct stp_switch root
Root switch.
Definition: stp.h:26
static int ipair_tx(struct ipair *ipair, const char *fmt,...)
Transmit XML message.
Definition: iphone.c:1284
static const char ipair_prefix[]
Common prefix for all pairing messages.
Definition: iphone.c:1220
static const char ipair_host_id[]
Arbitrary host ID used for pairing.
Definition: iphone.c:1239
struct x509_certificate * device
Device certificate.
Definition: iphone.h:38
uint16_t device
Device ID.
Definition: ena.h:24
An iPhone pairing client.
Definition: iphone.h:182
struct x509_certificate * host
Host certificate.
Definition: iphone.h:36
A hardware device.
Definition: device.h:73
static int icert_encode(struct icert *icert, struct x509_certificate *cert, char **encenc)
Construct doubly base64-encoded certificate.
Definition: iphone.c:551
static const char ipair_system_buid[]
Arbitrary system BUID used for pairing.
Definition: iphone.c:1236
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct x509_certificate * root
Root certificate.
Definition: iphone.h:34
static const char ipair_suffix[]
Common suffix for all pairing messages.
Definition: iphone.c:1231
struct icert icert
Pairing certificates.
Definition: iphone.h:207

References device, icert::device, free, icert::host, ipair::icert, icert_encode(), ipair_host_id, ipair_prefix, ipair_suffix, ipair_system_buid, ipair_tx(), rc, root, and icert::root.

Referenced by ipair_rx_pair_error(), ipair_rx_pubkey(), and ipair_rx_session_error().

◆ ipair_rx_pair()

static int ipair_rx_pair ( struct ipair ipair,
char *  msg 
)
static

Receive Pair message.

Parameters
ipairPairing client
msgXML message
Return values
rcReturn status code

Definition at line 1627 of file iphone.c.

1627  {
1628  char *error;
1629  char *escrow;
1630  char *end;
1631  int rc;
1632 
1633  /* Check for pairing errors */
1634  if ( ( rc = ipair_key ( ipair, msg, "Error", "string", &error,
1635  &end ) ) == 0 ) {
1636  *end = '\0';
1637  return ipair_rx_pair_error ( ipair, error );
1638  }
1639 
1640  /* Get EscrowBag */
1641  if ( ( rc = ipair_key ( ipair, msg, "EscrowBag", "data", &escrow,
1642  &end ) ) != 0 ) {
1643  DBGC ( ipair, "IPAIR %p unexpected pairing response:\n%s\n",
1644  ipair, msg );
1645  return rc;
1646  }
1647  DBGC ( ipair, "IPAIR %p pairing successful\n", ipair );
1648 
1649  /* Send session request */
1653 
1654  return 0;
1655 }
static int ipair_key(struct ipair *ipair, const char *msg, const char *key, const char *type, char **start, char **end)
Locate XML property list dictionary value.
Definition: iphone.c:1404
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void start_timer_nodelay(struct retry_timer *timer)
Start timer with no delay.
Definition: retry.h:99
int(* tx)(struct ipair *ipair)
Transmit message.
Definition: iphone.h:195
struct arbelprm_completion_with_error error
Definition: arbel.h:12
#define DBGC(...)
Definition: compiler.h:505
static int ipair_rx_session(struct ipair *ipair, char *msg)
Receive StartSession message.
Definition: iphone.c:1714
An iPhone pairing client.
Definition: iphone.h:182
static int ipair_tx_session(struct ipair *ipair)
Transmit StartSession message.
Definition: iphone.c:1663
uint32_t end
Ending offset.
Definition: netvsc.h:18
int(* rx)(struct ipair *ipair, char *msg)
Receive message.
Definition: iphone.h:202
static int ipair_rx_pair_error(struct ipair *ipair, char *error)
Receive Pair message error.
Definition: iphone.c:1603
struct retry_timer timer
Pairing timer.
Definition: iphone.h:189
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285

References DBGC, end, error, ipair_key(), ipair_rx_pair_error(), ipair_rx_session(), ipair_tx_session(), msg(), rc, ipair::rx, start_timer_nodelay(), ipair::timer, and ipair::tx.

Referenced by ipair_rx_pair_error(), ipair_rx_pubkey(), and ipair_rx_session_error().

◆ ipair_tx_session()

static int ipair_tx_session ( struct ipair ipair)
static

Transmit StartSession message.

Parameters
ipairPairing client
Return values
rcReturn status code

Definition at line 1663 of file iphone.c.

1663  {
1664  int rc;
1665 
1666  /* Transmit message */
1667  if ( ( rc = ipair_tx ( ipair,
1668  "%s"
1669  "<string>StartSession</string>\n"
1670  "<key>SystemBUID</key>\n"
1671  "<string>%s</string>\n"
1672  "<key>HostID</key>\n"
1673  "<string>%s</string>\n"
1674  "%s",
1677  ) ) != 0 )
1678  return rc;
1679 
1680  return 0;
1681 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int ipair_tx(struct ipair *ipair, const char *fmt,...)
Transmit XML message.
Definition: iphone.c:1284
static const char ipair_prefix[]
Common prefix for all pairing messages.
Definition: iphone.c:1220
static const char ipair_host_id[]
Arbitrary host ID used for pairing.
Definition: iphone.c:1239
An iPhone pairing client.
Definition: iphone.h:182
static const char ipair_system_buid[]
Arbitrary system BUID used for pairing.
Definition: iphone.c:1236
static const char ipair_suffix[]
Common suffix for all pairing messages.
Definition: iphone.c:1231

References ipair_host_id, ipair_prefix, ipair_suffix, ipair_system_buid, ipair_tx(), and rc.

Referenced by ipair_rx_pair(), and ipair_rx_pubkey().

◆ ipair_rx_session()

static int ipair_rx_session ( struct ipair ipair,
char *  msg 
)
static

Receive StartSession message.

Parameters
ipairPairing client
msgXML message
Return values
rcReturn status code

Definition at line 1714 of file iphone.c.

1714  {
1715  char *error;
1716  char *session;
1717  char *end;
1718  int rc;
1719 
1720  /* Check for session errors */
1721  if ( ( rc = ipair_key ( ipair, msg, "Error", "string", &error,
1722  &end ) ) == 0 ) {
1723  *end = '\0';
1724  return ipair_rx_session_error ( ipair, error );
1725  }
1726 
1727  /* Check for session ID */
1728  if ( ( rc = ipair_key ( ipair, msg, "SessionID", "string", &session,
1729  &end ) ) != 0 ) {
1730  DBGC ( ipair, "IPAIR %p unexpected session response:\n%s\n",
1731  ipair, msg );
1732  return rc;
1733  }
1734  *end = '\0';
1735  DBGC ( ipair, "IPAIR %p starting session \"%s\"\n", ipair, session );
1736 
1737  /* Start TLS */
1738  if ( ( rc = add_tls ( &ipair->xfer, "iPhone", &icert_root,
1739  ipair->icert.key ) ) != 0 ) {
1740  DBGC ( ipair, "IPAIR %p could not start TLS: %s\n",
1741  ipair, strerror ( rc ) );
1742  return rc;
1743  }
1744 
1745  /* Record that TLS has been started */
1746  ipair->flags |= IPAIR_TLS;
1747 
1748  return 0;
1749 }
static int ipair_key(struct ipair *ipair, const char *msg, const char *key, const char *type, char **start, char **end)
Locate XML property list dictionary value.
Definition: iphone.c:1404
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct arbelprm_completion_with_error error
Definition: arbel.h:12
static struct x509_root icert_root
Root of trust for iPhone certificates.
Definition: iphone.c:94
#define DBGC(...)
Definition: compiler.h:505
struct interface xfer
Data transfer interface.
Definition: iphone.h:186
static int ipair_rx_session_error(struct ipair *ipair, char *error)
Receive StartSession message error.
Definition: iphone.c:1690
An iPhone pairing client.
Definition: iphone.h:182
struct ntlm_data session
Session key.
Definition: ntlm.h:24
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct icert icert
Pairing certificates.
Definition: iphone.h:207
struct private_key * key
"Private" key
Definition: iphone.h:32
uint32_t end
Ending offset.
Definition: netvsc.h:18
TLS session has been started.
Definition: iphone.h:217
unsigned int flags
State flags.
Definition: iphone.h:204
int add_tls(struct interface *xfer, const char *name, struct x509_root *root, struct private_key *key)
Add TLS on an interface.
Definition: tls.c:3816
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285

References add_tls(), DBGC, end, error, ipair::flags, ipair::icert, icert_root, ipair_key(), ipair_rx_session_error(), IPAIR_TLS, icert::key, msg(), rc, session, strerror(), and ipair::xfer.

Referenced by ipair_rx_pair(), and ipair_rx_pubkey().

◆ ipair_free()

static void ipair_free ( struct refcnt refcnt)
static

Free pairing client.

Parameters
refcntReference counter

Definition at line 1253 of file iphone.c.

1253  {
1254  struct ipair *ipair = container_of ( refcnt, struct ipair, refcnt );
1255 
1256  icert_free ( &ipair->icert );
1257  free ( ipair );
1258 }
An iPhone pairing client.
Definition: iphone.h:182
A reference counter.
Definition: refcnt.h:26
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct icert icert
Pairing certificates.
Definition: iphone.h:207
static void icert_free(struct icert *icert)
Free pairing certificates.
Definition: iphone.c:330

References container_of, free, ipair::icert, and icert_free().

Referenced by ipair_create().

◆ ipair_close()

static void ipair_close ( struct ipair ipair,
int  rc 
)
static

Shut down pairing client.

Parameters
ipairPairing client
rcReason for close

Definition at line 1266 of file iphone.c.

1266  {
1267 
1268  /* Shut down interfaces */
1269  intf_shutdown ( &ipair->xfer, rc );
1270 
1271  /* Stop timer */
1272  stop_timer ( &ipair->timer );
1273 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:278
struct interface xfer
Data transfer interface.
Definition: iphone.h:186
An iPhone pairing client.
Definition: iphone.h:182
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
struct retry_timer timer
Pairing timer.
Definition: iphone.h:189

References intf_shutdown(), rc, stop_timer(), ipair::timer, and ipair::xfer.

Referenced by ipair_deliver(), ipair_expired(), and ipair_window_changed().

◆ ipair_tx()

static int ipair_tx ( struct ipair ipair,
const char *  fmt,
  ... 
)
static

Transmit XML message.

Parameters
ipairPairing client
fmtFormat string
...Arguments
Return values
rcReturn status code

Definition at line 1284 of file iphone.c.

1284  {
1285  struct io_buffer *iobuf;
1286  struct ipair_header *hdr;
1287  va_list args;
1288  size_t len;
1289  char *msg;
1290  int rc;
1291 
1292  /* Calculate length of formatted string */
1293  va_start ( args, fmt );
1294  len = ( vsnprintf ( NULL, 0, fmt, args ) + 1 /* NUL */ );
1295  va_end ( args );
1296 
1297  /* Allocate I/O buffer */
1298  iobuf = xfer_alloc_iob ( &ipair->xfer, ( sizeof ( *hdr ) + len ) );
1299  if ( ! iobuf )
1300  return -ENOMEM;
1301  hdr = iob_put ( iobuf, sizeof ( *hdr ) );
1302 
1303  /* Construct XML message */
1304  memset ( hdr, 0, sizeof ( *hdr ) );
1305  hdr->len = htonl ( len );
1306  msg = iob_put ( iobuf, len );
1307  va_start ( args, fmt );
1308  vsnprintf ( msg, len, fmt, args );
1309  va_end ( args );
1310  DBGC2 ( ipair, "IPAIR %p transmitting:\n%s\n", ipair, msg );
1311 
1312  /* Transmit message */
1313  if ( ( rc = xfer_deliver_iob ( &ipair->xfer,
1314  iob_disown ( iobuf ) ) ) != 0 )
1315  return rc;
1316 
1317  return 0;
1318 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:120
#define va_end(ap)
Definition: stdarg.h:9
int xfer_deliver_iob(struct interface *intf, struct io_buffer *iobuf)
Deliver datagram as I/O buffer without metadata.
Definition: xfer.c:255
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
struct interface xfer
Data transfer interface.
Definition: iphone.h:186
struct io_buffer * xfer_alloc_iob(struct interface *intf, size_t len)
Allocate I/O buffer.
Definition: xfer.c:158
#define htonl(value)
Definition: byteswap.h:133
An iPhone pairing client.
Definition: iphone.h:182
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
__builtin_va_list va_list
Definition: stdarg.h:6
int ssize_t const char * fmt
Definition: vsprintf.h:72
An iPhone USB multiplexed pseudo-TCP XML message header.
Definition: iphone.h:174
#define va_start(ap, last)
Definition: stdarg.h:7
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
Write a formatted string to a buffer.
Definition: vsprintf.c:351
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:33
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285

References DBGC2, ENOMEM, fmt, hdr, htonl, iob_disown, iob_put, len, memset(), msg(), NULL, rc, va_end, va_start, vsnprintf(), ipair::xfer, xfer_alloc_iob(), and xfer_deliver_iob().

Referenced by ipair_tx_pair(), ipair_tx_pubkey(), and ipair_tx_session().

◆ ipair_rx()

static int ipair_rx ( struct ipair ipair,
char *  msg,
size_t  len 
)
static

Receive XML message payload.

Parameters
ipairPairing client
msgMessage payload
lenLength of message
Return values
rcReturn status code

Definition at line 1328 of file iphone.c.

1328  {
1329  int ( * rx ) ( struct ipair *ipair, char *msg );
1330  int rc;
1331 
1332  /* Ignore empty messages */
1333  if ( ! len )
1334  return 0;
1335 
1336  /* Sanity check */
1337  if ( ( msg[ len - 1 ] != '\0' ) && ( msg[ len - 1 ] != '\n' ) ) {
1338  DBGC ( ipair, "IPAIR %p malformed XML:\n", ipair );
1339  DBGC_HDA ( ipair, 0, msg, len );
1340  return -EPROTO;
1341  }
1342 
1343  /* Add NUL terminator (potentially overwriting final newline) */
1344  msg[ len - 1 ] = '\0';
1345  DBGC2 ( ipair, "IPAIR %p received:\n%s\n\n", ipair, msg );
1346 
1347  /* Handle according to current state */
1348  rx = ipair->rx;
1349  if ( ! rx ) {
1350  DBGC ( ipair, "IPAIR %p unexpected XML:\n%s\n", ipair, msg );
1351  return -EPROTO;
1352  }
1353  ipair->rx = NULL;
1354  if ( ( rc = rx ( ipair, msg ) ) != 0 )
1355  return rc;
1356 
1357  return 0;
1358 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
An iPhone pairing client.
Definition: iphone.h:182
#define DBGC_HDA(...)
Definition: compiler.h:506
#define EPROTO
Protocol error.
Definition: errno.h:624
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
u8 rx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets from the AP.
Definition: wpa.h:234
int(* rx)(struct ipair *ipair, char *msg)
Receive message.
Definition: iphone.h:202
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285

References DBGC, DBGC2, DBGC_HDA, EPROTO, len, msg(), NULL, rc, ipair::rx, and rx.

Referenced by ipair_deliver().

◆ ipair_tag()

static int ipair_tag ( struct ipair ipair,
const char *  msg,
const char *  tag,
char **  start,
char **  end 
)
static

Locate XML tag.

Parameters
ipairPairing client
msgXML message
tagTag name
Return values
startStart of tag content
endEnd of tag content
rcReturn status code

Definition at line 1370 of file iphone.c.

1371  {
1372  char buf[ 2 /* "</" */ + strlen ( tag ) + 1 /* ">" */ + 1 /* NUL */ ];
1373 
1374  /* Locate opening tag */
1375  sprintf ( buf, "<%s>", tag );
1376  *start = strstr ( msg, buf );
1377  if ( ! *start )
1378  return -ENOENT;
1379  *start += strlen ( buf );
1380 
1381  /* Locate closing tag */
1382  sprintf ( buf, "</%s>", tag );
1383  *end = strstr ( *start, buf );
1384  if ( ! *end ) {
1385  DBGC ( ipair, "IPAIR %p missing closing tag %s in:\n%s\n",
1386  ipair, buf, msg );
1387  return -ENOENT;
1388  }
1389 
1390  return 0;
1391 }
#define sprintf(buf, fmt,...)
Write a formatted string to a buffer.
Definition: stdio.h:36
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
An iPhone pairing client.
Definition: iphone.h:182
uint32_t start
Starting offset.
Definition: netvsc.h:12
char * strstr(const char *haystack, const char *needle)
Find substring.
Definition: string.c:309
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
uint32_t end
Ending offset.
Definition: netvsc.h:18
uint64_t tag
Identity tag.
Definition: edd.h:30
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285

References DBGC, end, ENOENT, msg(), sprintf, start, strlen(), strstr(), and tag.

Referenced by ipair_key().

◆ ipair_key()

static int ipair_key ( struct ipair ipair,
const char *  msg,
const char *  key,
const char *  type,
char **  start,
char **  end 
)
static

Locate XML property list dictionary value.

Parameters
ipairPairing client
msgXML message
keyKey name
typeKey type
Return values
startStart of value content
endEnd of value content
rcReturn status code

Definition at line 1404 of file iphone.c.

1405  {
1406  int rc;
1407 
1408  /* Iterate over keys */
1409  while ( 1 ) {
1410 
1411  /* Locate key */
1412  if ( ( rc = ipair_tag ( ipair, msg, "key", start,
1413  end ) ) != 0 )
1414  return rc;
1415  msg = *end;
1416 
1417  /* Check key name */
1418  if ( memcmp ( *start, key, ( *end - *start ) ) != 0 )
1419  continue;
1420 
1421  /* Locate value */
1422  return ipair_tag ( ipair, msg, type, start, end );
1423  }
1424 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An iPhone pairing client.
Definition: iphone.h:182
uint32_t start
Starting offset.
Definition: netvsc.h:12
static int ipair_tag(struct ipair *ipair, const char *msg, const char *tag, char **start, char **end)
Locate XML tag.
Definition: iphone.c:1370
uint32_t type
Operating system type.
Definition: ena.h:12
uint32_t end
Ending offset.
Definition: netvsc.h:18
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
union @382 key
Sense key.
Definition: crypto.h:284
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285

References end, ipair_tag(), key, memcmp(), msg(), rc, start, and type.

Referenced by ipair_rx_pair(), ipair_rx_pubkey(), and ipair_rx_session().

◆ ipair_rx_pair_error()

static int ipair_rx_pair_error ( struct ipair ipair,
char *  error 
)
static

Receive Pair message error.

Parameters
ipairPairing client
errorPairing error
Return values
rcReturn status code

Definition at line 1603 of file iphone.c.

1603  {
1604 
1605  /* Check for actual errors */
1606  if ( strcmp ( error, "PairingDialogResponsePending" ) != 0 ) {
1607  DBGC ( ipair, "IPAIR %p pairing error \"%s\"\n", ipair, error );
1608  return -EPERM;
1609  }
1610 
1611  /* Retransmit pairing request */
1612  ipair->tx = ipair_tx_pair;
1613  ipair->rx = ipair_rx_pair;
1615 
1616  DBGC ( ipair, "IPAIR %p waiting for pairing dialog\n", ipair );
1617  return 0;
1618 }
int(* tx)(struct ipair *ipair)
Transmit message.
Definition: iphone.h:195
struct arbelprm_completion_with_error error
Definition: arbel.h:12
static int ipair_rx_pair(struct ipair *ipair, char *msg)
Receive Pair message.
Definition: iphone.c:1627
#define DBGC(...)
Definition: compiler.h:505
An iPhone pairing client.
Definition: iphone.h:182
#define EPERM
Operation not permitted.
Definition: errno.h:614
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition: retry.c:64
#define IPAIR_RETRY_DELAY
Pairing retry delay.
Definition: iphone.h:224
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
static int ipair_tx_pair(struct ipair *ipair)
Transmit Pair message.
Definition: iphone.c:1538
int(* rx)(struct ipair *ipair, char *msg)
Receive message.
Definition: iphone.h:202
struct retry_timer timer
Pairing timer.
Definition: iphone.h:189

References DBGC, EPERM, error, IPAIR_RETRY_DELAY, ipair_rx_pair(), ipair_tx_pair(), ipair::rx, start_timer_fixed(), strcmp(), ipair::timer, and ipair::tx.

Referenced by ipair_rx_pair().

◆ ipair_rx_session_error()

static int ipair_rx_session_error ( struct ipair ipair,
char *  error 
)
static

Receive StartSession message error.

Parameters
ipairPairing client
errorPairing error
Return values
rcReturn status code

Definition at line 1690 of file iphone.c.

1690  {
1691 
1692  /* Check for actual errors */
1693  if ( strcmp ( error, "InvalidHostID" ) != 0 ) {
1694  DBGC ( ipair, "IPAIR %p session error \"%s\"\n", ipair, error );
1695  return -EPERM;
1696  }
1697 
1698  /* Transmit pairing request */
1699  ipair->tx = ipair_tx_pair;
1700  ipair->rx = ipair_rx_pair;
1702 
1703  DBGC ( ipair, "IPAIR %p unknown host: requesting pairing\n", ipair );
1704  return 0;
1705 }
static void start_timer_nodelay(struct retry_timer *timer)
Start timer with no delay.
Definition: retry.h:99
int(* tx)(struct ipair *ipair)
Transmit message.
Definition: iphone.h:195
struct arbelprm_completion_with_error error
Definition: arbel.h:12
static int ipair_rx_pair(struct ipair *ipair, char *msg)
Receive Pair message.
Definition: iphone.c:1627
#define DBGC(...)
Definition: compiler.h:505
An iPhone pairing client.
Definition: iphone.h:182
#define EPERM
Operation not permitted.
Definition: errno.h:614
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
static int ipair_tx_pair(struct ipair *ipair)
Transmit Pair message.
Definition: iphone.c:1538
int(* rx)(struct ipair *ipair, char *msg)
Receive message.
Definition: iphone.h:202
struct retry_timer timer
Pairing timer.
Definition: iphone.h:189

References DBGC, EPERM, error, ipair_rx_pair(), ipair_tx_pair(), ipair::rx, start_timer_nodelay(), strcmp(), ipair::timer, and ipair::tx.

Referenced by ipair_rx_session().

◆ ipair_window_changed()

static void ipair_window_changed ( struct ipair ipair)
static

Handle window change notification.

Parameters
ipairPairing client

Definition at line 1756 of file iphone.c.

1756  {
1757 
1758  /* Report pairing as complete once TLS session has been established */
1759  if ( ( ipair->flags & IPAIR_TLS ) && xfer_window ( &ipair->xfer ) ) {
1760 
1761  /* Sanity checks */
1764  assert ( ! x509_is_valid ( ipair->icert.root, NULL ) );
1765  assert ( ! x509_is_valid ( ipair->icert.host, NULL ) );
1766  assert ( ! x509_is_valid ( ipair->icert.device, NULL ) );
1767 
1768  /* Report pairing as complete */
1769  DBGC ( ipair, "IPAIR %p established TLS session\n", ipair );
1770  ipair_close ( ipair, 0 );
1771  return;
1772  }
1773 }
static void ipair_close(struct ipair *ipair, int rc)
Shut down pairing client.
Definition: iphone.c:1266
static struct x509_root icert_root
Root of trust for iPhone certificates.
Definition: iphone.c:94
#define DBGC(...)
Definition: compiler.h:505
struct interface xfer
Data transfer interface.
Definition: iphone.h:186
int x509_is_valid(struct x509_certificate *cert, struct x509_root *root)
Check if X.509 certificate is valid.
Definition: x509.c:1318
struct x509_certificate * device
Device certificate.
Definition: iphone.h:38
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:116
An iPhone pairing client.
Definition: iphone.h:182
struct x509_certificate * host
Host certificate.
Definition: iphone.h:36
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct x509_certificate * root
Root certificate.
Definition: iphone.h:34
struct icert icert
Pairing certificates.
Definition: iphone.h:207
TLS session has been started.
Definition: iphone.h:217
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
unsigned int flags
State flags.
Definition: iphone.h:204

References assert(), DBGC, icert::device, ipair::flags, icert::host, ipair::icert, icert_root, ipair_close(), IPAIR_TLS, NULL, icert::root, x509_is_valid(), ipair::xfer, and xfer_window().

◆ ipair_deliver()

static int ipair_deliver ( struct ipair ipair,
struct io_buffer iobuf,
struct xfer_metadata *meta  __unused 
)
static

Handle received data.

Parameters
ipairPairing client
iobufI/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 1783 of file iphone.c.

1784  {
1785  struct ipair_header *hdr;
1786  int rc;
1787 
1788  /* Strip header (which may appear in a separate packet) */
1789  if ( ( ! ( ipair->flags & IPAIR_RX_LEN ) ) &&
1790  ( iob_len ( iobuf ) >= sizeof ( *hdr ) ) ) {
1791  iob_pull ( iobuf, sizeof ( *hdr ) );
1792  ipair->flags |= IPAIR_RX_LEN;
1793  }
1794 
1795  /* Clear received header flag if we have a message */
1796  if ( iob_len ( iobuf ) )
1797  ipair->flags &= ~IPAIR_RX_LEN;
1798 
1799  /* Receive message */
1800  if ( ( rc = ipair_rx ( ipair, iobuf->data, iob_len ( iobuf ) ) ) != 0 )
1801  goto error;
1802 
1803  /* Free I/O buffer */
1804  free_iob ( iobuf );
1805 
1806  return 0;
1807 
1808  error:
1809  ipair_close ( ipair, rc );
1810  free_iob ( iobuf );
1811  return rc;
1812 }
static void ipair_close(struct ipair *ipair, int rc)
Shut down pairing client.
Definition: iphone.c:1266
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
struct arbelprm_completion_with_error error
Definition: arbel.h:12
static int ipair_rx(struct ipair *ipair, char *msg, size_t len)
Receive XML message payload.
Definition: iphone.c:1328
An iPhone pairing client.
Definition: iphone.h:182
Standalone length has been received.
Definition: iphone.h:215
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
void * data
Start of data.
Definition: iobuf.h:48
An iPhone USB multiplexed pseudo-TCP XML message header.
Definition: iphone.h:174
unsigned int flags
State flags.
Definition: iphone.h:204

References io_buffer::data, error, ipair::flags, free_iob(), hdr, iob_len(), iob_pull, ipair_close(), ipair_rx(), IPAIR_RX_LEN, and rc.

◆ ipair_expired()

static void ipair_expired ( struct retry_timer timer,
int over  __unused 
)
static

Pairing transmission timer.

Parameters
timerRetransmission timer
overFailure indicator

Definition at line 1820 of file iphone.c.

1820  {
1821  struct ipair *ipair = container_of ( timer, struct ipair, timer );
1822  int ( * tx ) ( struct ipair *ipair );
1823  int rc;
1824 
1825  /* Sanity check */
1826  tx = ipair->tx;
1827  assert ( tx != NULL );
1828 
1829  /* Clear pending transmission */
1830  ipair->tx = NULL;
1831 
1832  /* Transmit data, if applicable */
1833  if ( ( rc = tx ( ipair ) ) != 0 )
1834  ipair_close ( ipair, rc );
1835 }
static void ipair_close(struct ipair *ipair, int rc)
Shut down pairing client.
Definition: iphone.c:1266
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int(* tx)(struct ipair *ipair)
Transmit message.
Definition: iphone.h:195
An iPhone pairing client.
Definition: iphone.h:182
A timer.
Definition: timer.h:28
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
u8 tx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets to the AP.
Definition: wpa.h:237

References assert(), container_of, ipair_close(), NULL, rc, ipair::tx, and tx.

Referenced by ipair_create().

◆ iphone_in_complete()

static void iphone_in_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
)
static

Complete bulk IN transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 1899 of file iphone.c.

1900  {
1901  struct iphone *iphone = container_of ( ep, struct iphone, usbnet.in );
1902  struct net_device *netdev = iphone->netdev;
1903 
1904  /* Profile receive completions */
1905  profile_start ( &iphone_in_profiler );
1906 
1907  /* Ignore packets cancelled when the endpoint closes */
1908  if ( ! ep->open )
1909  goto ignore;
1910 
1911  /* Record USB errors against the network device */
1912  if ( rc != 0 ) {
1913  DBGC ( iphone, "IPHONE %p bulk IN failed: %s\n",
1914  iphone, strerror ( rc ) );
1915  goto error;
1916  }
1917 
1918  /* Strip padding */
1919  if ( iob_len ( iobuf ) < IPHONE_IN_PAD ) {
1920  DBGC ( iphone, "IPHONE %p malformed bulk IN:\n", iphone );
1921  DBGC_HDA ( iphone, 0, iobuf->data, iob_len ( iobuf ) );
1922  rc = -EINVAL;
1923  goto error;
1924  }
1925  iob_pull ( iobuf, IPHONE_IN_PAD );
1926 
1927  /* Hand off to network stack */
1928  netdev_rx ( netdev, iob_disown ( iobuf ) );
1929 
1930  profile_stop ( &iphone_in_profiler );
1931  return;
1932 
1933  error:
1934  netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
1935  ignore:
1936  free_iob ( iobuf );
1937 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
#define IPHONE_IN_PAD
Bulk IN padding.
Definition: iphone.h:271
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
struct arbelprm_completion_with_error error
Definition: arbel.h:12
#define DBGC(...)
Definition: compiler.h:505
int open
Endpoint is open.
Definition: usb.h:404
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define DBGC_HDA(...)
Definition: compiler.h:506
static struct net_device * netdev
Definition: gdbudp.c:52
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
A network device.
Definition: netdevice.h:352
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:29
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:548
An iPhone network device.
Definition: iphone.h:254
void * data
Start of data.
Definition: iobuf.h:48
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:262
struct net_device * netdev
Network device.
Definition: iphone.h:260

References container_of, io_buffer::data, DBGC, DBGC_HDA, EINVAL, error, free_iob(), usbnet_device::in, iob_disown, iob_len(), iob_pull, IPHONE_IN_PAD, netdev, iphone::netdev, netdev_rx(), netdev_rx_err(), usb_endpoint::open, profile_start(), profile_stop(), rc, strerror(), and iphone::usbnet.

◆ iphone_out_transmit()

static int iphone_out_transmit ( struct iphone iphone,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
iphoneiPhone device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 1951 of file iphone.c.

1952  {
1953  int rc;
1954 
1955  /* Profile transmissions */
1956  profile_start ( &iphone_out_profiler );
1957 
1958  /* Enqueue I/O buffer */
1959  if ( ( rc = usb_stream ( &iphone->usbnet.out, iobuf, 1 ) ) != 0 )
1960  return rc;
1961 
1962  profile_stop ( &iphone_out_profiler );
1963  return 0;
1964 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition: usb.c:545
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
An iPhone network device.
Definition: iphone.h:254
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:262

References usbnet_device::out, profile_start(), profile_stop(), rc, usb_stream(), and iphone::usbnet.

Referenced by iphone_transmit().

◆ iphone_out_complete()

static void iphone_out_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
)
static

Complete bulk OUT transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 1973 of file iphone.c.

1974  {
1975  struct iphone *iphone = container_of ( ep, struct iphone, usbnet.out );
1976  struct net_device *netdev = iphone->netdev;
1977 
1978  /* Report TX completion */
1979  netdev_tx_complete_err ( netdev, iobuf, rc );
1980 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static struct net_device * netdev
Definition: gdbudp.c:52
A network device.
Definition: netdevice.h:352
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:470
An iPhone network device.
Definition: iphone.h:254
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:262
struct net_device * netdev
Network device.
Definition: iphone.h:260

References container_of, netdev, iphone::netdev, netdev_tx_complete_err(), usbnet_device::out, rc, and iphone::usbnet.

◆ iphone_check_pair()

static int iphone_check_pair ( struct iphone iphone)
static

Check pairing status.

Parameters
iphoneiPhone device
Return values
rcReturn status code

Definition at line 1993 of file iphone.c.

1993  {
1994  struct imux *imux;
1995 
1996  /* Find corresponding USB multiplexer */
1997  list_for_each_entry ( imux, &imuxes, list ) {
1998  if ( imux->usb == iphone->usb )
1999  return imux->rc;
2000  }
2001 
2002  return -EPIPE_NO_MUX;
2003 }
#define EPIPE_NO_MUX
Definition: iphone.c:51
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
struct usb_device * usb
USB device.
Definition: iphone.h:256
An iPhone USB multiplexer.
Definition: iphone.h:114
struct usb_device * usb
USB device.
Definition: iphone.h:118
An iPhone network device.
Definition: iphone.h:254
int rc
Pairing status.
Definition: iphone.h:151
struct list_head list
List of USB multiplexers.
Definition: iphone.h:124

References EPIPE_NO_MUX, imux::list, list_for_each_entry, imux::rc, imux::usb, and iphone::usb.

Referenced by iphone_check_link().

◆ iphone_check_link()

static void iphone_check_link ( struct net_device netdev)
static

Check link status.

Parameters
netdevNetwork device

Definition at line 2010 of file iphone.c.

2010  {
2011  struct iphone *iphone = netdev->priv;
2012  struct usb_device *usb = iphone->usb;
2013  uint8_t status;
2014  int rc;
2015 
2016  /* Check pairing status */
2017  if ( ( rc = iphone_check_pair ( iphone ) ) != 0 )
2018  goto err_pair;
2019 
2020  /* Get link status */
2021  if ( ( rc = usb_control ( usb, IPHONE_GET_LINK, 0, 0, &status,
2022  sizeof ( status ) ) ) != 0 ) {
2023  DBGC ( iphone, "IPHONE %p could not get link status: %s\n",
2024  iphone, strerror ( rc ) );
2025  goto err_control;
2026  }
2027 
2028  /* Check link status */
2029  if ( status != IPHONE_LINK_UP ) {
2030  rc = -ENOTCONN_STATUS ( status );
2031  goto err_status;
2032  }
2033 
2034  /* Success */
2035  rc = 0;
2036 
2037  err_status:
2038  err_control:
2039  err_pair:
2040  /* Report link status. Since we have to check the link
2041  * periodically (due to an absence of an interrupt endpoint),
2042  * do this only if the link status has actually changed.
2043  */
2044  if ( rc != netdev->link_rc ) {
2045  if ( rc == 0 ) {
2046  DBGC ( iphone, "IPHONE %p link up\n", iphone );
2047  } else {
2048  DBGC ( iphone, "IPHONE %p link down: %s\n",
2049  iphone, strerror ( rc ) );
2050  }
2051  netdev_link_err ( netdev, rc );
2052  }
2053 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int iphone_check_pair(struct iphone *iphone)
Check pairing status.
Definition: iphone.c:1993
#define DBGC(...)
Definition: compiler.h:505
int usb_control(struct usb_device *usb, unsigned int request, unsigned int value, unsigned int index, void *data, size_t len)
Issue USB control transaction.
Definition: usb.c:783
uint8_t status
Status.
Definition: ena.h:16
int link_rc
Link status code.
Definition: netdevice.h:401
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
#define ENOTCONN_STATUS(status)
Definition: iphone.c:63
A USB device.
Definition: usb.h:708
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
Definition: netdevice.c:207
struct usb_device * usb
USB device.
Definition: iphone.h:256
unsigned char uint8_t
Definition: stdint.h:10
An iPhone network device.
Definition: iphone.h:254
#define IPHONE_GET_LINK
Get link status.
Definition: iphone.h:239
Link up.
Definition: iphone.h:248

References DBGC, ENOTCONN_STATUS, iphone_check_pair(), IPHONE_GET_LINK, IPHONE_LINK_UP, net_device::link_rc, netdev, netdev_link_err(), net_device::priv, rc, status, strerror(), iphone::usb, and usb_control().

Referenced by iphone_expired(), and iphone_probe().

◆ iphone_expired()

static void iphone_expired ( struct retry_timer timer,
int over  __unused 
)
static

Periodically update link status.

Parameters
timerLink status timer
overFailure indicator

Definition at line 2061 of file iphone.c.

2061  {
2062  struct iphone *iphone = container_of ( timer, struct iphone, timer );
2063  struct net_device *netdev = iphone->netdev;
2064 
2065  /* Check link status */
2067 
2068  /* Restart timer, if device is open */
2069  if ( netdev_is_open ( netdev ) )
2071 }
static void iphone_check_link(struct net_device *netdev)
Check link status.
Definition: iphone.c:2010
A timer.
Definition: timer.h:28
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:658
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static struct net_device * netdev
Definition: gdbudp.c:52
A network device.
Definition: netdevice.h:352
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition: retry.c:64
An iPhone network device.
Definition: iphone.h:254
#define IPHONE_LINK_CHECK_INTERVAL
Link check interval.
Definition: iphone.h:289
struct net_device * netdev
Network device.
Definition: iphone.h:260

References container_of, iphone_check_link(), IPHONE_LINK_CHECK_INTERVAL, netdev, iphone::netdev, netdev_is_open(), and start_timer_fixed().

Referenced by iphone_probe().

◆ iphone_open()

static int iphone_open ( struct net_device netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 2079 of file iphone.c.

2079  {
2080  struct iphone *iphone = netdev->priv;
2081  int rc;
2082 
2083  /* Open USB network device */
2084  if ( ( rc = usbnet_open ( &iphone->usbnet ) ) != 0 ) {
2085  DBGC ( iphone, "IPHONE %p could not open: %s\n",
2086  iphone, strerror ( rc ) );
2087  goto err_open;
2088  }
2089 
2090  /* Start the link status check timer */
2092 
2093  return 0;
2094 
2095  usbnet_close ( &iphone->usbnet );
2096  err_open:
2097  return rc;
2098 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void start_timer_nodelay(struct retry_timer *timer)
Start timer with no delay.
Definition: retry.h:99
#define DBGC(...)
Definition: compiler.h:505
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
An iPhone network device.
Definition: iphone.h:254
struct retry_timer timer
Link status check timer.
Definition: iphone.h:267
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:262
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition: usbnet.c:127
int usbnet_open(struct usbnet_device *usbnet)
Open USB network device.
Definition: usbnet.c:54

References DBGC, netdev, net_device::priv, rc, start_timer_nodelay(), strerror(), iphone::timer, iphone::usbnet, usbnet_close(), and usbnet_open().

◆ iphone_close()

static void iphone_close ( struct net_device netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 2105 of file iphone.c.

2105  {
2106  struct iphone *iphone = netdev->priv;
2107 
2108  /* Stop the link status check timer */
2109  stop_timer ( &iphone->timer );
2110 
2111  /* Close USB network device */
2112  usbnet_close ( &iphone->usbnet );
2113 }
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
An iPhone network device.
Definition: iphone.h:254
struct retry_timer timer
Link status check timer.
Definition: iphone.h:267
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:262
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition: usbnet.c:127

References netdev, net_device::priv, stop_timer(), iphone::timer, iphone::usbnet, and usbnet_close().

◆ iphone_transmit()

static int iphone_transmit ( struct net_device netdev,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
netdevNetwork device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 2122 of file iphone.c.

2123  {
2124  struct iphone *iphone = netdev->priv;
2125  int rc;
2126 
2127  /* Transmit packet */
2128  if ( ( rc = iphone_out_transmit ( iphone, iobuf ) ) != 0 )
2129  return rc;
2130 
2131  return 0;
2132 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
static int iphone_out_transmit(struct iphone *iphone, struct io_buffer *iobuf)
Transmit packet.
Definition: iphone.c:1951
An iPhone network device.
Definition: iphone.h:254

References iphone_out_transmit(), netdev, net_device::priv, and rc.

◆ iphone_poll()

static void iphone_poll ( struct net_device netdev)
static

Poll for completed and received packets.

Parameters
netdevNetwork device

Definition at line 2139 of file iphone.c.

2139  {
2140  struct iphone *iphone = netdev->priv;
2141  int rc;
2142 
2143  /* Poll USB bus */
2144  usb_poll ( iphone->bus );
2145 
2146  /* Refill endpoints */
2147  if ( ( rc = usbnet_refill ( &iphone->usbnet ) ) != 0 )
2148  netdev_rx_err ( netdev, NULL, rc );
2149 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
int usbnet_refill(struct usbnet_device *usbnet)
Refill USB network device bulk IN and interrupt endpoints.
Definition: usbnet.c:151
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1051
An iPhone network device.
Definition: iphone.h:254
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:262
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct usb_bus * bus
USB bus.
Definition: iphone.h:258

References iphone::bus, netdev, netdev_rx_err(), NULL, net_device::priv, rc, usb_poll(), iphone::usbnet, and usbnet_refill().

◆ iphone_probe()

static int iphone_probe ( struct usb_function func,
struct usb_configuration_descriptor config 
)
static

Probe device.

Parameters
funcUSB function
configConfiguration descriptor
Return values
rcReturn status code

Definition at line 2166 of file iphone.c.

2167  {
2168  struct usb_device *usb = func->usb;
2169  struct net_device *netdev;
2170  struct iphone *iphone;
2171  int rc;
2172 
2173  /* Allocate and initialise structure */
2174  netdev = alloc_etherdev ( sizeof ( *iphone ) );
2175  if ( ! netdev ) {
2176  rc = -ENOMEM;
2177  goto err_alloc;
2178  }
2180  netdev->dev = &func->dev;
2181  iphone = netdev->priv;
2182  memset ( iphone, 0, sizeof ( *iphone ) );
2183  iphone->usb = usb;
2184  iphone->bus = usb->port->hub->bus;
2185  iphone->netdev = netdev;
2190  timer_init ( &iphone->timer, iphone_expired, &netdev->refcnt );
2191  DBGC ( iphone, "IPHONE %p on %s\n", iphone, func->name );
2192 
2193  /* Describe USB network device */
2194  if ( ( rc = usbnet_describe ( &iphone->usbnet, config ) ) != 0 ) {
2195  DBGC ( iphone, "IPHONE %p could not describe: %s\n",
2196  iphone, strerror ( rc ) );
2197  goto err_describe;
2198  }
2199 
2200  /* Fetch MAC address */
2201  if ( ( rc = usb_control ( usb, IPHONE_GET_MAC, 0, 0, netdev->hw_addr,
2202  ETH_ALEN ) ) != 0 ) {
2203  DBGC ( iphone, "IPHONE %p could not fetch MAC address: %s\n",
2204  iphone, strerror ( rc ) );
2205  goto err_fetch_mac;
2206  }
2207 
2208  /* Register network device */
2209  if ( ( rc = register_netdev ( netdev ) ) != 0 )
2210  goto err_register;
2211 
2212  /* Set initial link status */
2214 
2215  /* Add to list of iPhone network devices */
2216  list_add ( &iphone->list, &iphones );
2217 
2218  usb_func_set_drvdata ( func, iphone );
2219  return 0;
2220 
2221  list_del ( &iphone->list );
2223  err_register:
2224  err_fetch_mac:
2225  err_describe:
2226  netdev_nullify ( netdev );
2227  netdev_put ( netdev );
2228  err_alloc:
2229  return rc;
2230 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Name.
Definition: usb.h:661
static void iphone_check_link(struct net_device *netdev)
Check link status.
Definition: iphone.c:2010
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
#define DBGC(...)
Definition: compiler.h:505
int usb_control(struct usb_device *usb, unsigned int request, unsigned int value, unsigned int index, void *data, size_t len)
Issue USB control transaction.
Definition: usb.c:783
#define IPHONE_IN_MTU
Bulk IN buffer size.
Definition: iphone.h:277
static struct net_device_operations iphone_operations
iPhone network device operations
Definition: iphone.c:2152
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:515
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct usb_port * port
USB port.
Definition: usb.h:712
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
void * priv
Driver private data.
Definition: netdevice.h:431
static void usb_refill_init(struct usb_endpoint *ep, size_t reserve, size_t len, unsigned int max)
Initialise USB endpoint refill.
Definition: usb.h:602
static struct net_device * netdev
Definition: gdbudp.c:52
static void usb_func_set_drvdata(struct usb_function *func, void *priv)
Set USB function driver private data.
Definition: usb.h:692
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
A USB device.
Definition: usb.h:708
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:354
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:759
A network device.
Definition: netdevice.h:352
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:29
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
struct usb_device * usb
USB device.
Definition: iphone.h:256
static struct usb_endpoint_driver_operations iphone_out_operations
Bulk OUT endpoint operations.
Definition: iphone.c:1983
#define ETH_ALEN
Definition: if_ether.h:8
struct usb_device * usb
USB device.
Definition: usb.h:663
static struct usb_endpoint_driver_operations iphone_in_operations
Bulk IN endpoint operations.
Definition: iphone.c:1940
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
static void iphone_expired(struct retry_timer *timer, int over __unused)
Periodically update link status.
Definition: iphone.c:2061
An iPhone network device.
Definition: iphone.h:254
static void usbnet_init(struct usbnet_device *usbnet, struct usb_function *func, struct usb_endpoint_driver_operations *intr, struct usb_endpoint_driver_operations *in, struct usb_endpoint_driver_operations *out)
Initialise USB network device.
Definition: usbnet.h:44
struct usb_hub * hub
USB hub.
Definition: usb.h:800
#define IPHONE_IN_MAX_FILL
Bulk IN maximum fill level.
Definition: iphone.h:283
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
struct retry_timer timer
Link status check timer.
Definition: iphone.h:267
int usbnet_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe USB network device interfaces.
Definition: usbnet.c:277
#define IPHONE_GET_MAC
Get MAC address.
Definition: iphone.h:234
struct usbnet_device usbnet
USB network device.
Definition: iphone.h:262
struct device dev
Generic device.
Definition: usb.h:667
struct usb_bus * bus
USB bus.
Definition: usb.h:830
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct usb_bus * bus
USB bus.
Definition: iphone.h:258
struct net_device * netdev
Network device.
Definition: iphone.h:260
struct list_head list
List of iPhone network devices.
Definition: iphone.h:265
void * memset(void *dest, int character, size_t len) __nonnull

References alloc_etherdev(), iphone::bus, usb_hub::bus, DBGC, net_device::dev, usb_function::dev, ENOMEM, ETH_ALEN, usb_port::hub, net_device::hw_addr, usbnet_device::in, iphone_check_link(), iphone_expired(), IPHONE_GET_MAC, IPHONE_IN_MAX_FILL, IPHONE_IN_MTU, iphone_in_operations, iphone_operations, iphone_out_operations, iphone::list, list_add, list_del, memset(), usb_function::name, netdev, iphone::netdev, netdev_init(), netdev_nullify(), netdev_put(), NULL, usb_device::port, net_device::priv, rc, net_device::refcnt, register_netdev(), strerror(), iphone::timer, unregister_netdev(), iphone::usb, usb_function::usb, usb_control(), usb_func_set_drvdata(), usb_refill_init(), iphone::usbnet, usbnet_describe(), and usbnet_init().

◆ iphone_remove()

static void iphone_remove ( struct usb_function func)
static

Remove device.

Parameters
funcUSB function

Definition at line 2237 of file iphone.c.

2237  {
2238  struct iphone *iphone = usb_func_get_drvdata ( func );
2239  struct net_device *netdev = iphone->netdev;
2240 
2241  list_del ( &iphone->list );
2243  netdev_nullify ( netdev );
2244  netdev_put ( netdev );
2245 }
static void * usb_func_get_drvdata(struct usb_function *func)
Get USB function driver private data.
Definition: usb.h:703
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
A network device.
Definition: netdevice.h:352
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
An iPhone network device.
Definition: iphone.h:254
struct net_device * netdev
Network device.
Definition: iphone.h:260
struct list_head list
List of iPhone network devices.
Definition: iphone.h:265

References iphone::list, list_del, netdev, iphone::netdev, netdev_nullify(), netdev_put(), unregister_netdev(), and usb_func_get_drvdata().

◆ REQUIRING_SYMBOL()

REQUIRING_SYMBOL ( iphone_driver  )

◆ REQUIRE_OBJECT()

REQUIRE_OBJECT ( rsa_sha256  )

Variable Documentation

◆ __profiler

struct profiler iphone_out_profiler __profiler
static
Initial value:
=
{ .name = "iphone.in" }

Bulk IN completion profiler.

Bulk OUT profiler.

Definition at line 70 of file iphone.c.

◆ icert_root_fingerprint

uint8_t icert_root_fingerprint[SHA256_DIGEST_SIZE]
static

iPhone root certificate fingerprint

Definition at line 91 of file iphone.c.

Referenced by icert_certs().

◆ icert_root

struct x509_root icert_root
static
Initial value:
= {
.refcnt = REF_INIT ( ref_no_free ),
.digest = &sha256_algorithm,
.count = 1,
.fingerprints = icert_root_fingerprint,
}
static uint8_t icert_root_fingerprint[SHA256_DIGEST_SIZE]
iPhone root certificate fingerprint
Definition: iphone.c:91
struct digest_algorithm sha256_algorithm
SHA-256 algorithm.
Definition: sha256.c:264
#define REF_INIT(free_fn)
Initialise a static reference counter.
Definition: refcnt.h:77
void ref_no_free(struct refcnt *refcnt __unused)
Do not free reference-counted object.
Definition: refcnt.c:101

Root of trust for iPhone certificates.

Definition at line 94 of file iphone.c.

Referenced by icert_certs(), ipair_rx_session(), and ipair_window_changed().

◆ icert_nul

const uint8_t icert_nul[] = { 0x00 }
static

Single zero byte used in constructed certificates.

Definition at line 102 of file iphone.c.

Referenced by icert_cert(), and icert_certs().

◆ icert_rsa

const uint8_t icert_rsa[]
static
Initial value:
= {
ASN1_NULL, 0x00 )
}
#define ASN1_SHORT(tag,...)
Construct a short ASN.1 value.
Definition: asn1.h:104
#define ASN1_NULL
ASN.1 null.
Definition: asn1.h:71
#define ASN1_SEQUENCE
ASN.1 sequence.
Definition: asn1.h:89
#define ASN1_OID
ASN.1 object identifier.
Definition: asn1.h:74
#define ASN1_OID_RSAENCRYPTION
ASN.1 OID for rsaEncryption (1.2.840.113549.1.1.1)
Definition: asn1.h:131

"RSA algorithm" identifier used in constructed certificates

Definition at line 105 of file iphone.c.

Referenced by icert_cert().

◆ icert_sha256_rsa

const uint8_t icert_sha256_rsa[]
static
Initial value:
= {
ASN1_NULL, 0x00 ),
}
#define ASN1_SHORT(tag,...)
Construct a short ASN.1 value.
Definition: asn1.h:104
#define ASN1_NULL
ASN.1 null.
Definition: asn1.h:71
#define ASN1_SEQUENCE
ASN.1 sequence.
Definition: asn1.h:89
#define ASN1_OID
ASN.1 object identifier.
Definition: asn1.h:74
#define ASN1_OID_SHA256WITHRSAENCRYPTION
ASN.1 OID for sha256WithRSAEncryption (1.2.840.113549.1.1.11)
Definition: asn1.h:149

"SHA-256 with RSA algorithm" identifier used in constructed certificates

Definition at line 113 of file iphone.c.

Referenced by icert_cert().

◆ icert_root_exts_data

const uint8_t icert_root_exts_data[]
static
Initial value:
= {
0xff ) ) ) ) ) )
}
#define ASN1_SHORT(tag,...)
Construct a short ASN.1 value.
Definition: asn1.h:104
#define ASN1_BOOLEAN
ASN.1 boolean.
Definition: asn1.h:59
#define ASN1_OID_BASICCONSTRAINTS
ASN.1 OID for id-ce-basicConstraints (2.5.29.19)
Definition: asn1.h:248
#define ASN1_SEQUENCE
ASN.1 sequence.
Definition: asn1.h:89
#define ASN1_OID
ASN.1 object identifier.
Definition: asn1.h:74
#define ASN1_EXPLICIT_TAG(number)
ASN.1 explicit tag.
Definition: asn1.h:98
#define ASN1_OCTET_STRING
ASN.1 octet string.
Definition: asn1.h:68

Extensions used in constructed root certificate.

Definition at line 120 of file iphone.c.

◆ icert_root_exts

struct asn1_cursor icert_root_exts
static
Initial value:
=
static const uint8_t icert_root_exts_data[]
Extensions used in constructed root certificate.
Definition: iphone.c:120
#define ASN1_CURSOR(value)
Define an ASN.1 cursor for a static value.
Definition: asn1.h:305

Extensions used in constructed root certificate.

Definition at line 137 of file iphone.c.

Referenced by icert_certs().

◆ icert_leaf_exts_data

const uint8_t icert_leaf_exts_data[]
static
Initial value:
= {
0x00 ) ) ) ),
0x00 ) ) ) ) )
}
#define ASN1_SHORT(tag,...)
Construct a short ASN.1 value.
Definition: asn1.h:104
#define ASN1_BOOLEAN
ASN.1 boolean.
Definition: asn1.h:59
#define ASN1_OID_BASICCONSTRAINTS
ASN.1 OID for id-ce-basicConstraints (2.5.29.19)
Definition: asn1.h:248
#define ASN1_SEQUENCE
ASN.1 sequence.
Definition: asn1.h:89
#define ASN1_OID
ASN.1 object identifier.
Definition: asn1.h:74
#define ASN1_EXPLICIT_TAG(number)
ASN.1 explicit tag.
Definition: asn1.h:98
#define ASN1_OCTET_STRING
ASN.1 octet string.
Definition: asn1.h:68
#define ASN1_BIT_STRING
ASN.1 bit string.
Definition: asn1.h:65
#define ASN1_OID_KEYUSAGE
ASN.1 OID for id-ce-keyUsage (2.5.29.15)
Definition: asn1.h:243

Extensions used in constructed leaf certificates.

Definition at line 141 of file iphone.c.

◆ icert_leaf_exts

struct asn1_cursor icert_leaf_exts
static
Initial value:
=
#define ASN1_CURSOR(value)
Define an ASN.1 cursor for a static value.
Definition: asn1.h:305
static const uint8_t icert_leaf_exts_data[]
Extensions used in constructed leaf certificates.
Definition: iphone.c:141

Extensions used in constructed leaf certificates.

Definition at line 170 of file iphone.c.

Referenced by icert_certs().

◆ icert_tbs_prefix

const uint8_t icert_tbs_prefix[]
static
Initial value:
= {
ASN1_NULL, 0x00 )
}
#define ASN1_SHORT(tag,...)
Construct a short ASN.1 value.
Definition: asn1.h:104
#define ASN1_NULL
ASN.1 null.
Definition: asn1.h:71
#define ASN1_SEQUENCE
ASN.1 sequence.
Definition: asn1.h:89
#define ASN1_INTEGER
ASN.1 integer.
Definition: asn1.h:62
#define ASN1_OID
ASN.1 object identifier.
Definition: asn1.h:74
#define ASN1_EXPLICIT_TAG(number)
ASN.1 explicit tag.
Definition: asn1.h:98
#define ASN1_OID_SHA256WITHRSAENCRYPTION
ASN.1 OID for sha256WithRSAEncryption (1.2.840.113549.1.1.11)
Definition: asn1.h:149

"TBSCertificate" prefix in constructed certificates

Definition at line 174 of file iphone.c.

Referenced by icert_cert().

◆ icert_validity

const uint8_t icert_validity[]
static
Initial value:
= {
'1', '9', '7', '8', '1', '2', '1', '0',
'2', '2', '0', '0', '0', '0', 'Z' ),
'2', '9', '9', '9', '0', '1', '0', '1',
'0', '0', '0', '0', '0', '0', 'Z' ) )
}
#define ASN1_SHORT(tag,...)
Construct a short ASN.1 value.
Definition: asn1.h:104
#define ASN1_GENERALIZED_TIME
ASN.1 generalized time.
Definition: asn1.h:86
#define ASN1_SEQUENCE
ASN.1 sequence.
Definition: asn1.h:89

Validity period in constructed certificates.

Definition at line 186 of file iphone.c.

Referenced by icert_cert().

◆ icert_name_root_data

const uint8_t icert_name_root_data[]
static
Initial value:
= {
ASN1_SHORT ( ASN1_UTF8_STRING, 'R', 'o', 'o', 't' ) ) ) )
}
#define ASN1_SHORT(tag,...)
Construct a short ASN.1 value.
Definition: asn1.h:104
#define ASN1_SET
ASN.1 set.
Definition: asn1.h:92
#define ASN1_OID_COMMON_NAME
ASN.1 OID for commonName (2.5.4.3)
Definition: asn1.h:238
#define ASN1_SEQUENCE
ASN.1 sequence.
Definition: asn1.h:89
#define ASN1_UTF8_STRING
ASN.1 UTF-8 string.
Definition: asn1.h:80
#define ASN1_OID
ASN.1 object identifier.
Definition: asn1.h:74

"Root" subject name

Definition at line 200 of file iphone.c.

◆ icert_name_root

struct asn1_cursor icert_name_root
static
Initial value:
=
static const uint8_t icert_name_root_data[]
"Root" subject name
Definition: iphone.c:200
#define ASN1_CURSOR(value)
Define an ASN.1 cursor for a static value.
Definition: asn1.h:305

"Root" subject name

Definition at line 208 of file iphone.c.

Referenced by icert_certs().

◆ icert_name_ipxe_data

const uint8_t icert_name_ipxe_data[]
static
Initial value:
= {
ASN1_SHORT ( ASN1_UTF8_STRING, 'i', 'P', 'X', 'E' ) ) ) )
}
#define ASN1_SHORT(tag,...)
Construct a short ASN.1 value.
Definition: asn1.h:104
#define ASN1_SET
ASN.1 set.
Definition: asn1.h:92
#define ASN1_OID_COMMON_NAME
ASN.1 OID for commonName (2.5.4.3)
Definition: asn1.h:238
#define ASN1_SEQUENCE
ASN.1 sequence.
Definition: asn1.h:89
#define ASN1_UTF8_STRING
ASN.1 UTF-8 string.
Definition: asn1.h:80
#define ASN1_OID
ASN.1 object identifier.
Definition: asn1.h:74

"iPXE" subject name

Definition at line 212 of file iphone.c.

◆ icert_name_ipxe

struct asn1_cursor icert_name_ipxe
static
Initial value:
=
static const uint8_t icert_name_ipxe_data[]
"iPXE" subject name
Definition: iphone.c:212
#define ASN1_CURSOR(value)
Define an ASN.1 cursor for a static value.
Definition: asn1.h:305

"iPXE" subject name

Definition at line 220 of file iphone.c.

Referenced by icert_certs().

◆ icert_name_iphone_data

const uint8_t icert_name_iphone_data[]
static
Initial value:
= {
'i', 'P', 'h', 'o', 'n', 'e' ) ) ) )
}
#define ASN1_SHORT(tag,...)
Construct a short ASN.1 value.
Definition: asn1.h:104
#define ASN1_SET
ASN.1 set.
Definition: asn1.h:92
#define ASN1_OID_COMMON_NAME
ASN.1 OID for commonName (2.5.4.3)
Definition: asn1.h:238
#define ASN1_SEQUENCE
ASN.1 sequence.
Definition: asn1.h:89
#define ASN1_UTF8_STRING
ASN.1 UTF-8 string.
Definition: asn1.h:80
#define ASN1_OID
ASN.1 object identifier.
Definition: asn1.h:74

"iPhone" subject name

Definition at line 224 of file iphone.c.

◆ icert_name_iphone

struct asn1_cursor icert_name_iphone
static
Initial value:
=
#define ASN1_CURSOR(value)
Define an ASN.1 cursor for a static value.
Definition: asn1.h:305
static const uint8_t icert_name_iphone_data[]
"iPhone" subject name
Definition: iphone.c:224

"iPhone" subject name

Definition at line 233 of file iphone.c.

Referenced by icert_certs().

◆ __unused

const uint8_t icert_private_b [] __unused
static
Initial value:
= {
0x02, 0x81, 0x81, 0x00, 0xc9, 0xc0, 0xdd, 0xa6, 0xd5, 0xf9, 0x05, 0x3e,
0x1d, 0xcb, 0x67, 0x08, 0xa8, 0x50, 0x27, 0x63, 0x95, 0x87, 0x42, 0x7e,
0xfb, 0xff, 0x55, 0x55, 0xb8, 0xc0, 0x6f, 0x13, 0xcb, 0xf7, 0xc5, 0x1b,
0xda, 0x44, 0x3c, 0xbc, 0x1a, 0xe1, 0x15, 0x1e, 0xab, 0x56, 0x74, 0x02,
0x8b, 0xb3, 0xcd, 0x42, 0x56, 0xcd, 0x9c, 0xc3, 0x15, 0xe2, 0x33, 0x97,
0x6d, 0x77, 0xdd, 0x20, 0x3a, 0x74, 0xb1, 0x4c, 0xee, 0xeb, 0xe8, 0xaa,
0x20, 0x71, 0x5a, 0xa2, 0x5b, 0xf8, 0x1a, 0xcb, 0xd2, 0x7b, 0x96, 0xb6,
0x42, 0xb4, 0x7c, 0x7a, 0x13, 0xec, 0x55, 0xd3, 0x36, 0x8b, 0xe3, 0x17,
0xc5, 0xc4, 0xcc, 0xe0, 0x27, 0x8c, 0xed, 0xa1, 0x4c, 0x8a, 0x50, 0x4a,
0x1c, 0xc4, 0x58, 0xf6, 0xcd, 0xcc, 0xc3, 0x5f, 0xe6, 0x3c, 0xff, 0x97,
0x51, 0xed, 0xf5, 0xaa, 0x89, 0xcc, 0x3f, 0x63, 0x67, 0x46, 0x9f, 0xbf,
0x02, 0x03, 0x01, 0x00, 0x01
}

Public key(s) used for pairing.

"Private" key(s) used for pairing

Yes, this publicly visible "private" key completely obviates any nominal security provided by the pairing process. Looked at another way, this modifies the iPhone to behave like every other USB tethering device: if the cable is physically connected and tethering is enabled then the device will Just Work.

Unlike Android, the iPhone seems to have no meaningful permissions model: any device that is trusted to use the phone for tethering seems to also be trusted to use the iPhone for any other purpose (e.g. accessing files, reading messages, etc). Apple should probably fix this at some point, e.g. via defining extended key usages in the root and host certificates.

Definition at line 237 of file iphone.c.

◆ icert_begin

const char icert_begin[] = "-----BEGIN CERTIFICATE-----\n"
static

PEM certificate prefix.

Definition at line 320 of file iphone.c.

Referenced by icert_encode().

◆ icert_end

const char icert_end[] = "\n-----END CERTIFICATE-----\n"
static

PEM certificate suffix.

Definition at line 323 of file iphone.c.

Referenced by icert_encode().

◆ imux_in_operations

struct usb_endpoint_driver_operations imux_in_operations
static
Initial value:
= {
.complete = imux_in_complete,
}
static void imux_in_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk IN transfer.
Definition: iphone.c:887

Bulk IN endpoint operations.

Definition at line 939 of file iphone.c.

Referenced by imux_probe().

◆ imux_out_operations

struct usb_endpoint_driver_operations imux_out_operations
static
Initial value:
= {
.complete = imux_out_complete,
}
static void imux_out_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk OUT transfer.
Definition: iphone.c:950

Bulk OUT endpoint operations.

Definition at line 966 of file iphone.c.

Referenced by imux_probe().

◆ imux_tcp_operations

struct interface_operation imux_tcp_operations[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
struct io_buffer * xfer_alloc_iob(struct interface *intf, size_t len)
Allocate I/O buffer.
Definition: xfer.c:158
static int imux_deliver(struct imux *imux, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
Transmit packet via pseudo-TCP socket.
Definition: iphone.c:1060
static struct io_buffer * imux_alloc_iob(struct imux *imux __unused, size_t len)
Allocate I/O buffer for pseudo-TCP socket.
Definition: iphone.c:1036
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
An iPhone USB multiplexer.
Definition: iphone.h:114
static void imux_close(struct imux *imux, int rc)
Close USB multiplexer.
Definition: iphone.c:993

Pseudo-TCP socket interface operations.

Definition at line 1074 of file iphone.c.

◆ imux_tcp_desc

struct interface_descriptor imux_tcp_desc
static
Initial value:
=
An iPhone USB multiplexer.
Definition: iphone.h:114
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:80
static struct interface_operation imux_tcp_operations[]
Pseudo-TCP socket interface operations.
Definition: iphone.c:1074

Pseudo-TCP socket interface descriptor.

Definition at line 1081 of file iphone.c.

Referenced by imux_probe().

◆ imux_process_desc

struct process_descriptor imux_process_desc
static
Initial value:
=
A process.
Definition: process.h:17
An iPhone USB multiplexer.
Definition: iphone.h:114
#define PROC_DESC(object_type, process, _step)
Define a process descriptor.
Definition: process.h:82
static void imux_step(struct imux *imux)
Multiplexer process.
Definition: iphone.c:1089

Multiplexer process descriptor.

Definition at line 1114 of file iphone.c.

Referenced by imux_probe().

◆ imux_ids

struct usb_device_id imux_ids[]
static
Initial value:
= {
{
.name = "imux",
.vendor = 0x05ac,
.product = USB_ANY_ID,
},
}
#define USB_ANY_ID
Match-anything ID.
Definition: usb.h:1347

USB multiplexer device IDs.

Definition at line 1194 of file iphone.c.

◆ __usb_driver

struct usb_driver iphone_driver __usb_driver
Initial value:
= {
.ids = imux_ids,
.id_count = ( sizeof ( imux_ids ) / sizeof ( imux_ids[0] ) ),
.class = USB_CLASS_ID ( 0xff, 0xfe, 0x02 ),
.score = USB_SCORE_NORMAL,
.probe = imux_probe,
.remove = imux_remove,
}
static int imux_probe(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe device.
Definition: iphone.c:1124
#define USB_CLASS_ID(base, subclass, protocol)
Construct USB class ID.
Definition: usb.h:1363
Normal driver.
Definition: usb.h:1427
static void imux_remove(struct usb_function *func)
Remove device.
Definition: iphone.c:1185
static struct usb_device_id imux_ids[]
USB multiplexer device IDs.
Definition: iphone.c:1194

USB multiplexer driver.

iPhone driver

Definition at line 1203 of file iphone.c.

◆ ipair_prefix

const char ipair_prefix[]
static
Initial value:
=
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
"<plist version=\"1.0\">\n"
"<dict>\n"
"<key>Label</key>\n"
"<string>iPXE</string>\n"
"<key>Request</key>\n"

Common prefix for all pairing messages.

Definition at line 1220 of file iphone.c.

Referenced by ipair_tx_pair(), ipair_tx_pubkey(), and ipair_tx_session().

◆ ipair_suffix

const char ipair_suffix[]
static
Initial value:
=
"</dict>\n"
"</plist>\n"

Common suffix for all pairing messages.

Definition at line 1231 of file iphone.c.

Referenced by ipair_tx_pair(), ipair_tx_pubkey(), and ipair_tx_session().

◆ ipair_system_buid

const char ipair_system_buid[] = "E4DB92D2-248A-469A-AC34-92045D07E695"
static

Arbitrary system BUID used for pairing.

Definition at line 1236 of file iphone.c.

Referenced by ipair_tx_pair(), and ipair_tx_session().

◆ ipair_host_id

const char ipair_host_id[] = "93CEBC27-8457-4804-9108-F42549DF6143"
static

Arbitrary host ID used for pairing.

Definition at line 1239 of file iphone.c.

Referenced by ipair_tx_pair(), and ipair_tx_session().

◆ ipair_xfer_operations

struct interface_operation ipair_xfer_operations[]
static
Initial value:
= {
}
static void ipair_close(struct ipair *ipair, int rc)
Shut down pairing client.
Definition: iphone.c:1266
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:146
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
An iPhone pairing client.
Definition: iphone.h:182
static int ipair_deliver(struct ipair *ipair, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
Handle received data.
Definition: iphone.c:1783
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
static void ipair_window_changed(struct ipair *ipair)
Handle window change notification.
Definition: iphone.c:1756

Pairing client interface operations.

Definition at line 1838 of file iphone.c.

◆ ipair_xfer_desc

struct interface_descriptor ipair_xfer_desc
static
Initial value:
=
static struct interface_operation ipair_xfer_operations[]
Pairing client interface operations.
Definition: iphone.c:1838
An iPhone pairing client.
Definition: iphone.h:182
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:80

Pairing client interface descriptor.

Definition at line 1845 of file iphone.c.

Referenced by ipair_create().

◆ iphone_in_operations

struct usb_endpoint_driver_operations iphone_in_operations
static
Initial value:
= {
.complete = iphone_in_complete,
}
static void iphone_in_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk IN transfer.
Definition: iphone.c:1899

Bulk IN endpoint operations.

Definition at line 1940 of file iphone.c.

Referenced by iphone_probe().

◆ iphone_out_operations

struct usb_endpoint_driver_operations iphone_out_operations
static
Initial value:
= {
.complete = iphone_out_complete,
}
static void iphone_out_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk OUT transfer.
Definition: iphone.c:1973

Bulk OUT endpoint operations.

Definition at line 1983 of file iphone.c.

Referenced by iphone_probe().

◆ iphone_operations

struct net_device_operations iphone_operations
static
Initial value:
= {
.open = iphone_open,
.close = iphone_close,
.transmit = iphone_transmit,
.poll = iphone_poll,
}
static void iphone_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: iphone.c:2139
static int iphone_open(struct net_device *netdev)
Open network device.
Definition: iphone.c:2079
static int iphone_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: iphone.c:2122
static void iphone_close(struct net_device *netdev)
Close network device.
Definition: iphone.c:2105

iPhone network device operations

Definition at line 2152 of file iphone.c.

Referenced by iphone_probe().

◆ iphone_ids

struct usb_device_id iphone_ids[]
static
Initial value:
= {
{
.name = "iphone",
.vendor = 0x05ac,
.product = USB_ANY_ID,
},
}
#define USB_ANY_ID
Match-anything ID.
Definition: usb.h:1347

iPhone device IDs

Definition at line 2248 of file iphone.c.