Root/
Source at commit 1158 created 13 years 16 days ago. By azimutz, Match nvidia.c with the one on my branch (Chazi) adding dev id's from issue 99 and Asus G74SX (0DF4, 1251). | |
---|---|
1 | /*␊ |
2 | * Copyright (c) 2009 Evan Lojewski. All rights reserved.␊ |
3 | *␊ |
4 | */␊ |
5 | ␊ |
6 | #include "libsaio.h"␊ |
7 | #include "modules.h"␊ |
8 | #include "boot.h"␊ |
9 | #include "bootstruct.h"␊ |
10 | #include "pci.h"␊ |
11 | #include "device_inject.h"␊ |
12 | ␊ |
13 | #ifndef DEBUG_ETHERNET␊ |
14 | #define DEBUG_ETHERNET 0␊ |
15 | #endif␊ |
16 | ␊ |
17 | #if DEBUG_ETHERNET␊ |
18 | #define DBG(x...) printf(x)␊ |
19 | #else␊ |
20 | #define DBG(x...)␊ |
21 | #endif␊ |
22 | ␊ |
23 | void set_eth_builtin(pci_dt_t *eth_dev);␊ |
24 | void set_wifi_airport(pci_dt_t *wlan_dev);␊ |
25 | ␊ |
26 | uint32_t builtin_set = 0;␊ |
27 | ␊ |
28 | ␊ |
29 | ␊ |
30 | void Networking_hook(void* arg1, void* arg2, void* arg3, void* arg4)␊ |
31 | {␊ |
32 | ␉pci_dt_t* current = arg1;␊ |
33 | ␉␊ |
34 | ␉if(current->class_id == PCI_CLASS_NETWORK_ETHERNET)␊ |
35 | ␉{␊ |
36 | ␉␉// LAN␊ |
37 | ␉␉␊ |
38 | ␉␉bool do_eth_devprop = false;␉␊ |
39 | ␉␉getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, &bootInfo->bootConfig);␊ |
40 | ␉␉␊ |
41 | ␉␉if (do_eth_devprop)␊ |
42 | ␉␉{␊ |
43 | ␉␉␉set_eth_builtin(current);␊ |
44 | ␉␉}␊ |
45 | ␉}␊ |
46 | ␉else if(current->class_id == PCI_CLASS_NETWORK_OTHER)␊ |
47 | ␉{␊ |
48 | ␉␉// WIFI␊ |
49 | ␉␉set_wifi_airport(current);␊ |
50 | ␉␉␊ |
51 | ␉}␊ |
52 | ␉␊ |
53 | }␊ |
54 | ␊ |
55 | void Networking_start()␊ |
56 | {␊ |
57 | ␉register_hook_callback("PCIDevice", &Networking_hook);␊ |
58 | }␊ |
59 | ␊ |
60 | /* a fine place for this code */␊ |
61 | ␊ |
62 | int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id)␊ |
63 | {␊ |
64 | ␉uint8_t builtin = 0x0;␊ |
65 | ␉␊ |
66 | ␉if(device)␊ |
67 | ␉{␊ |
68 | ␉␉␊ |
69 | ␉␉if((vendor_id != 0x168c) && (builtin_set == 0)) ␊ |
70 | ␉␉{␊ |
71 | ␉␉␉builtin_set = 1;␊ |
72 | ␉␉␉builtin = 0x01;␊ |
73 | ␉␉}␊ |
74 | ␉␉␊ |
75 | ␉␉if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1))␊ |
76 | ␉␉{␊ |
77 | ␉␉␉return 0;␊ |
78 | ␉␉}␊ |
79 | ␉␉␊ |
80 | ␉␉devices_number++;␊ |
81 | ␉␉return 1;␊ |
82 | ␉}␊ |
83 | ␉else␊ |
84 | ␉{␊ |
85 | ␉␉return 0;␊ |
86 | ␉}␊ |
87 | ␉␊ |
88 | }␊ |
89 | ␊ |
90 | void set_eth_builtin(pci_dt_t *eth_dev)␊ |
91 | {␊ |
92 | ␉char *devicepath = get_pci_dev_path(eth_dev);␊ |
93 | ␉struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice));␊ |
94 | ␉␊ |
95 | ␉verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);␊ |
96 | ␉␊ |
97 | ␉if (!string)␊ |
98 | ␉␉string = devprop_create_string();␊ |
99 | ␉␊ |
100 | ␉device = devprop_add_device(string, devicepath);␊ |
101 | ␉if(device)␊ |
102 | ␉{␊ |
103 | ␉␉verbose("Setting up lan keys\n");␊ |
104 | ␉␉devprop_add_network_template(device, eth_dev->vendor_id);␊ |
105 | ␉␉stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);␊ |
106 | ␉␉if(stringdata)␊ |
107 | ␉␉{␊ |
108 | ␉␉␉memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);␊ |
109 | ␉␉␉stringlength = string->length;␊ |
110 | ␉␉}␊ |
111 | ␉}␊ |
112 | }␊ |
113 | ␊ |
114 | ␊ |
115 | struct wifi_cards␊ |
116 | {␊ |
117 | ␉uint16_t␉vendor_id;␊ |
118 | ␉uint16_t␉device_id;␊ |
119 | ␉char*␉␉model;␊ |
120 | };␊ |
121 | ␊ |
122 | struct wifi_cards known_wifi_cards[] =␊ |
123 | {␊ |
124 | ␉{0x14e4, 0x4315, "Dell Wireless 1395"},␊ |
125 | ␉{0x14e4, 0x432b, "Dell Wireless 1510"},␊ |
126 | ␉{0x168C, 0x002B, "Atheros 9285 8802.11 b/g/n Wireless Network Adapter"},␊ |
127 | };␊ |
128 | ␊ |
129 | void set_wifi_airport(pci_dt_t *wlan_dev)␊ |
130 | {␊ |
131 | ␉char tmp[16];␊ |
132 | ␉␊ |
133 | ␉char *devicepath = get_pci_dev_path(wlan_dev);␊ |
134 | ␉struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice));␊ |
135 | ␉␊ |
136 | ␉verbose("Wifi Controller [%04x:%04x] :: %s\n", wlan_dev->vendor_id, wlan_dev->device_id, devicepath);␊ |
137 | ␉␊ |
138 | ␉if (!string)␊ |
139 | ␉␉string = devprop_create_string();␊ |
140 | ␉␊ |
141 | ␉device = devprop_add_device(string, devicepath);␊ |
142 | ␉if(device)␊ |
143 | ␉{␊ |
144 | ␉␉sprintf(tmp, "Airport");␊ |
145 | ␉␉devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp) + 1);␊ |
146 | ␉␉devprop_add_value(device, "device_type", (uint8_t *) tmp, strlen(tmp) + 1);␊ |
147 | ␊ |
148 | ␉␉␊ |
149 | ␉␉int i = 0;␊ |
150 | ␉␉for( ; i < sizeof(known_wifi_cards) / sizeof(known_wifi_cards[0]); i++)␊ |
151 | ␉␉{␊ |
152 | ␉␉␉if(wlan_dev->vendor_id == known_wifi_cards[i].vendor_id &&␊ |
153 | ␉␉␉ wlan_dev->device_id == known_wifi_cards[i].device_id)␊ |
154 | ␉␉␉{␊ |
155 | ␉␉␉␉verbose("Setting up wifi keys\n");␊ |
156 | ␉␉␉␉␊ |
157 | ␉␉␉␉devprop_add_value(device, "model", (uint8_t*)known_wifi_cards[i].model, (strlen(known_wifi_cards[i].model) + 1));␊ |
158 | ␉␉␉␉␊ |
159 | ␉␉␉␉// NOTE: I would set the subsystem id and subsystem vendor id here,␊ |
160 | ␉␉␉␉// however, those values seem to be ovverriden in the boot process.␊ |
161 | ␉␉␉␉// A batter method would be injecting the DTGP dsdt method␊ |
162 | ␉␉␉␉// and then injectinve the subsystem id there.␊ |
163 | ␉␉␉␉␊ |
164 | ␉␉␉␉stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);␊ |
165 | ␉␉␉␉if(stringdata)␊ |
166 | ␉␉␉␉{␊ |
167 | ␉␉␉␉␉memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);␊ |
168 | ␉␉␉␉␉stringlength = string->length;␊ |
169 | ␉␉␉␉}␊ |
170 | ␉␉␉␉␊ |
171 | ␉␉␉␉return;␊ |
172 | ␉␉␉␉␊ |
173 | ␉␉␉}␊ |
174 | ␉␉}␊ |
175 | ␉␉␊ |
176 | ␉␉␊ |
177 | ␉}␊ |
178 | }␊ |
179 |