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 | ␊ |
12 | #ifndef DEBUG_ETHERNET␊ |
13 | #define DEBUG_ETHERNET 0␊ |
14 | #endif␊ |
15 | ␊ |
16 | #if DEBUG_ETHERNET␊ |
17 | #define DBG(x...) printf(x)␊ |
18 | #else␊ |
19 | #define DBG(x...)␊ |
20 | #endif␊ |
21 | #define kEnableWifi␉␉␉"EnableWifi"␉␊ |
22 | #define kEthernetBuiltIn␉"EthernetBuiltIn"␉␊ |
23 | #define kEnableNetworking␉"EnableNetworkModule"␊ |
24 | ␊ |
25 | static void set_eth_builtin(pci_dt_t *eth_dev);␊ |
26 | static void set_wifi_airport(pci_dt_t *wlan_dev);␊ |
27 | static int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id);␊ |
28 | ␊ |
29 | ␊ |
30 | void Networking_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);␊ |
31 | ␊ |
32 | uint32_t builtin_set = 0;␊ |
33 | ␊ |
34 | void Networking_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
35 | {␊ |
36 | ␉pci_dt_t* current = arg1;␊ |
37 | ␉␊ |
38 | ␉if(current->class_id == PCI_CLASS_NETWORK_ETHERNET)␊ |
39 | ␉{␊ |
40 | ␉␉// LAN␊ |
41 | ␉␉␊ |
42 | ␉␉bool do_eth_devprop = true;␉␊ |
43 | ␉␉getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, DEFAULT_BOOT_CONFIG);␊ |
44 | ␉␉␊ |
45 | ␉␉if (do_eth_devprop)␊ |
46 | ␉␉{␊ |
47 | ␉␉␉set_eth_builtin(current);␊ |
48 | ␉␉}␊ |
49 | ␉}␊ |
50 | ␉else if(current->class_id == PCI_CLASS_NETWORK_OTHER)␊ |
51 | ␉{␊ |
52 | ␉␉// WIFI␊ |
53 | ␉␉bool do_wifi_devprop = true;␉␊ |
54 | ␉␉getBoolForKey(kEnableWifi, &do_wifi_devprop, DEFAULT_BOOT_CONFIG);␊ |
55 | ␉␉␊ |
56 | ␉␉if (do_wifi_devprop)␉␉␊ |
57 | set_wifi_airport(current);␊ |
58 | ␉␉␊ |
59 | ␉}␊ |
60 | ␉␊ |
61 | }␊ |
62 | ␊ |
63 | void Networking_start(void);␊ |
64 | void Networking_start(void)␊ |
65 | {␊ |
66 | ␉bool enable = true;␊ |
67 | ␉getBoolForKey(kEnableNetworking, &enable, DEFAULT_BOOT_CONFIG) ;␊ |
68 | ␉␊ |
69 | ␉if (enable) {␊ |
70 | ␉␉register_hook_callback("PCIDevice", &Networking_hook);␊ |
71 | ␉}␊ |
72 | }␊ |
73 | ␊ |
74 | /* a fine place for this code */␊ |
75 | ␊ |
76 | static int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id)␊ |
77 | {␊ |
78 | ␉uint8_t builtin = 0x0;␊ |
79 | ␉␊ |
80 | ␉if(device)␊ |
81 | ␉{␊ |
82 | ␉␉␊ |
83 | ␉␉if((vendor_id != 0x168c) && (builtin_set == 0)) ␊ |
84 | ␉␉{␊ |
85 | ␉␉␉builtin_set = 1;␊ |
86 | ␉␉␉builtin = 0x01;␊ |
87 | ␉␉}␊ |
88 | ␉␉␊ |
89 | ␉␉if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1))␊ |
90 | ␉␉{␊ |
91 | ␉␉␉return 0;␊ |
92 | ␉␉}␊ |
93 | ␉␉␊ |
94 | ␉␉devices_number++;␊ |
95 | ␉␉return 1;␊ |
96 | ␉}␊ |
97 | ␉else␊ |
98 | ␉{␊ |
99 | ␉␉return 0;␊ |
100 | ␉}␊ |
101 | ␉␊ |
102 | }␊ |
103 | ␊ |
104 | static void set_eth_builtin(pci_dt_t *eth_dev)␊ |
105 | {␊ |
106 | ␉char *devicepath = get_pci_dev_path(eth_dev);␊ |
107 | if (!devicepath) {␊ |
108 | return ;␊ |
109 | }␊ |
110 | ␉struct DevPropDevice *device /*= (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice))*/;␊ |
111 | ␉␊ |
112 | ␉verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);␊ |
113 | ␉␊ |
114 | ␉if (!string)␊ |
115 | ␉␉string = devprop_create_string();␊ |
116 | ␉␊ |
117 | ␉device = devprop_add_device(string, devicepath);␊ |
118 | ␉if(device)␊ |
119 | ␉{␊ |
120 | ␉␉verbose("Setting up lan keys\n");␊ |
121 | ␉␉devprop_add_network_template(device, eth_dev->vendor_id);␊ |
122 | ␉␉stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);␊ |
123 | ␉␉if(stringdata)␊ |
124 | ␉␉{␊ |
125 | ␉␉␉memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);␊ |
126 | ␉␉␉stringlength = string->length;␊ |
127 | ␉␉}␊ |
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 | ␉char *devicepath = get_pci_dev_path(wlan_dev);␊ |
151 | if (!devicepath) {␊ |
152 | return ;␊ |
153 | }␊ |
154 | ␉struct DevPropDevice *device /*= (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice))*/;␊ |
155 | ␉␊ |
156 | ␉verbose("Wifi Controller [%04x:%04x] :: %s\n", wlan_dev->vendor_id, wlan_dev->device_id, devicepath);␊ |
157 | ␉␊ |
158 | ␉if (!string)␊ |
159 | ␉␉string = devprop_create_string();␊ |
160 | ␉␊ |
161 | ␉device = devprop_add_device(string, devicepath);␊ |
162 | ␉if(device)␊ |
163 | ␉{␊ |
164 | ␉␉sprintf(tmp, "Airport");␊ |
165 | ␉␉devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp) + 1);␊ |
166 | ␉␉devprop_add_value(device, "device_type", (uint8_t *) tmp, strlen(tmp) + 1);␊ |
167 | ␊ |
168 | ␉␉␊ |
169 | ␉␉unsigned int i = 0;␊ |
170 | ␉␉for( ; i < sizeof(known_wifi_cards) / sizeof(known_wifi_cards[0]); i++)␊ |
171 | ␉␉{␊ |
172 | ␉␉␉if(wlan_dev->vendor_id == known_wifi_cards[i].vendor_id &&␊ |
173 | ␉␉␉ wlan_dev->device_id == known_wifi_cards[i].device_id)␊ |
174 | ␉␉␉{␊ |
175 | ␉␉␉␉verbose("Setting up wifi keys\n");␊ |
176 | ␉␉␉␉␊ |
177 | ␉␉␉␉devprop_add_value(device, "model", (uint8_t*)known_wifi_cards[i].model, (strlen(known_wifi_cards[i].model) + 1));␊ |
178 | ␉␉␉␉␊ |
179 | ␉␉␉␉// NOTE: I would set the subsystem id and subsystem vendor id here,␊ |
180 | ␉␉␉␉// however, those values seem to be ovverriden in the boot process.␊ |
181 | ␉␉␉␉// A batter method would be injecting the DTGP dsdt method␊ |
182 | ␉␉␉␉// and then injectinve the subsystem id there.␊ |
183 | ␉␉␉␉␊ |
184 | ␉␉␉␉stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);␊ |
185 | ␉␉␉␉if(stringdata)␊ |
186 | ␉␉␉␉{␊ |
187 | ␉␉␉␉␉memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);␊ |
188 | ␉␉␉␉␉stringlength = string->length;␊ |
189 | ␉␉␉␉}␊ |
190 | ␉␉␉␉␊ |
191 | ␉␉␉␉return;␊ |
192 | ␉␉␉␉␊ |
193 | ␉␉␉}␊ |
194 | ␉␉}␉␉␊ |
195 | ␉}␊ |
196 | }␊ |
197 | |