MobileApple80211.c 4.2 KB

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