--- BasiliskII/src/AmigaOS/ether_amiga.cpp 1999/10/19 19:28:14 1.2 +++ BasiliskII/src/AmigaOS/ether_amiga.cpp 2002/01/15 14:58:34 1.11 @@ -1,7 +1,7 @@ /* * ether_amiga.cpp - Ethernet device driver, AmigaOS specific stuff * - * Basilisk II (C) 1997-1999 Christian Bauer + * Basilisk II (C) 1997-2002 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -116,11 +116,11 @@ static int16 send_to_proc(uint32 what, u * Initialization */ -void EtherInit(void) +bool ether_init(void) { // Do nothing if no Ethernet device specified if (PrefsFindString("ether") == NULL) - return; + return false; // Initialize protocol list NewList(&prot_list); @@ -151,8 +151,7 @@ void EtherInit(void) goto open_error; // Everything OK - net_open = true; - return; + return true; open_error: net_proc = NULL; @@ -160,6 +159,7 @@ open_error: DeleteMsgPort(reply_port); reply_port = NULL; } + return false; } @@ -167,7 +167,7 @@ open_error: * Deinitialization */ -void EtherExit(void) +void ether_exit(void) { // Stop process if (net_proc) { @@ -188,10 +188,10 @@ void EtherExit(void) * Reset */ -void EtherReset(void) +void ether_reset(void) { // Remove all protocols - if (net_open) + if (net_proc) send_to_proc(MSG_CLEANUP); } @@ -346,6 +346,8 @@ static __saveds __regargs LONG copy_from static __saveds void net_func(void) { + const char *str; + BYTE od_error; struct MsgPort *write_port = NULL, *control_port = NULL; struct IOSana2Req *write_io = NULL, *control_io = NULL; bool opened = false; @@ -388,13 +390,41 @@ static __saveds void net_func(void) // Parse device name char dev_name[256]; ULONG dev_unit; - if (sscanf(PrefsFindString("ether"), "%[^/]/%ld", dev_name, &dev_unit) < 2) + + str = PrefsFindString("ether"); + if (str) { + const char *FirstSlash = strchr(str, '/'); + const char *LastSlash = strrchr(str, '/'); + + if (FirstSlash && FirstSlash && FirstSlash != LastSlash) { + + // Device name contains path, i.e. "Networks/xyzzy.device" + const char *lp = str; + char *dp = dev_name; + + while (lp != LastSlash) + *dp++ = *lp++; + *dp = '\0'; + + if (strlen(dev_name) < 1) + goto quit; + + if (sscanf(LastSlash, "/%ld", &dev_unit) != 1) + goto quit; + } else { + if (sscanf(str, "%[^/]/%ld", dev_name, &dev_unit) != 2) + goto quit; + } + } else goto quit; // Open device control_io->ios2_BufferManagement = buffer_tags; - if (OpenDevice((UBYTE *)dev_name, dev_unit, (struct IORequest *)control_io, 0) || control_io->ios2_Req.io_Device == 0) + od_error = OpenDevice((UBYTE *)dev_name, dev_unit, (struct IORequest *)control_io, 0); + if (od_error != 0 || control_io->ios2_Req.io_Device == 0) { + printf("WARNING: OpenDevice(<%s>, unit=%d) returned error %d)\n", (UBYTE *)dev_name, dev_unit, od_error); goto quit; + } opened = true; // Is it Ethernet? @@ -451,7 +481,7 @@ static __saveds void net_func(void) case MSG_ADD_MULTI: control_io->ios2_Req.io_Command = S2_ADDMULTICASTADDRESS; - memcpy(control_io->ios2_SrcAddr, Mac2HostAddr(msg->pointer + eMultiAddr), 6); + Mac2Host_memcpy(control_io->ios2_SrcAddr, msg->pointer + eMultiAddr, 6); DoIO((struct IORequest *)control_io); if (control_io->ios2_Req.io_Error == S2ERR_NOT_SUPPORTED) { WarningAlert(GetString(STR_NO_MULTICAST_WARN)); @@ -464,7 +494,7 @@ static __saveds void net_func(void) case MSG_DEL_MULTI: control_io->ios2_Req.io_Command = S2_DELMULTICASTADDRESS; - memcpy(control_io->ios2_SrcAddr, Mac2HostAddr(msg->pointer + eMultiAddr), 6); + Mac2Host_memcpy(control_io->ios2_SrcAddr, msg->pointer + eMultiAddr, 6); DoIO((struct IORequest *)control_io); if (control_io->ios2_Req.io_Error) msg->result = eMultiErr; @@ -548,10 +578,9 @@ static __saveds void net_func(void) } write_io->ios2_DataLength = len; - // Get destination address, set source address + // Get destination address uint32 hdr = ReadMacInt32(wds + 2); - memcpy(write_io->ios2_DstAddr, Mac2HostAddr(hdr), 6); - memcpy(Mac2HostAddr(hdr + 6), ether_addr, 6); + Mac2Host_memcpy(write_io->ios2_DstAddr, hdr, 6); // Get packet type uint32 type = ReadMacInt16(hdr + 12); @@ -651,7 +680,7 @@ void EtherInterrupt(void) continue; // Copy header to RHA - memcpy(Mac2HostAddr(ether_data + ed_RHA), io->ios2_Data, 14); + Host2Mac_memcpy(ether_data + ed_RHA, io->ios2_Data, 14); 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))); // Call protocol handler