Chameleon

Chameleon Svn Source Tree

Root/branches/meklortOld/i386/modules/Networking/Networking.c

Source at commit 1166 created 13 years 10 days ago.
By meklort, Fixed recent Makefile changes. Please do not use /Users/evan/SourceCode/tmp/chameleon/trunk or VPATH. the *only* time you should use /Users/evan/SourceCode/tmp/chameleon/trunk is when setting the SRCROOT variable. Also note that very soon make pkg is going to be removed. The pkg build script in trunk is very out of date. Instead please use the package maker at http://forge.voodooprojects.org/p/chameleonApplications/. Once this is ready for trunk it will be merged.
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
23void set_eth_builtin(pci_dt_t *eth_dev);
24void set_wifi_airport(pci_dt_t *wlan_dev);
25
26uint32_t builtin_set = 0;
27
28
29
30void Networking_hook(void* arg1, void* arg2, void* arg3, void* arg4)
31{
32pci_dt_t* current = arg1;
33
34if(current->class_id == PCI_CLASS_NETWORK_ETHERNET)
35{
36// LAN
37
38bool do_eth_devprop = false;
39getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, &bootInfo->bootConfig);
40
41if (do_eth_devprop)
42{
43set_eth_builtin(current);
44}
45}
46else if(current->class_id == PCI_CLASS_NETWORK_OTHER)
47{
48// WIFI
49set_wifi_airport(current);
50
51}
52
53}
54
55void Networking_start()
56{
57register_hook_callback("PCIDevice", &Networking_hook);
58}
59
60/* a fine place for this code */
61
62int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id)
63{
64uint8_t builtin = 0x0;
65
66if(device)
67{
68
69if((vendor_id != 0x168c) && (builtin_set == 0))
70{
71builtin_set = 1;
72builtin = 0x01;
73}
74
75if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1))
76{
77return 0;
78}
79
80devices_number++;
81return 1;
82}
83else
84{
85return 0;
86}
87
88}
89
90void set_eth_builtin(pci_dt_t *eth_dev)
91{
92char *devicepath = get_pci_dev_path(eth_dev);
93struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice));
94
95verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);
96
97if (!string)
98string = devprop_create_string();
99
100device = devprop_add_device(string, devicepath);
101if(device)
102{
103verbose("Setting up lan keys\n");
104devprop_add_network_template(device, eth_dev->vendor_id);
105stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);
106if(stringdata)
107{
108memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
109stringlength = string->length;
110}
111}
112}
113
114
115struct wifi_cards
116{
117uint16_tvendor_id;
118uint16_tdevice_id;
119char*model;
120};
121
122struct 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
129void set_wifi_airport(pci_dt_t *wlan_dev)
130{
131char tmp[16];
132
133char *devicepath = get_pci_dev_path(wlan_dev);
134struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice));
135
136verbose("Wifi Controller [%04x:%04x] :: %s\n", wlan_dev->vendor_id, wlan_dev->device_id, devicepath);
137
138if (!string)
139string = devprop_create_string();
140
141device = devprop_add_device(string, devicepath);
142if(device)
143{
144sprintf(tmp, "Airport");
145devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp) + 1);
146devprop_add_value(device, "device_type", (uint8_t *) tmp, strlen(tmp) + 1);
147
148
149int i = 0;
150for( ; i < sizeof(known_wifi_cards) / sizeof(known_wifi_cards[0]); i++)
151{
152if(wlan_dev->vendor_id == known_wifi_cards[i].vendor_id &&
153 wlan_dev->device_id == known_wifi_cards[i].device_id)
154{
155verbose("Setting up wifi keys\n");
156
157devprop_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
164stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);
165if(stringdata)
166{
167memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
168stringlength = string->length;
169}
170
171return;
172
173}
174}
175
176
177}
178}
179

Archive Download this file

Revision: 1166