1 | /*␊ |
2 | * Copyright (c) 2009 Evan Lojewski. All rights reserved.␊ |
3 | *␊ |
4 | */␊ |
5 | ␊ |
6 | #include "libsaio.h"␊ |
7 | #include "modules.h"␊ |
8 | #include "bootstruct.h"␊ |
9 | #include "pci.h"␊ |
10 | #include "device_inject.h"␊ |
11 | #include "platform.h"␊ |
12 | #include "fake_efi.h"␊ |
13 | ␊ |
14 | #ifndef DEBUG_ETHERNET␊ |
15 | #define DEBUG_ETHERNET 0␊ |
16 | #endif␊ |
17 | ␊ |
18 | #if DEBUG_ETHERNET␊ |
19 | #define DBG(x...) printf(x)␊ |
20 | #else␊ |
21 | #define DBG(x...)␊ |
22 | #endif␊ |
23 | #define kEnableWifi␉␉␉"EnableWifi"␉␊ |
24 | #define kEthernetBuiltIn␉"EthernetBuiltIn"␉␊ |
25 | ␊ |
26 | static void set_eth_builtin(pci_dt_t *eth_dev);␊ |
27 | static void set_wifi_airport(pci_dt_t *wlan_dev);␊ |
28 | static int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id);␊ |
29 | ␊ |
30 | ␊ |
31 | void Networking_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);␊ |
32 | ␊ |
33 | uint32_t builtin_set = 0;␊ |
34 | ␊ |
35 | void Networking_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
36 | {␊ |
37 | ␉pci_dt_t* current = arg1;␊ |
38 | ␉␊ |
39 | ␉if(current->class_id == PCI_CLASS_NETWORK_ETHERNET)␊ |
40 | ␉{␊ |
41 | ␉␉// LAN␊ |
42 | ␉␉␊ |
43 | ␉␉bool do_eth_devprop = true;␉␊ |
44 | ␉␉getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, DEFAULT_BOOT_CONFIG);␊ |
45 | ␉␉␊ |
46 | ␉␉if (do_eth_devprop)␊ |
47 | ␉␉{␊ |
48 | ␉␉␉set_eth_builtin(current);␊ |
49 | ␉␉}␊ |
50 | ␉}␊ |
51 | ␉else if(current->class_id == PCI_CLASS_NETWORK_OTHER)␊ |
52 | ␉{␊ |
53 | ␉␉// WIFI␊ |
54 | ␉␉bool do_wifi_devprop = true;␉␊ |
55 | ␉␉getBoolForKey(kEnableWifi, &do_wifi_devprop, DEFAULT_BOOT_CONFIG);␊ |
56 | ␉␉␊ |
57 | ␉␉if (do_wifi_devprop)␉␉␊ |
58 | set_wifi_airport(current);␊ |
59 | ␉␉␊ |
60 | ␉}␊ |
61 | ␉␊ |
62 | }␊ |
63 | ␊ |
64 | void Networking_start(void);␊ |
65 | void Networking_start(void)␊ |
66 | {␉␊ |
67 | ␉register_device_inject();␊ |
68 | ␉register_hook_callback("PCIDevice", &Networking_hook);␊ |
69 | }␊ |
70 | ␊ |
71 | /* a fine place for this code */␊ |
72 | ␊ |
73 | static int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id)␊ |
74 | {␊ |
75 | ␉uint8_t builtin = 0x0;␊ |
76 | ␉␊ |
77 | ␉if(device)␊ |
78 | ␉{␊ |
79 | uint32_t devices_number;␊ |
80 | ␉␉␊ |
81 | ␉␉if((vendor_id != 0x168c) && (builtin_set == 0)) ␊ |
82 | ␉␉{␊ |
83 | ␉␉␉builtin_set = 1;␊ |
84 | ␉␉␉builtin = 0x01;␊ |
85 | ␉␉}␊ |
86 | ␉␉␊ |
87 | ␉␉if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1))␊ |
88 | ␉␉{␊ |
89 | ␉␉␉return 0;␊ |
90 | ␉␉}␊ |
91 | ␉␉␊ |
92 | if (!(devices_number = (uint32_t)get_env(envDeviceNumber))) {␊ |
93 | devices_number = 1;␊ |
94 | } ␊ |
95 | ␊ |
96 | ␊ |
97 | safe_set_env(envDeviceNumber,devices_number+1); ␊ |
98 | ␊ |
99 | ␉␉return 1;␊ |
100 | ␉}␊ |
101 | ␉else␊ |
102 | ␉{␊ |
103 | ␉␉return 0;␊ |
104 | ␉}␊ |
105 | ␉␊ |
106 | }␊ |
107 | ␊ |
108 | static void set_eth_builtin(pci_dt_t *eth_dev)␊ |
109 | {␉␊ |
110 | ␉struct DevPropDevice *device;␊ |
111 | struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString);␊ |
112 | ␊ |
113 | ␉verbose("LAN Controller [%04x:%04x]\n", eth_dev->vendor_id, eth_dev->device_id);␊ |
114 | ␉␊ |
115 | ␉if (!string)␊ |
116 | {␊ |
117 | ␉␉string = devprop_create_string();␊ |
118 | if (!string) return;␊ |
119 | safe_set_env(envEFIString,(uint32_t)string);␊ |
120 | ␉}␊ |
121 | ␊ |
122 | ␉device = devprop_add_device(string, eth_dev);␊ |
123 | ␉if(device)␊ |
124 | ␉{␊ |
125 | ␉␉verbose("Setting up lan keys\n");␊ |
126 | ␉␉devprop_add_network_template(device, eth_dev->vendor_id);␊ |
127 | devprop_generate_string(string);␉␉␊ |
128 | ␉}␊ |
129 | }␊ |
130 | ␊ |
131 | ␊ |
132 | struct wifi_cards␊ |
133 | {␊ |
134 | ␉uint16_t␉vendor_id;␊ |
135 | ␉uint16_t␉device_id;␊ |
136 | ␉char*␉␉model;␊ |
137 | };␊ |
138 | ␊ |
139 | struct wifi_cards known_wifi_cards[] =␊ |
140 | {␊ |
141 | ␉{0x14e4, 0x4315, "Dell Wireless 1395"},␊ |
142 | ␉{0x14e4, 0x432b, "Dell Wireless 1510"},␊ |
143 | ␉{0x168C, 0x002B, "Atheros 9285 8802.11 b/g/n Wireless Network Adapter"},␊ |
144 | };␊ |
145 | ␊ |
146 | static void set_wifi_airport(pci_dt_t *wlan_dev)␊ |
147 | {␊ |
148 | ␉char tmp[16];␊ |
149 | ␉␉␊ |
150 | ␉struct DevPropDevice *device ;␊ |
151 | struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString);␊ |
152 | ␊ |
153 | ␉verbose("Wifi Controller [%04x:%04x]\n", wlan_dev->vendor_id, wlan_dev->device_id);␊ |
154 | ␉␊ |
155 | ␉if (!string)␊ |
156 | {␊ |
157 | ␉␉string = devprop_create_string();␊ |
158 | if (!string) return;␊ |
159 | safe_set_env(envEFIString,(uint32_t)string);␊ |
160 | ␉}␊ |
161 | ␊ |
162 | ␉device = devprop_add_device(string, wlan_dev);␊ |
163 | ␉if(device)␊ |
164 | ␉{␊ |
165 | ␉␉snprintf(tmp, sizeof(tmp),"Airport");␊ |
166 | ␉␉devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp) + 1);␊ |
167 | ␉␉devprop_add_value(device, "device_type", (uint8_t *) tmp, strlen(tmp) + 1);␊ |
168 | ␊ |
169 | ␉␉␊ |
170 | ␉␉unsigned int i = 0;␊ |
171 | ␉␉for( ; i < sizeof(known_wifi_cards) / sizeof(known_wifi_cards[0]); i++)␊ |
172 | ␉␉{␊ |
173 | ␉␉␉if(wlan_dev->vendor_id == known_wifi_cards[i].vendor_id &&␊ |
174 | ␉␉␉ wlan_dev->device_id == known_wifi_cards[i].device_id)␊ |
175 | ␉␉␉{␊ |
176 | ␉␉␉␉verbose("Setting up wifi keys\n");␊ |
177 | ␉␉␉␉␊ |
178 | ␉␉␉␉devprop_add_value(device, "model", (uint8_t*)known_wifi_cards[i].model, (strlen(known_wifi_cards[i].model) + 1));␉␉␉␉␊ |
179 | ␉␉␉␉ ␊ |
180 | ␉␉␉␉return;␊ |
181 | ␉␉␉␉␊ |
182 | ␉␉␉}␊ |
183 | ␉␉}␉␉␊ |
184 | ␉}␊ |
185 | }␊ |
186 | |