Home | History | Annotate | Download | only in drivers
      1 #include "includes.h"
      2 #include <dlfcn.h>
      3 
      4 #include "common.h"
      5 
      6 #include <CoreFoundation/CoreFoundation.h>
      7 #include "MobileApple80211.h"
      8 
      9 /*
     10  * Code for dynamically loading Apple80211 functions from Aeropuerto to avoid
     11  * having to link with full Preferences.framework.
     12  */
     13 
     14 static void *aeropuerto = NULL;
     15 
     16 
     17 int _Apple80211Initialized(void)
     18 {
     19 	return aeropuerto ? 1 : 0;
     20 }
     21 
     22 
     23 static int (*__Apple80211Open)(Apple80211Ref *ctx) = NULL;
     24 
     25 int Apple80211Open(Apple80211Ref *ctx)
     26 {
     27 	return __Apple80211Open(ctx);
     28 }
     29 
     30 
     31 static int (*__Apple80211Close)(Apple80211Ref ctx) = NULL;
     32 
     33 int Apple80211Close(Apple80211Ref ctx)
     34 {
     35 	return __Apple80211Close(ctx);
     36 }
     37 
     38 
     39 static int (*__Apple80211GetIfListCopy)(Apple80211Ref handle, CFArrayRef *list)
     40 	= NULL;
     41 
     42 int Apple80211GetIfListCopy(Apple80211Ref handle, CFArrayRef *list)
     43 {
     44 	return __Apple80211GetIfListCopy(handle, list);
     45 }
     46 
     47 
     48 static int (*__Apple80211BindToInterface)(Apple80211Ref handle,
     49 					  CFStringRef interface) = NULL;
     50 
     51 int Apple80211BindToInterface(Apple80211Ref handle,
     52 			      CFStringRef interface)
     53 {
     54 	return __Apple80211BindToInterface(handle, interface);
     55 }
     56 
     57 
     58 static int (*__Apple80211GetInterfaceNameCopy)(Apple80211Ref handle,
     59 					       CFStringRef *name) = NULL;
     60 
     61 int Apple80211GetInterfaceNameCopy(Apple80211Ref handle,
     62 				   CFStringRef *name)
     63 {
     64 	return __Apple80211GetInterfaceNameCopy(handle, name);
     65 }
     66 
     67 
     68 static int (*__Apple80211GetInfoCopy)(Apple80211Ref handle,
     69 				      CFDictionaryRef *info) = NULL;
     70 
     71 int Apple80211GetInfoCopy(Apple80211Ref handle,
     72 			  CFDictionaryRef *info)
     73 {
     74 	return __Apple80211GetInfoCopy(handle, info);
     75 }
     76 
     77 
     78 static int (*__Apple80211GetPower)(Apple80211Ref handle, char *pwr) = NULL;
     79 
     80 int Apple80211GetPower(Apple80211Ref handle, char *pwr)
     81 {
     82 	return __Apple80211GetPower(handle, pwr);
     83 }
     84 
     85 
     86 static int (*__Apple80211SetPower)(Apple80211Ref handle, char pwr) = NULL;
     87 
     88 int Apple80211SetPower(Apple80211Ref handle, char pwr)
     89 {
     90 	return __Apple80211SetPower(handle, pwr);
     91 }
     92 
     93 
     94 static int (*__Apple80211Scan)(Apple80211Ref handle, CFArrayRef *list,
     95 			       CFDictionaryRef parameters) = NULL;
     96 
     97 int Apple80211Scan(Apple80211Ref handle, CFArrayRef *list,
     98 		   CFDictionaryRef parameters)
     99 {
    100 	return __Apple80211Scan(handle, list, parameters);
    101 }
    102 
    103 
    104 static int (*__Apple80211Associate)(Apple80211Ref handle, CFDictionaryRef bss,
    105 				    CFStringRef password) = NULL;
    106 
    107 int Apple80211Associate(Apple80211Ref handle, CFDictionaryRef bss,
    108 			CFStringRef password)
    109 {
    110 	return __Apple80211Associate(handle, bss, password);
    111 }
    112 
    113 
    114 static int (*__Apple80211AssociateAndCopyInfo)(Apple80211Ref handle,
    115 					       CFDictionaryRef bss,
    116 					       CFStringRef password,
    117 					       CFDictionaryRef *info) =
    118 	NULL;
    119 
    120 int Apple80211AssociateAndCopyInfo(Apple80211Ref handle, CFDictionaryRef bss,
    121 				   CFStringRef password, CFDictionaryRef *info)
    122 {
    123 	return __Apple80211AssociateAndCopyInfo(handle, bss, password, info);
    124 }
    125 
    126 
    127 static int (*__Apple80211CopyValue)(Apple80211Ref handle, int field,
    128 				    CFDictionaryRef arg2, void *value) = NULL;
    129 
    130 int Apple80211CopyValue(Apple80211Ref handle, int field, CFDictionaryRef arg2,
    131 			void *value)
    132 {
    133 	return __Apple80211CopyValue(handle, field, arg2, value);
    134 }
    135 
    136 
    137 #define DLSYM(s) \
    138 do { \
    139 	__ ## s = dlsym(aeropuerto, #s); \
    140 	if (__ ## s == NULL) { \
    141 		wpa_printf(MSG_ERROR, "MobileApple80211: Could not resolve " \
    142 			   "symbol '" #s "' (%s)", dlerror()); \
    143 		err = 1; \
    144 	} \
    145 } while (0)
    146 
    147 
    148 __attribute__ ((constructor))
    149 void _Apple80211_constructor(void)
    150 {
    151 	const char *fname = "/System/Library/SystemConfiguration/"
    152 		"Aeropuerto.bundle/Aeropuerto";
    153 	int err = 0;
    154 
    155 	aeropuerto = dlopen(fname, RTLD_LAZY);
    156 	if (!aeropuerto) {
    157 		wpa_printf(MSG_ERROR, "MobileApple80211: Failed to open %s "
    158 			   "for symbols", fname);
    159 		return;
    160 	}
    161 
    162 	DLSYM(Apple80211Open);
    163 	DLSYM(Apple80211Close);
    164 	DLSYM(Apple80211GetIfListCopy);
    165 	DLSYM(Apple80211BindToInterface);
    166 	DLSYM(Apple80211GetInterfaceNameCopy);
    167 	DLSYM(Apple80211GetInfoCopy);
    168 	DLSYM(Apple80211GetPower);
    169 	DLSYM(Apple80211SetPower);
    170 	DLSYM(Apple80211Scan);
    171 	DLSYM(Apple80211Associate);
    172 	DLSYM(Apple80211AssociateAndCopyInfo);
    173 	DLSYM(Apple80211CopyValue);
    174 
    175 	if (err) {
    176 		dlclose(aeropuerto);
    177 		aeropuerto = NULL;
    178 	}
    179 }
    180 
    181 
    182 __attribute__ ((destructor))
    183 void _Apple80211_destructor(void)
    184 {
    185 	if (aeropuerto) {
    186 		dlclose(aeropuerto);
    187 		aeropuerto = NULL;
    188 	}
    189 }
    190