1 |
|
/* |
2 |
|
* ether_amiga.cpp - Ethernet device driver, AmigaOS specific stuff |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2001 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
116 |
|
* Initialization |
117 |
|
*/ |
118 |
|
|
119 |
< |
void EtherInit(void) |
119 |
> |
bool ether_init(void) |
120 |
|
{ |
121 |
|
// Do nothing if no Ethernet device specified |
122 |
|
if (PrefsFindString("ether") == NULL) |
123 |
< |
return; |
123 |
> |
return false; |
124 |
|
|
125 |
|
// Initialize protocol list |
126 |
|
NewList(&prot_list); |
135 |
|
proc_error = false; |
136 |
|
SetSignal(0, SIGF_SINGLE); |
137 |
|
net_proc = CreateNewProcTags( |
138 |
< |
NP_Entry, net_func, |
139 |
< |
NP_Name, "Basilisk II Ethernet Task", |
138 |
> |
NP_Entry, (ULONG)net_func, |
139 |
> |
NP_Name, (ULONG)"Basilisk II Ethernet Task", |
140 |
|
NP_Priority, 1, |
141 |
|
TAG_END |
142 |
|
); |
151 |
|
goto open_error; |
152 |
|
|
153 |
|
// Everything OK |
154 |
< |
net_open = true; |
155 |
< |
return; |
154 |
> |
return true; |
155 |
|
|
156 |
|
open_error: |
157 |
|
net_proc = NULL; |
159 |
|
DeleteMsgPort(reply_port); |
160 |
|
reply_port = NULL; |
161 |
|
} |
162 |
+ |
return false; |
163 |
|
} |
164 |
|
|
165 |
|
|
167 |
|
* Deinitialization |
168 |
|
*/ |
169 |
|
|
170 |
< |
void EtherExit(void) |
170 |
> |
void ether_exit(void) |
171 |
|
{ |
172 |
|
// Stop process |
173 |
|
if (net_proc) { |
188 |
|
* Reset |
189 |
|
*/ |
190 |
|
|
191 |
< |
void EtherReset(void) |
191 |
> |
void ether_reset(void) |
192 |
|
{ |
193 |
|
// Remove all protocols |
194 |
< |
if (net_open) |
194 |
> |
if (net_proc) |
195 |
|
send_to_proc(MSG_CLEANUP); |
196 |
|
} |
197 |
|
|
287 |
|
* Copy received network packet to Mac side |
288 |
|
*/ |
289 |
|
|
290 |
< |
static __saveds __asm LONG copy_to_buff(register __a0 uint8 *to, register __a1 uint8 *from, register __d0 uint32 packet_len) |
290 |
> |
static __saveds __regargs LONG copy_to_buff(uint8 *to /*a0*/, uint8 *from /*a1*/, uint32 packet_len /*d0*/) |
291 |
|
{ |
292 |
|
D(bug("CopyToBuff to %08lx, from %08lx, size %08lx\n", to, from, packet_len)); |
293 |
|
|
313 |
|
* Copy data from Mac WDS to outgoing network packet |
314 |
|
*/ |
315 |
|
|
316 |
< |
static __saveds __asm LONG copy_from_buff(register __a0 uint8 *to, register __a1 uint32 wds, register __d0 uint32 packet_len) |
316 |
> |
static __saveds __regargs LONG copy_from_buff(uint8 *to /*a0*/, char *wds /*a1*/, uint32 packet_len /*d0*/) |
317 |
|
{ |
318 |
|
D(bug("CopyFromBuff to %08lx, wds %08lx, size %08lx\n", to, wds, packet_len)); |
319 |
|
#if MONITOR |
320 |
|
bug("Sending Ethernet packet:\n"); |
321 |
|
#endif |
322 |
|
for (;;) { |
323 |
< |
int len = ReadMacInt16(wds); |
323 |
> |
int len = ReadMacInt16((uint32)wds); |
324 |
|
if (len == 0) |
325 |
|
break; |
326 |
|
#if MONITOR |
327 |
< |
uint8 *adr = Mac2HostAddr(ReadMacInt32(wds + 2)); |
327 |
> |
uint8 *adr = Mac2HostAddr(ReadMacInt32((uint32)wds + 2)); |
328 |
|
for (int i=0; i<len; i++) { |
329 |
|
bug("%02lx ", adr[i]); |
330 |
|
} |
331 |
|
#endif |
332 |
< |
CopyMem(Mac2HostAddr(ReadMacInt32(wds + 2)), to, len); |
332 |
> |
CopyMem(Mac2HostAddr(ReadMacInt32((uint32)wds + 2)), to, len); |
333 |
|
to += len; |
334 |
|
wds += 6; |
335 |
|
} |
346 |
|
|
347 |
|
static __saveds void net_func(void) |
348 |
|
{ |
349 |
+ |
const char *str; |
350 |
+ |
BYTE od_error; |
351 |
|
struct MsgPort *write_port = NULL, *control_port = NULL; |
352 |
|
struct IOSana2Req *write_io = NULL, *control_io = NULL; |
353 |
|
bool opened = false; |
390 |
|
// Parse device name |
391 |
|
char dev_name[256]; |
392 |
|
ULONG dev_unit; |
393 |
< |
if (sscanf(PrefsFindString("ether"), "%[^/]/%ld", dev_name, &dev_unit) < 2) |
393 |
> |
|
394 |
> |
str = PrefsFindString("ether"); |
395 |
> |
if (str) |
396 |
> |
{ |
397 |
> |
const char *FirstSlash = strchr(str, '/'); |
398 |
> |
const char *LastSlash = strrchr(str, '/'); |
399 |
> |
|
400 |
> |
if (FirstSlash && FirstSlash && FirstSlash != LastSlash) |
401 |
> |
{ |
402 |
> |
// Device name contains path, i.e. "Networks/xyzzy.device" |
403 |
> |
const char *lp = str; |
404 |
> |
char *dp = dev_name; |
405 |
> |
|
406 |
> |
while (lp != LastSlash) |
407 |
> |
*dp++ = *lp++; |
408 |
> |
*dp = '\0'; |
409 |
> |
|
410 |
> |
if (strlen(dev_name) < 1) |
411 |
> |
goto quit; |
412 |
> |
|
413 |
> |
if (1 != sscanf(LastSlash, "/%ld", &dev_unit)) |
414 |
> |
goto quit; |
415 |
> |
|
416 |
> |
// printf("dev=<%s> unit=%d\n", dev_name, dev_unit); |
417 |
> |
} |
418 |
> |
else |
419 |
> |
{ |
420 |
> |
if (2 != sscanf(str, "%[^/]/%ld", dev_name, &dev_unit)) |
421 |
> |
goto quit; |
422 |
> |
} |
423 |
> |
} |
424 |
> |
else |
425 |
|
goto quit; |
426 |
|
|
427 |
|
// Open device |
428 |
|
control_io->ios2_BufferManagement = buffer_tags; |
429 |
< |
if (OpenDevice((UBYTE *)dev_name, dev_unit, (struct IORequest *)control_io, 0) || control_io->ios2_Req.io_Device == 0) |
429 |
> |
od_error = OpenDevice((UBYTE *)dev_name, dev_unit, (struct IORequest *)control_io, 0); |
430 |
> |
if (0 != od_error || control_io->ios2_Req.io_Device == 0) |
431 |
> |
{ |
432 |
> |
printf("WARNING: OpenDevice(<%s>, unit=%d) returned error %d)\n", (UBYTE *)dev_name, dev_unit, od_error); |
433 |
|
goto quit; |
434 |
+ |
} |
435 |
|
opened = true; |
436 |
|
|
437 |
|
// Is it Ethernet? |
488 |
|
|
489 |
|
case MSG_ADD_MULTI: |
490 |
|
control_io->ios2_Req.io_Command = S2_ADDMULTICASTADDRESS; |
491 |
< |
memcpy(control_io->ios2_SrcAddr, Mac2HostAddr(msg->pointer + eMultiAddr), 6); |
491 |
> |
Mac2Host_memcpy(control_io->ios2_SrcAddr, msg->pointer + eMultiAddr, 6); |
492 |
|
DoIO((struct IORequest *)control_io); |
493 |
|
if (control_io->ios2_Req.io_Error == S2ERR_NOT_SUPPORTED) { |
494 |
|
WarningAlert(GetString(STR_NO_MULTICAST_WARN)); |
501 |
|
|
502 |
|
case MSG_DEL_MULTI: |
503 |
|
control_io->ios2_Req.io_Command = S2_DELMULTICASTADDRESS; |
504 |
< |
memcpy(control_io->ios2_SrcAddr, Mac2HostAddr(msg->pointer + eMultiAddr), 6); |
504 |
> |
Mac2Host_memcpy(control_io->ios2_SrcAddr, msg->pointer + eMultiAddr, 6); |
505 |
|
DoIO((struct IORequest *)control_io); |
506 |
|
if (control_io->ios2_Req.io_Error) |
507 |
|
msg->result = eMultiErr; |
587 |
|
|
588 |
|
// Get destination address, set source address |
589 |
|
uint32 hdr = ReadMacInt32(wds + 2); |
590 |
< |
memcpy(write_io->ios2_DstAddr, Mac2HostAddr(hdr), 6); |
591 |
< |
memcpy(Mac2HostAddr(hdr + 6), ether_addr, 6); |
590 |
> |
Mac2Host_memcpy(write_io->ios2_DstAddr, hdr, 6); |
591 |
> |
Host2Mac_memcpy(hdr + 6, ether_addr, 6); |
592 |
|
|
593 |
|
// Get packet type |
594 |
|
uint32 type = ReadMacInt16(hdr + 12); |
672 |
|
|
673 |
|
// Packet write done, enqueue DT to call IODone |
674 |
|
if (write_done) { |
675 |
< |
Enqueue(ether_data + ed_DeferredTask, 0xd92); |
675 |
> |
EnqueueMac(ether_data + ed_DeferredTask, 0xd92); |
676 |
|
write_done = false; |
677 |
|
} |
678 |
|
|
688 |
|
continue; |
689 |
|
|
690 |
|
// Copy header to RHA |
691 |
< |
memcpy(Mac2HostAddr(ether_data + ed_RHA), io->ios2_Data, 14); |
691 |
> |
Host2Mac_memcpy(ether_data + ed_RHA, io->ios2_Data, 14); |
692 |
|
D(bug(" header %08lx%04lx %08lx%04lx %04lx\n", ReadMacInt32(ether_data + ed_RHA), ReadMacInt16(ether_data + ed_RHA + 4), ReadMacInt32(ether_data + ed_RHA + 6), ReadMacInt16(ether_data + ed_RHA + 10), ReadMacInt16(ether_data + ed_RHA + 12))); |
693 |
|
|
694 |
|
// Call protocol handler |