105 |
|
* Initialization |
106 |
|
*/ |
107 |
|
|
108 |
< |
void EtherInit(void) |
108 |
> |
bool ether_init(void) |
109 |
|
{ |
110 |
|
// Do nothing if no Ethernet device specified |
111 |
|
if (PrefsFindString("ether") == NULL) |
112 |
< |
return; |
112 |
> |
return false; |
113 |
|
|
114 |
|
// Find net_server team |
115 |
|
i_wanna_try_that_again: |
148 |
|
// It was found, so something else must be wrong |
149 |
|
if (sheep_net_found) { |
150 |
|
WarningAlert(GetString(STR_NO_NET_ADDON_WARN)); |
151 |
< |
return; |
151 |
> |
return false; |
152 |
|
} |
153 |
|
|
154 |
|
// Not found, inform the user |
155 |
|
if (!ChoiceAlert(GetString(STR_NET_CONFIG_MODIFY_WARN), GetString(STR_OK_BUTTON), GetString(STR_CANCEL_BUTTON))) |
156 |
< |
return; |
156 |
> |
return false; |
157 |
|
|
158 |
|
// Change the network config file and restart the network |
159 |
|
fin = fopen("/boot/home/config/settings/network", "r"); |
208 |
|
area_id handler_buffer; |
209 |
|
if ((handler_buffer = find_area("packet buffer")) < B_NO_ERROR) { |
210 |
|
WarningAlert(GetString(STR_NET_ADDON_INIT_FAILED)); |
211 |
< |
return; |
211 |
> |
return false; |
212 |
|
} |
213 |
|
if ((buffer_area = clone_area("local packet buffer", (void **)&net_buffer_ptr, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, handler_buffer)) < B_NO_ERROR) { |
214 |
|
D(bug("EtherInit: couldn't clone packet area\n")); |
215 |
|
WarningAlert(GetString(STR_NET_ADDON_CLONE_FAILED)); |
216 |
< |
return; |
216 |
> |
return false; |
217 |
|
} |
218 |
|
if ((read_sem = create_sem(0, "ether read")) < B_NO_ERROR) { |
219 |
|
printf("FATAL: can't create Ethernet semaphore\n"); |
220 |
< |
return; |
220 |
> |
return false; |
221 |
|
} |
222 |
|
net_buffer_ptr->read_sem = read_sem; |
223 |
|
write_sem = net_buffer_ptr->write_sem; |
233 |
|
D(bug("Ethernet address %02x %02x %02x %02x %02x %02x\n", ether_addr[0], ether_addr[1], ether_addr[2], ether_addr[3], ether_addr[4], ether_addr[5])); |
234 |
|
|
235 |
|
// Everything OK |
236 |
< |
net_open = true; |
236 |
> |
return true; |
237 |
|
} |
238 |
|
|
239 |
|
|
241 |
|
* Deinitialization |
242 |
|
*/ |
243 |
|
|
244 |
< |
void EtherExit(void) |
244 |
> |
void ether_exit(void) |
245 |
|
{ |
246 |
< |
if (net_open) { |
247 |
< |
|
248 |
< |
// Close communications with add-on |
249 |
< |
for (int i=0; i<WRITE_PACKET_COUNT; i++) |
250 |
< |
net_buffer_ptr->write[i].cmd = IN_USE | (DEACTIVATE_SHEEP_NET << 8); |
251 |
< |
release_sem(write_sem); |
246 |
> |
// Close communications with add-on |
247 |
> |
for (int i=0; i<WRITE_PACKET_COUNT; i++) |
248 |
> |
net_buffer_ptr->write[i].cmd = IN_USE | (DEACTIVATE_SHEEP_NET << 8); |
249 |
> |
release_sem(write_sem); |
250 |
|
|
251 |
< |
// Quit reception thread |
252 |
< |
ether_thread_active = false; |
253 |
< |
status_t result; |
254 |
< |
release_sem(read_sem); |
255 |
< |
wait_for_thread(read_thread, &result); |
251 |
> |
// Quit reception thread |
252 |
> |
ether_thread_active = false; |
253 |
> |
status_t result; |
254 |
> |
release_sem(read_sem); |
255 |
> |
wait_for_thread(read_thread, &result); |
256 |
|
|
257 |
< |
delete_sem(read_sem); |
258 |
< |
delete_area(buffer_area); |
257 |
> |
delete_sem(read_sem); |
258 |
> |
delete_area(buffer_area); |
259 |
|
|
260 |
< |
// Remove all protocols |
261 |
< |
remove_all_protocols(); |
264 |
< |
} |
260 |
> |
// Remove all protocols |
261 |
> |
remove_all_protocols(); |
262 |
|
} |
263 |
|
|
264 |
|
|
266 |
|
* Reset |
267 |
|
*/ |
268 |
|
|
269 |
< |
void EtherReset(void) |
269 |
> |
void ether_reset(void) |
270 |
|
{ |
271 |
|
remove_all_protocols(); |
272 |
|
} |
361 |
|
} else { |
362 |
|
|
363 |
|
// Copy packet to buffer |
364 |
< |
uint8 *start; |
368 |
< |
uint8 *bp = start = p->data; |
369 |
< |
for (;;) { |
370 |
< |
int len = ReadMacInt16(wds); |
371 |
< |
if (len == 0) |
372 |
< |
break; |
373 |
< |
Mac2Host_memcpy(bp, ReadMacInt32(wds + 2), len); |
374 |
< |
bp += len; |
375 |
< |
wds += 6; |
376 |
< |
} |
364 |
> |
int len = ether_wds_to_buffer(wds, p->data); |
365 |
|
|
366 |
|
// Set source address |
367 |
< |
memcpy(start + 6, ether_addr, 6); |
367 |
> |
memcpy(p->data + 6, ether_addr, 6); |
368 |
|
|
369 |
|
#if MONITOR |
370 |
|
bug("Sending Ethernet packet:\n"); |
371 |
< |
for (int i=0; i<(uint32)(bp-start); i++) { |
372 |
< |
bug("%02x ", start[i]); |
371 |
> |
for (int i=0; i<len; i++) { |
372 |
> |
bug("%02x ", p->data[i]); |
373 |
|
} |
374 |
|
bug("\n"); |
375 |
|
#endif |
376 |
|
|
377 |
|
// Notify add-on |
378 |
< |
p->length = (uint32)(bp - start); |
378 |
> |
p->length = len; |
379 |
|
p->cmd = IN_USE | (SHEEP_PACKET << 8); |
380 |
|
wr_pos = (wr_pos + 1) % WRITE_PACKET_COUNT; |
381 |
|
release_sem(write_sem); |