Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 1119