├── .gitignore ├── debug.lib ├── scsidayna.prefs ├── compile.bat ├── version.h ├── debug.h ├── deviceheader.c ├── Makefile ├── compiler.h ├── deviceinit.c ├── macros.h ├── debug.i ├── newstyle.h ├── README.md ├── device.h ├── scsiwifi.h ├── Common.mk ├── sana2.h ├── scsiwifi.c ├── licence.txt └── device.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.lha 3 | *.device 4 | 5 | -------------------------------------------------------------------------------- /debug.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobSmithDev/daynaport-amiga/HEAD/debug.lib -------------------------------------------------------------------------------- /scsidayna.prefs: -------------------------------------------------------------------------------- 1 | DEVICE=scsi.device 2 | DEVICEID=-1 3 | PRIORITY=0 4 | MODE=2 5 | AUTOCONNECT=0 6 | SSID= 7 | KEY= 8 | 9 | -------------------------------------------------------------------------------- /compile.bat: -------------------------------------------------------------------------------- 1 | 2 | rem assemble kprintf.asm: vasmm68k_mot -m68000 -Fhunk -nowarn=2064 -quiet kprintf.asm -I "D:\DaynaChain\amiga-sdk-master\sdkinclude" -o kprintf.o 3 | rem set SDK="D:\amigaxcompile\vbcc\targets\m68k-amigaos\include" 4 | del *.o /q 5 | del *.device /q 6 | cls 7 | make 8 | -------------------------------------------------------------------------------- /version.h: -------------------------------------------------------------------------------- 1 | /* 2 | version.h 3 | 4 | (C) 2018 Henryk Richter 5 | 6 | version and date handling 7 | */ 8 | #ifndef _INC_VERSION_H 9 | #define _INC_VERSION_H 10 | 11 | #define DEVICEVERSION 1 12 | #define DEVICEREVISION 3 13 | #define DEVICEEXTRA 14 | /* #define DEVICEEXTRA Beta */ 15 | #define DEVICEDATE 2025-09-25 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | debug.h 3 | 4 | (C) 2018 Henryk Richter 5 | 6 | Debugging Macros 7 | 8 | 9 | */ 10 | #ifndef _INC_DEBUG_H 11 | #define _INC_DEBUG_H 12 | 13 | #ifdef DEBUG 14 | extern void KPrintF(char *, ...), KGetChar(void); 15 | 16 | #define D(_x_) do { KPrintF("%s:%ld:",__FILE__,__LINE__); KPrintF _x_; KPrintF("\r\n"); } while(0) 17 | 18 | #else /* DEBUG */ 19 | 20 | #define D(x) 21 | 22 | #endif /* DEBUG */ 23 | 24 | 25 | #endif /* _INC_DEBUG_H */ 26 | -------------------------------------------------------------------------------- /deviceheader.c: -------------------------------------------------------------------------------- 1 | /* 2 | Device Header - ROMTAG 3 | 4 | (C) 2018 Henryk Richter 5 | 6 | taken from commandline (compiler options) 7 | -DDEVICENAME=blah.device 8 | -DDEVICEVERSION=45 9 | -DDEVICEREVISION=36 10 | -DDEVICEDATE=2.12.2012 11 | 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #ifdef HAVE_VERSION_H 19 | #include "version.h" 20 | #endif 21 | #include "compiler.h" 22 | #include "device.h" 23 | 24 | /* Enable this if you want pure C for the device. (disable compilation of romtag.asm in that case) 25 | I personally prefer the small ASM blob to steer away from linking challenges. 26 | */ 27 | #if 1 28 | 29 | ASM LONG LibNull( void ) 30 | { 31 | return 0; 32 | } 33 | 34 | extern const char DeviceName[]; 35 | extern const char DeviceVersionString[]; 36 | extern const APTR DeviceInitTab[]; 37 | 38 | static const struct Resident _00RomTag = { 39 | RTC_MATCHWORD, 40 | ( struct Resident* ) &_00RomTag, 41 | ( struct Resident* ) &_00RomTag + 1, 42 | RTF_AUTOINIT, 43 | DEVICEVERSION, 44 | NT_DEVICE, 45 | 0, 46 | (char*)DeviceName, 47 | (char*)DeviceVersionString+6, 48 | (APTR)DeviceInitTab 49 | }; 50 | #endif 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # 3 | # makefile for vbcc or gcc 4 | # 5 | # original author: Henryk Richter 6 | # 7 | # concept: 8 | # 9 | # tools required: 10 | # - vbcc, defaulting to m68k-amigaos 11 | # - vlink 12 | # (- vasm) 13 | # 14 | # porting: 15 | # 16 | # see Common.mk 17 | # 18 | ############################################################################### 19 | 20 | ############################################################################### 21 | # Date, version, extra objects to build 22 | # 23 | ############################################################################### 24 | DEVICEVERSION=1 25 | DEVICEREVISION=3 26 | DEVICEDATE=2025-09-25 27 | 28 | ############################################################################### 29 | # Devices to build (1 or 2, keep DEVICEID2 empty if only one build is desired) 30 | # 31 | ############################################################################### 32 | 33 | DEVICEID=scsidayna.device 34 | DEFINES = # 35 | ASMDEFS = # 36 | CPU = 68000 37 | 38 | DEVICEID2= 39 | 40 | ############################################################################### 41 | # import generic ruleset 42 | # 43 | ############################################################################### 44 | include Common.mk 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | compiler.h 3 | 4 | (C) 2018 Henryk Richter 5 | 6 | Interface macros for ASM subroutines for VBCC, GCC and SAS/C 7 | 8 | syntax: 9 | ASM SAVEDS int some_asm_subroutine( 10 | ASMR(d3) unsigned int some_data ASMREG(d3), 11 | ASMR(a0) unsigned char *some_address ASMREG(a0) 12 | ); 13 | 14 | Reason for the double spec of An/Dn: some compilers (SAS) require the register 15 | on the left hand side, gcc on the right hand side. I wanted to avoid a big macro 16 | for the whole argument and moved the stuff into two macros per argument. 17 | 18 | */ 19 | #ifndef _INC_ASMINTERFACE_H 20 | #define _INC_ASMINTERFACE_H 21 | 22 | #ifdef __SASC 23 | 24 | #define ASM __asm 25 | #define ASMR(x) register __ ## x 26 | #define ASMREG(x) 27 | #define SAVEDS __saveds 28 | #define STRUCTOFFSET OFFSET /* exec/initializers.h */ 29 | #define INLINE __inline static 30 | 31 | #else /* __SASC */ 32 | 33 | #ifdef __GNUC__ 34 | 35 | #define ASM 36 | #define ASMR(x) register 37 | #define ASMREG(x) __asm("" #x "") 38 | //#define SAVEDS __saveds 39 | #define SAVEDS 40 | #define STRUCTOFFSET OFFSET /* exec/initializers.h */ 41 | #define INLINE static inline 42 | 43 | #else /* __GNUC__ */ 44 | 45 | #ifdef __VBCC__ 46 | 47 | #define ASM 48 | #define ASMR(x) __reg("" #x "") 49 | #define ASMREG(x) 50 | #define SAVEDS __saveds 51 | #define STRUCTOFFSET(_a_,_b_) offsetof(struct _a_, _b_) /* stddef.h */ 52 | #include 53 | /* sorry, I ran into some issues inlining stuff with VBCC, disabling it */ 54 | #define INLINE 55 | 56 | #else /* __VBCC__ */ 57 | 58 | #error "Compiler not supported yet in compiler.h" 59 | 60 | #endif /* __VBCC__ */ 61 | #endif /* __GNUC__ */ 62 | #endif /* __SASC */ 63 | 64 | 65 | #endif /* _INC_ASMINTERFACE_H */ 66 | -------------------------------------------------------------------------------- /deviceinit.c: -------------------------------------------------------------------------------- 1 | /* 2 | devinit.c 3 | 4 | (C) 2018 Henryk Richter 5 | 6 | initialization structures and data 7 | 8 | */ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #ifdef HAVE_VERSION_H 17 | #include "version.h" 18 | #endif 19 | #include "device.h" 20 | #include "macros.h" 21 | #include 22 | 23 | #define xstr(a) str(a) 24 | #define str(a) #a 25 | 26 | #ifndef DEVICEEXTRA 27 | #define DEVICEEXTRA 28 | #endif 29 | 30 | static const char _DeviceVersionString[] = "$VER: " xstr(DEVICENAME) " " xstr(DEVICEVERSION) "." xstr(DEVICEREVISION) xstr(DEVICEEXTRA) " (" xstr(DEVICEDATE) ")"; 31 | const char *DeviceVersionString = (const char *)_DeviceVersionString; 32 | const char DeviceName[] = xstr(DEVICENAME); 33 | 34 | 35 | const APTR DeviceFunctions[] = { 36 | (APTR) DevOpen, 37 | (APTR) DevClose, 38 | (APTR) DevExpunge, 39 | (APTR) LibNull, 40 | (APTR) DevBeginIO, 41 | (APTR) DevAbortIO, 42 | (APTR) -1 43 | }; 44 | 45 | 46 | #define WORDINIT(_a_) UWORD _a_ ##W1; UWORD _a_ ##W2; UWORD _a_ ##ARG; 47 | #define LONGINIT(_a_) UBYTE _a_ ##A1; UBYTE _a_ ##A2; ULONG _a_ ##ARG; 48 | struct DeviceInitData 49 | { 50 | WORDINIT(w1) 51 | LONGINIT(l1) 52 | WORDINIT(w2) 53 | WORDINIT(w3) 54 | WORDINIT(w4) 55 | LONGINIT(l2) 56 | ULONG end_initlist; 57 | } DeviceInitializers = 58 | { 59 | INITBYTE( STRUCTOFFSET( Node, ln_Type), NT_DEVICE), 60 | 0x80, (UBYTE) ((LONG)STRUCTOFFSET( Node, ln_Name)), (ULONG) &DeviceName[0], 61 | INITBYTE( STRUCTOFFSET(Library,lib_Flags), LIBF_SUMUSED|LIBF_CHANGED ), 62 | INITWORD( STRUCTOFFSET(Library,lib_Version), DEVICEVERSION ), 63 | INITWORD( STRUCTOFFSET(Library,lib_Revision), DEVICEREVISION ), 64 | 0x80, (UBYTE) ((LONG)STRUCTOFFSET(Library,lib_IdString)), (ULONG) &_DeviceVersionString[6], 65 | (ULONG) 0 66 | }; 67 | 68 | 69 | const APTR DeviceInitTab[] = { 70 | (APTR) sizeof( DEVBASETYPE ), 71 | (APTR) &DeviceFunctions, 72 | (APTR) &DeviceInitializers, 73 | (APTR) DevInit 74 | }; 75 | 76 | 77 | -------------------------------------------------------------------------------- /macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | macros.h 3 | 4 | (C) 2018 Henryk Richter 5 | 6 | useful macros 7 | 8 | */ 9 | #ifndef _INC_MACROS_H 10 | #define _INC_MACROS_H 11 | 12 | #define GetHead(l) (void *)(((struct List *)l)->lh_Head->ln_Succ \ 13 | ? ((struct List *)l)->lh_Head \ 14 | : (struct Node *)0) 15 | #define GetTail(l) (void *)(((struct List *)l)->lh_TailPred->ln_Pred \ 16 | ? ((struct List *)l)->lh_TailPred \ 17 | : (struct Node *)0) 18 | #define GetSucc(n) (void *)(((struct Node *)n)->ln_Succ->ln_Succ \ 19 | ? ((struct Node *)n)->ln_Succ \ 20 | : (struct Node *)0) 21 | #define GetPred(n) (void *)(((struct Node *)n)->ln_Pred->ln_Pred \ 22 | ? ((struct Node *)n)->ln_Pred \ 23 | : (struct Node *)0) 24 | 25 | #define REMOVE(n) ((void)(\ 26 | ((struct Node *)n)->ln_Pred->ln_Succ = ((struct Node *)n)->ln_Succ,\ 27 | ((struct Node *)n)->ln_Succ->ln_Pred = ((struct Node *)n)->ln_Pred )) 28 | 29 | #define ADDHEAD(l,n) ((void)(\ 30 | ((struct Node *)n)->ln_Succ = ((struct List *)l)->lh_Head, \ 31 | ((struct Node *)n)->ln_Pred = (struct Node *)&((struct List *)l)->lh_Head, \ 32 | ((struct List *)l)->lh_Head->ln_Pred = ((struct Node *)n), \ 33 | ((struct List *)l)->lh_Head = ((struct Node *)n))) 34 | 35 | #define ADDTAIL(l,n) ((void)(\ 36 | ((struct Node *)n)->ln_Succ = (struct Node *)&((struct List *)l)->lh_Tail, \ 37 | ((struct Node *)n)->ln_Pred = ((struct List *)l)->lh_TailPred, \ 38 | ((struct List *)l)->lh_TailPred->ln_Succ = ((struct Node *)n), \ 39 | ((struct List *)l)->lh_TailPred = ((struct Node *)n) )) 40 | 41 | #define NEWLIST(l) (((struct List *)l)->lh_TailPred = (struct Node *)(l), \ 42 | ((struct List *)l)->lh_Tail = 0, \ 43 | ((struct List *)l)->lh_Head = (struct Node *)&(((struct List *)l)->lh_Tail)) 44 | 45 | 46 | #define min(_a_,_b_) ( (_a_) > (_b_) ) ? _b_ : _a_ 47 | #define max(_a_,_b_) ( (_a_) < (_b_) ) ? _b_ : _a_ 48 | #define BOUNDS(_val_,_min_,_max_) ( (_val_) < (_min_) ) ? _min_ : ( (_val_) > (_max_) ) ? _max_ : _val_ 49 | 50 | 51 | #endif /* _INC_MACROS_H */ 52 | 53 | -------------------------------------------------------------------------------- /debug.i: -------------------------------------------------------------------------------- 1 | ; ifd DEBUG 2 | ; XDEF _AbsExecBase 3 | ; XDEF _LVORawDoFmt 4 | ; XDEF _LVORawPutChar 5 | ; XDEF _LVORawMayGetChar 6 | ; XDEF _AbsExecBase 7 | ; endif 8 | 9 | ifnd _LVORawDoFmt 10 | _LVORawDoFmt equ -$20a 11 | endc 12 | ifnd _LVORawPutChar 13 | _LVORawPutChar equ -$204 14 | _LVORawIOInit equ -$1f8 15 | _LVORawMayGetChar equ -$1fe 16 | endc 17 | 18 | ; 19 | ; 20 | ; 21 | ifne DEBUG 22 | 23 | XREF _KPrintF 24 | 25 | WRITEDEBUG macro 26 | movem.l d0/d1/a0/a1,-(sp) 27 | ifnb \9 28 | move.l \9,-(sp) 29 | endif 30 | ifnb \8 31 | move.l \8,-(sp) 32 | endif 33 | ifnb \7 34 | move.l \7,-(sp) 35 | endif 36 | ifnb \6 37 | move.l \6,-(sp) 38 | endif 39 | ifnb \5 40 | move.l \5,-(sp) 41 | endif 42 | ifnb \4 43 | move.l \4,-(sp) 44 | endif 45 | ifnb \3 46 | move.l \3,-(sp) 47 | endif 48 | ifnb \2 49 | move.l \2,-(sp) 50 | endif 51 | lea.l (\1),a0 52 | move.l sp,a1 53 | jsr _KPrintF 54 | ifnb \2 55 | add.l #4,sp 56 | endif 57 | ifnb \3 58 | add.l #4,sp 59 | endif 60 | ifnb \4 61 | add.l #4,sp 62 | endif 63 | ifnb \5 64 | add.l #4,sp 65 | endif 66 | ifnb \6 67 | add.l #4,sp 68 | endif 69 | ifnb \7 70 | add.l #4,sp 71 | endif 72 | ifnb \8 73 | add.l #4,sp 74 | endif 75 | ifnb \9 76 | add.l #4,sp 77 | endif 78 | movem.l (sp)+,d0/d1/a0/a1 79 | endm 80 | else 81 | WRITEDEBUG macro 82 | ; 83 | endm 84 | endc 85 | 86 | 87 | ; 88 | ; 89 | ; 90 | WRITEOUT macro 91 | movem.l d0/d1/d2/a0/a1/a6,-(sp) 92 | ifnb \9 93 | move.l \9,-(sp) 94 | endif 95 | ifnb \8 96 | move.l \8,-(sp) 97 | endif 98 | ifnb \7 99 | move.l \7,-(sp) 100 | endif 101 | ifnb \6 102 | move.l \6,-(sp) 103 | endif 104 | ifnb \5 105 | move.l \5,-(sp) 106 | endif 107 | ifnb \4 108 | move.l \4,-(sp) 109 | endif 110 | ifnb \3 111 | move.l \3,-(sp) 112 | endif 113 | ifnb \2 114 | move.l \2,-(sp) 115 | endif 116 | ifd DEBUG 117 | move.l \1,a0 118 | move.l sp,a1 119 | jsr _KPrintF 120 | endif 121 | move.l \1,d1 122 | move.l sp,d2 123 | movea.l DOSBase,a6 124 | jsr _LVOVPrintf(a6) 125 | ifnb \2 126 | add.l #4,sp 127 | endif 128 | ifnb \3 129 | add.l #4,sp 130 | endif 131 | ifnb \4 132 | add.l #4,sp 133 | endif 134 | ifnb \5 135 | add.l #4,sp 136 | endif 137 | ifnb \6 138 | add.l #4,sp 139 | endif 140 | ifnb \7 141 | add.l #4,sp 142 | endif 143 | ifnb \8 144 | add.l #4,sp 145 | endif 146 | ifnb \9 147 | add.l #4,sp 148 | endif 149 | movem.l (sp)+,d0/d1/d2/a0/a1/a6 150 | endm 151 | 152 | ;COUNTERS only when DEBUG is on 153 | ifd DEBUG 154 | ifne DEBUG 155 | DEBUG_COUNTERS EQU 1 156 | endc 157 | endc 158 | 159 | ifd DEBUG_COUNTERS 160 | COUNTER_INC macro 161 | addq.l #1,\1 162 | endm 163 | else 164 | COUNTER_INC macro 165 | nop 166 | endm 167 | endc 168 | 169 | ; write usage of all emulated instructions if DEBUG is 1 to RAWIO (sushi/sashimi/serial) 170 | ifd DEBUG 171 | ifne DEBUG 172 | HAVE_DEBUGINSTR EQU 1 173 | DEBUGINSTR macro 174 | ifnb \3 175 | WRITEDEBUG \1,\2,\3 176 | else 177 | WRITEDEBUG \1,\2 178 | endc 179 | endm 180 | endc 181 | endc 182 | ifnd HAVE_DEBUGINSTR 183 | DEBUGINSTR macro 184 | endm 185 | endc 186 | 187 | 188 | -------------------------------------------------------------------------------- /newstyle.h: -------------------------------------------------------------------------------- 1 | #ifndef DEVICES_NEWSTYLE_H 2 | #define DEVICES_NEWSTYLE_H 3 | /*------------------------------------------------------------------------*/ 4 | /* 5 | * $Id: newstyle.h 1.1 1997/05/15 18:53:15 heinz Exp $ 6 | * 7 | * Support header for the New Style Device standard 8 | * 9 | * (C)1996-1997 by Amiga International, Inc. 10 | * 11 | */ 12 | /*------------------------------------------------------------------------*/ 13 | 14 | /* 15 | * At the moment there is just a single new style general command: 16 | */ 17 | 18 | #define NSCMD_DEVICEQUERY 0x4000 19 | 20 | struct NSDeviceQueryResult { 21 | /* 22 | ** Standard information, must be reset for every query 23 | */ 24 | ULONG DevQueryFormat; /* this is type 0 */ 25 | ULONG SizeAvailable; /* bytes available */ 26 | 27 | /* 28 | ** Common information (READ ONLY!) 29 | */ 30 | UWORD DeviceType; /* what the device does */ 31 | UWORD DeviceSubType; /* depends on the main type */ 32 | UWORD *SupportedCommands; /* 0 terminated list of cmd's */ 33 | 34 | /* May be extended in the future! Check SizeAvailable! */ 35 | }; 36 | 37 | 38 | #define NSDEVTYPE_UNKNOWN 0 /* No suitable category, anything */ 39 | #define NSDEVTYPE_GAMEPORT 1 /* like gameport.device */ 40 | #define NSDEVTYPE_TIMER 2 /* like timer.device */ 41 | #define NSDEVTYPE_KEYBOARD 3 /* like keyboard.device */ 42 | #define NSDEVTYPE_INPUT 4 /* like input.device */ 43 | #define NSDEVTYPE_TRACKDISK 5 /* like trackdisk.device */ 44 | #define NSDEVTYPE_CONSOLE 6 /* like console.device */ 45 | #define NSDEVTYPE_SANA2 7 /* A >=SANA2R2 networking device */ 46 | #define NSDEVTYPE_AUDIO 8 /* like audio.device */ 47 | #define NSDEVTYPE_CLIPBOARD 9 /* like clipboard.device */ 48 | #define NSDEVTYPE_PRINTER 10 /* like printer.device */ 49 | #define NSDEVTYPE_SERIAL 11 /* like serial.device */ 50 | #define NSDEVTYPE_PARALLEL 12 /* like parallel.device */ 51 | 52 | 53 | /*------------------------------------------------------------------------*/ 54 | /* The following defines should really be part of device specific 55 | * includes. So we protect them from being redefined. 56 | */ 57 | #ifndef NSCMD_TD_READ64 58 | /* 59 | * An early new style trackdisk like device can also return this 60 | * new identifier for TD_GETDRIVETYPE. This should no longer 61 | * be the case though for newly written or updated NSD devices. 62 | * This identifier is ***OBSOLETE*** 63 | */ 64 | 65 | #define DRIVE_NEWSTYLE (0x4E535459L) /* 'NSTY' */ 66 | 67 | 68 | /* 69 | * At the moment, only four new style commands in the device 70 | * specific range and their ETD counterparts may be implemented. 71 | */ 72 | 73 | #define NSCMD_TD_READ64 0xC000 74 | #define NSCMD_TD_WRITE64 0xC001 75 | #define NSCMD_TD_SEEK64 0xC002 76 | #define NSCMD_TD_FORMAT64 0xC003 77 | 78 | #define NSCMD_ETD_READ64 0xE000 79 | #define NSCMD_ETD_WRITE64 0xE001 80 | #define NSCMD_ETD_SEEK64 0xE002 81 | #define NSCMD_ETD_FORMAT64 0xE003 82 | #endif /* NSCMD_TD_READ64 */ 83 | 84 | /*------------------------------------------------------------------------*/ 85 | 86 | #endif /* DEVICES_NEWSTYLE_H */ 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Amiga DaynaPORT Driver for BlueSCSI V2 and ZuluSCSI 2 | Created by RobSmithDev 3 | 4 | This is an implementation of a SANA-II driver for the Amiga, which allows you to use either a Pico W enabled BlueSCSI V2, or various WiFi equipped ZuluSCSI models to give internet access to the machine! 5 | 6 | This code is based on the MNT ZZ9000Net driver by Lukas F. Hartmann (which is based on work by Henryk Richter) and also borrows a little from the PlipBox device driver, which has several contributors. 7 | 8 | Setup Guides: 9 | - [YouTube video by Retronaut](https://www.youtube.com/watch?v=FDtqd04bq-k) 10 | - [BlueSCSI Docs](https://github.com/blueSCSI/blueSCSI-v2/wiki/WiFi-Amiga) 11 | - [Discord](https://discord.gg/pQsU3CR9fe) 12 | - [Workbench GUI Config Tool](https://github.com/AidanHolmes/BlueSCSIUI/releases/) 13 | 14 | ### SCSI Hardware Requirements: 15 | - [BlueSCSI Pico (V2) Wi-fi version](https://bluescsi.com/docs/WiFi-DaynaPORT) (v2024.10.26 or later firmware) 16 | - [ZuluSCSI Pico OSHW board with Pico W](https://zuluscsi.com/oshw/) (v2024.03.07 or later firmware) 17 | - [ZuluSCSI Pico Slim (DB25)](https://shop.rabbitholecomputing.com/products/zuluscsi-rp2040-pico-slim) 18 | - [ZuluSCSI Blaster (RP2350B)](https://zuluscsi.com) with RM2 WiFi module 19 | 20 | Tested configurations: 21 | 22 | ### Amiga 500/+ (2M Chip) 23 | - A590 HDD (2M Fast RAM, 7.0 ROM) with Kickstart 3.2 (scsi.device) 24 | - Ematrix 530 (ematscsi.device) 25 | 26 | ### Amiga 1200 27 | - Blizzard 1230IV / SCSI Kit (1230scsi.device) 28 | 29 | ### Amiga 2000 (2M Chip) 30 | - GVP Impact A2000-HC+8 Series II (8M Fast RAM), Kickstart 3.1 (gvpscsi.device) 31 | - A2091, Kickstart 3.1 (scsi.device) 32 | - phase5 Blizzard 2060 SCSI, Kickstart 3.1 (2060scsi.device) 33 | 34 | #### Side effects 35 | With BlueSCSI V2 hardware, the HDD light constantly flashes while the driver is in use. 36 | The driver needs to be copied to the `DEVS:Networks` folder and then setup your TCP/IP stack as normal. 37 | 38 | #### Notes 39 | If you find your data transfer is *very* slow, like less than 5K/s then check you've turned the debug log off within your BlueSCSI or ZuluSCSI configuration! 40 | 41 | ### Config File (IMPORTANT) 42 | `scsidayna.prefs` contains an example config file for the device. This needs to be copied to `ENVARC:` on the Amiga and rebooted. 43 | **If you change this file, they will not be picked up until restart or you copy it to ENV:** 44 | You can also manage this file with the [Workbench GUI config tool by Aidan Holmes](https://github.com/AidanHolmes/BlueSCSIUI/releases/). 45 | 46 | The format of that file is: 47 | ``` 48 | DEVICE=scsi.device 49 | DEVICEID=-1 50 | PRIORITY=0 51 | MODE=1 52 | AUTOCONNECT=0 53 | SSID= 54 | KEY= 55 | ``` 56 | 57 | where: 58 | - DEVICE is the name of the SCSI driver, eg: scsi.device or gvpscsi.device 59 | - DEVICEID is the SCSI device index the DaynaPORT is on, or -1 for Auto Detect 60 | - PRIORITY -128 to 127, sets the I/O task priority, see below 61 | - MODE see below 62 | - AUTOCONNECT 0/1 if 1, the driver will attempt to connect to the WIFI device (you can also configure BlueSCSI or ZuluSCSI to do this) 63 | - SSID The SSID/Wifi name to connect to if autoconnect=1 64 | - KEY the wifi key/password 65 | 66 | ## Mode 67 | This patches around weirdness in the various SCSI drivers. Mode should be: 68 | - 0: This runs in normal mode 69 | - 1: Runs in 24-byte pad mode (required for scsi.device - A590/A2091) 70 | - 2: Runs in 'single transfer' mode (required for gvpscsi.device) 71 | 72 | ## DEVICE 73 | This needs to match the SCSI interface you're using. You can check this using HDToolbox (see what device it uses in the tool type) or SCSIMounter etc. 74 | 75 | ## Task Priority 76 | A small note about task priority. If left at 0 the device will function perfectly fine, however the throughput of data is somewhat all over the place. 77 | If you want a really stable throughput, then set this to '1', but also expect this will possibly slow down some of the other applications running on your system. 78 | -------------------------------------------------------------------------------- /device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SCSI DaynaPORT Device (scsidayna.device) by RobSmithDev 3 | * 4 | * based LARGELY on the MNT ZZ9000 Network Driver 5 | * Copyright (C) 2016-2019, Lukas F. Hartmann 6 | * MNT Research GmbH, Berlin 7 | * https://mntre.com 8 | * Copyright (C) 2018 Henryk Richter 9 | * 10 | * SPDX-License-Identifier: GPL-3.0-or-later 11 | * GNU General Public License v3.0 or later 12 | * 13 | * https://spdx.org/licenses/GPL-3.0-or-later.html 14 | */ 15 | 16 | /* 17 | device.h 18 | 19 | (C) 2018 Henryk Richter 20 | 21 | Device Functions and Definitions 22 | 23 | 24 | */ 25 | #ifndef _INC_DEVICE_H 26 | #define _INC_DEVICE_H 27 | 28 | /* includes */ 29 | #include "compiler.h" 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include "debug.h" 36 | #include "sana2.h" 37 | 38 | /* reassign Library bases from global definitions to own struct */ 39 | #define SysBase db->db_SysBase 40 | #define DOSBase db->db_DOSBase 41 | #define UtilityBase db->db_UtilityBase 42 | 43 | struct DevUnit { 44 | /* HW Data (generic for now) (example only, unused in construct)*/ 45 | ULONG du_hwl0; 46 | ULONG du_hwl1; 47 | ULONG du_hwl2; 48 | APTR du_hwp0; 49 | APTR du_hwp1; 50 | APTR du_hwp2; 51 | }; 52 | 53 | struct devbase { 54 | struct Library db_Lib; 55 | BPTR db_SegList; /* from Device Init */ 56 | 57 | struct Library *db_SysBase; /* Exec Base */ 58 | struct Library *db_DOSBase; 59 | struct Library *db_UtilityBase; 60 | struct Sana2DeviceStats db_DevStats; 61 | 62 | volatile USHORT db_online; 63 | volatile USHORT db_currentWifiState; // the *actual* online state 64 | 65 | // SCSI device (in the main task) 66 | void* db_scsiSettings; // A pointer to a ScsiDaynaSettings struct 67 | USHORT db_scsiDeviceID; // The device ID that should be used going forward (auto-detect) 68 | USHORT db_scsiMode; // Scsi mode 69 | struct List db_ReadList; 70 | struct SignalSemaphore db_ReadListSem; 71 | struct List db_WriteList; 72 | struct SignalSemaphore db_WriteListSem; 73 | struct List db_EventList; 74 | struct SignalSemaphore db_EventListSem; 75 | struct List db_ReadOrphanList; 76 | struct SignalSemaphore db_ReadOrphanListSem; 77 | struct Process* db_Proc; 78 | struct SignalSemaphore db_ProcSem; 79 | }; 80 | 81 | #ifndef DEVBASETYPE 82 | #define DEVBASETYPE struct devbase 83 | #endif 84 | #ifndef DEVBASEP 85 | #define DEVBASEP DEVBASETYPE *db 86 | #endif 87 | 88 | /* PROTOS */ 89 | 90 | ASM LONG LibNull( void ); 91 | 92 | ASM SAVEDS struct Device *DevInit(ASMR(d0) DEVBASEP ASMREG(d0), 93 | ASMR(a0) BPTR seglist ASMREG(a0), 94 | ASMR(a6) struct Library *_SysBase ASMREG(a6) ); 95 | 96 | ASM SAVEDS LONG DevOpen( ASMR(a1) struct IOSana2Req *ios2 ASMREG(a1), 97 | ASMR(d0) ULONG unit ASMREG(d0), 98 | ASMR(d1) ULONG flags ASMREG(d1), 99 | ASMR(a6) DEVBASEP ASMREG(a6) ); 100 | 101 | ASM SAVEDS BPTR DevClose( ASMR(a1) struct IORequest *ios2 ASMREG(a1), 102 | ASMR(a6) DEVBASEP ASMREG(a6) ); 103 | 104 | ASM SAVEDS BPTR DevExpunge( ASMR(a6) DEVBASEP ASMREG(a6) ); 105 | 106 | ASM SAVEDS VOID DevBeginIO( ASMR(a1) struct IOSana2Req *ios2 ASMREG(a1), 107 | ASMR(a6) DEVBASEP ASMREG(a6) ); 108 | 109 | ASM SAVEDS LONG DevAbortIO( ASMR(a1) struct IORequest *ios2 ASMREG(a1), 110 | ASMR(a6) DEVBASEP ASMREG(a6) ); 111 | 112 | void DevTermIO( DEVBASETYPE*, struct IORequest * ); 113 | 114 | /* private functions */ 115 | #ifdef DEVICE_MAIN 116 | 117 | #endif /* DEVICE_MAIN */ 118 | 119 | #define HW_ADDRFIELDSIZE 6 120 | #define HW_ETH_HDR_SIZE 14 /* ethernet header: dst, src, type */ 121 | 122 | typedef BOOL (*BMFunc)(__reg("a0") void* a, __reg("a1") void* b, __reg("d0") long c); 123 | 124 | typedef struct BufferManagement 125 | { 126 | struct MinNode bm_Node; 127 | BMFunc bm_CopyFromBuffer; 128 | BMFunc bm_CopyToBuffer; 129 | } BufferManagement; 130 | 131 | #endif /* _INC_DEVICE_H */ 132 | -------------------------------------------------------------------------------- /scsiwifi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SCSI DaynaPORT Device (scsidayna.device) by RobSmithDev 3 | * DaynaPORT Interface Commands 4 | * 5 | */ 6 | #ifndef SCSI_WIFI_H 7 | #define SCSI_WIFI_H 1 8 | 9 | #include "compiler.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "debug.h" 16 | 17 | 18 | 19 | // Maximum number of WIFI networks the BlueScsi/SCSI2SD firmware will return 20 | #define SCSIWIFI_MAX_NETWORK_COUNT 10 21 | 22 | // This is defined in the BlueSCSI/SCSI2SD firmware. MTU would be ~1500 - the extra 20 bytes are ethernet overhead I guess!? 23 | #define SCSIWIFI_PACKET_MAX_SIZE 1520 24 | #define SCSIWIFI_PACKET_MTU_SIZE 1500 25 | 26 | // Result from calling SCSIWifi_open 27 | enum SCSIWifi_OpenResult {sworOK, sworOpenDeviceFailed, sworOutOfMem, sworInquireFail, sworNotDaynaDevice}; 28 | 29 | // Current status of a WIFI scan 30 | enum SCSIWifi_ScanStatus {swssBusy, swssComplete, swssNotRunning, swssError}; 31 | 32 | #ifdef __VBCC__ 33 | #pragma pack(1) 34 | #define STRUCT_PACKED 35 | #define STRUCT_ALIGN16 36 | #else 37 | #define STRUCT_PACKED __attribute__((packed)) 38 | #define STRUCT_ALIGN16 __attribute__((aligned (16))) 39 | #endif 40 | 41 | // Structure for MAC addresses from WIFI scsi 42 | struct STRUCT_PACKED SCSIWifi_MACAddress { 43 | UBYTE valid; 44 | UBYTE _padding; 45 | UBYTE address[6]; 46 | }; 47 | 48 | // Needs completing in order to join a WIFI network 49 | struct STRUCT_PACKED SCSIWifi_JoinRequest { 50 | char ssid[64]; 51 | char key[64]; 52 | UBYTE channel; // the channel number isn't used 53 | UBYTE _padding; 54 | }; 55 | 56 | // A single result received from a WIFI scan 57 | struct STRUCT_PACKED SCSIWifi_NetworkEntry { 58 | char ssid[64]; 59 | char bssid[6]; // Not implemented with getting current wifi status 60 | char rssi; // if this is 0 its not connected 61 | UBYTE channel; 62 | UBYTE flags; 63 | UBYTE _padding; 64 | }; 65 | 66 | // Disk settings 67 | struct ScsiDaynaSettings { 68 | // SCSI device driver 69 | char deviceName[108]; 70 | // Device ID 71 | SHORT deviceID; // if this is <0 or >7 then it auto-detects 72 | // Priority for the READING task 73 | SHORT taskPriority; 74 | // Driver mode 75 | USHORT scsiMode; 76 | // Auto-connect to this wifi network 77 | USHORT autoConnect; 78 | char ssid[64]; 79 | char key[64]; 80 | }; 81 | 82 | #ifdef __VBCC__ 83 | #pragma pack(2) 84 | #endif 85 | 86 | // The full result from a wifi scan - 742 bytes - word aligned 87 | struct STRUCT_ALIGN16 SCSIWifi_ScanResults { 88 | UWORD count; // Number of results 89 | struct SCSIWifi_NetworkEntry networks[SCSIWIFI_MAX_NETWORK_COUNT]; // 740 bytes 90 | }; 91 | 92 | #ifdef __VBCC__ 93 | #pragma pack() 94 | #endif 95 | 96 | 97 | // Device handle - yeah you don't need to know what's inside 98 | typedef void* SCSIWIFIDevice; 99 | 100 | // Internal SCSI device data 101 | struct SCSIDevice_OpenData { 102 | struct ExecBase *sysBase; // Library needs these 103 | struct UtilityBase *utilityBase; 104 | struct DosBase *dosBase; 105 | 106 | SHORT deviceID; // SCSI ID (0-7) 107 | USHORT scsiMode; // Special mode, from settings 108 | 109 | char* deviceDriverName; // SCSI Driver to use (eg: scsi.device or gvpscsi.device etc) 110 | }; 111 | 112 | // Populates settings with default values 113 | void SCSIWifi_defaultSettings(struct ScsiDaynaSettings* settings); 114 | 115 | // Loads settings from the ENV, returns 0 if the settings were bad and defaults were setup 116 | LONG SCSIWifi_loadSettings(void *utilityBase, void *dosBase, struct ScsiDaynaSettings* settings); 117 | 118 | // Saves settings back to ENV or ENVARC - returns 0 if it failed 119 | LONG SCSIWifi_saveSettings(struct DosBase *dosBase, struct ScsiDaynaSettings* settings, LONG saveToENV); 120 | 121 | // Attempt to open the DAYNA scsi device. 122 | SCSIWIFIDevice SCSIWifi_open(struct SCSIDevice_OpenData* openData, enum SCSIWifi_OpenResult* errorCode); 123 | 124 | // Free and release any memory allocated as a result of SCSIWifi_open. 125 | void SCSIWifi_close(SCSIWIFIDevice device); 126 | 127 | // Triggers a WIFI scan. Returns 1 if successful 128 | LONG SCSIWifi_scan(SCSIWIFIDevice device, enum SCSIWifi_ScanStatus* status); 129 | 130 | // Check how a current WIFI scan is progressing 131 | LONG SCSIWifi_scanComplete(SCSIWIFIDevice device, enum SCSIWifi_ScanStatus* status); 132 | 133 | // Get the results from the WIFI scan 134 | LONG SCSIWifi_getScanResults(SCSIWIFIDevice device, struct SCSIWifi_ScanResults* results); 135 | 136 | // Enable/Disable the WIFI device (this actually resets its circular buffer) - (setEnable !=0 to enable) 137 | LONG SCSIWifi_enable(SCSIWIFIDevice device, LONG setEnable); 138 | 139 | // Fetch the MAC address from the Wifi card 140 | LONG SCSIWifi_getMACAddress(SCSIWIFIDevice device, struct SCSIWifi_MACAddress* macAddress); 141 | 142 | // Attempt ot join the specified WIFI network - Only way to find out if it worked is to periodically call SCSIWifi_getNetwork 143 | LONG SCSIWifi_joinNetwork(SCSIWIFIDevice device, struct SCSIWifi_JoinRequest* wifi); 144 | 145 | // Fetch information about the currently connected network 146 | LONG SCSIWifi_getNetwork(SCSIWIFIDevice device, struct SCSIWifi_NetworkEntry* connection); 147 | 148 | // Add a Multicast Ethernet address to the adapter 149 | LONG SCSIWifi_addMulticastAddress(SCSIWIFIDevice device, struct SCSIWifi_MACAddress* macAddress); 150 | 151 | // Send an ethernet frame (this is actually queued and sent inside the bluescsi/scsi2sd) 152 | LONG SCSIWifi_sendFrame(SCSIWIFIDevice device, UBYTE* packet, UWORD packetSize); 153 | 154 | // On ENTRY, packetSize should be the memory size of packetBuffer, which SHOULD be SCSIWIFI_PACKET_MAX_SIZE + 6 155 | // If returns TRUE and packetSize=0 then no data is waiting to be read 156 | // Else packetSize will be what was read with the first 6 bytes being in the following format: 157 | // packetSize will *need* to be SCSIWIFI_PACKET_MAX_SIZE+6 158 | // Byte: 0 High Byte of packet size 159 | // 1: Low Byte of packet size 160 | // 2, 3, 4 = 0 161 | // 5: 0 if this was the last packet, or 0x10 if there are more to read 162 | LONG SCSIWifi_receiveFrame(SCSIWIFIDevice device, UBYTE* packetBuffer, UWORD* packetSize); 163 | 164 | 165 | #endif -------------------------------------------------------------------------------- /Common.mk: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # 3 | # Common.mk 4 | # 5 | # author: Henryk Richter 6 | # 7 | # note: when switching between different hc99ardware targets, don`t forget 8 | # "make clean" in between 9 | # 10 | # tools required: 11 | # GNU Make, either VBCC or GCC for AmigaOS/68k, VASM 12 | # recent sana2.h , e.g. from RoadShow SDK 13 | # 14 | # porting: 15 | # you might need to adapt the paths (prefix for Compiler/Includes) 16 | # Some installations have ADE: instead of GG: on Amigaos 17 | # Recent work on AmigaOS cross toolchains suggest /opt/m68k-amigaos/sys-include 18 | # instead of the traditional os-include 19 | # 20 | ############################################################################### 21 | # debug = 1 will include string debugging for terminal/sushi/sashimi 22 | debug = 0 23 | # compiler_vcc = 1 will trigger VBCC, else GCC 24 | compiler_vcc = 1 25 | 26 | ############################################################################### 27 | # prefix for system includes (ASM) 28 | # native AmigaOS compilation: set PREFX=GG: or PREFX=ADE:, depending on toolchain 29 | ############################################################################### 30 | PREFX = $(VBCC)/targets/m68k-amigaos 31 | #PREFX = gg: 32 | SYSINC ?= "-I$(PREFX)/include -I$(PREFX)/include2" 33 | SYSLIB ?= "-L$(PREFX)/lib" 34 | 35 | ############################################################################### 36 | # 37 | # compiler executables (choice of gcc or vbcc) 38 | # 39 | ############################################################################### 40 | ifeq ($(compiler_vcc),1) 41 | 42 | # VBCC (use explicit vlink line for LINK= if complaints about R_PC happen) 43 | CCX = vc +aos68k $(SYSINC) 44 | LINK = vlink -bamigahunk -x -s -mrel -Cvbcc -Bstatic -nostdlib -lamiga $(SYSLIB) #-Rshort 45 | #LINKEXE = vlink -bamigahunk -x -s -mrel -Cvbcc -Bstatic 46 | LINKEXE = vc +aos68k 47 | #LINK = $(CCX) -nostdlib 48 | CFLAGS = -O2 -+ -sc -cpu=$(CPU) 49 | CFLAGS2 = -Os -+ -sc -c99 -cpu=$(CPU2) 50 | 51 | else 52 | 53 | # GCC 54 | CCX = m68k-amigaos-gcc 55 | LINK = $(CCX) -nostartfiles -s 56 | LINKEXE = $(CCX) -s -noixemul 57 | CFLAGS = -O3 -s -m$(CPU) -Wall -noixemul -mregparm=4 -fomit-frame-pointer -msoft-float -noixemul 58 | CFLAGS2 = -O3 -s -m$(CPU2) -Wall -noixemul -mregparm=4 -fomit-frame-pointer -msoft-float -noixemul 59 | 60 | endif 61 | 62 | VASM = vasmm68k_mot 63 | VASMFORMAT = -m$(CPU) -Fhunk -nowarn=2064 -quiet $(SYSINC) 64 | VASMFORMAT2 = -m$(CPU2) -Fhunk -nowarn=2064 -quiet $(SYSINC) 65 | 66 | # unused here 67 | #HOST = $(shell uname) 68 | 69 | ############################################################################### 70 | # 71 | # paths to the local includes 72 | # 73 | ############################################################################### 74 | 75 | IPATH = 76 | 77 | ############################################################################### 78 | # 79 | # compile-level feature definitions 80 | # 81 | ############################################################################### 82 | ifeq ($(compiler_vcc),1) 83 | # skip quotes with VCC, the AmigaOS native version doesn't like them 84 | #DEFINES += -DDEVICEVERSION=$(DEVICEVERSION) -DDEVICEREVISION=$(DEVICEREVISION) 85 | #DEFINES += -DDEVICEDATE=$(DEVICEDATE) 86 | #DEFINES += -DDEVICEEXTRA=$(DEVICEEXTRA) 87 | DEFINES += -DDEVICENAME="$(DEVICEID)" 88 | DEFINES += -DHAVE_VERSION_H=1 89 | #DEFINES += -DNEWSTYLE 90 | #ASMDEFS += -DDEVICEVERSION=$(DEVICEVERSION) -DDEVICEREVISION=$(DEVICEREVISION) 91 | #ASMDEFS += -DDEVICEDATE=$(DEVICEDATE) -DDEVICENAME=$(DEVICEID) 92 | 93 | #DEFINES2 += -DDEVICEVERSION=$(DEVICEVERSION) -DDEVICEREVISION=$(DEVICEREVISION) 94 | #DEFINES2 += -DDEVICEDATE=$(DEVICEDATE) 95 | #DEFINES2 += -DDEVICEEXTRA=$(DEVICEEXTRA) 96 | DEFINES2 += -DDEVICENAME="$(DEVICEID2)" 97 | DEFINES2 += -DHAVE_VERSION_H=1 98 | #DEFINES2 += -DNEWSTYLE 99 | #ASMDEFS2 += -DDEVICEVERSION=$(DEVICEVERSION) -DDEVICEREVISION=$(DEVICEREVISION) 100 | 101 | else 102 | 103 | #DEFINES += -D"DEVICEVERSION=$(DEVICEVERSION)" -D"DEVICEREVISION=$(DEVICEREVISION)" 104 | #DEFINES += -D"DEVICEDATE=$(DEVICEDATE)" 105 | #DEFINES += -D"DEVICEEXTRA=$(DEVICEEXTRA)" 106 | DEFINES += -D"DEVICENAME="$(DEVICEID)"" 107 | DEFINES += -DHAVE_VERSION_H=1 108 | DEFINES += -DNEWSTYLE 109 | #ASMDEFS += -DDEVICEVERSION=$(DEVICEVERSION) -DDEVICEREVISION=$(DEVICEREVISION) 110 | #ASMDEFS += -DDEVICEDATE=$(DEVICEDATE) -DDEVICENAME=$(DEVICEID) 111 | 112 | #DEFINES2 += -D"DEVICEVERSION=$(DEVICEVERSION)" -D"DEVICEREVISION=$(DEVICEREVISION)" 113 | #DEFINES2 += -D"DEVICEDATE=$(DEVICEDATE)" -D"DEVICENAME="$(DEVICEID2)"" 114 | #DEFINES2 += -D"DEVICEEXTRA=$(DEVICEEXTRA)" 115 | DEFINES2 += -D"DEVICENAME="$(DEVICEID2)"" 116 | DEFINES2 += -DHAVE_VERSION_H=1 117 | DEFINES2 += -DNEWSTYLE 118 | #ASMDEFS2 += -DDEVICEVERSION=$(DEVICEVERSION) -DDEVICEREVISION=$(DEVICEREVISION) 119 | 120 | endif 121 | 122 | 123 | ############################################################################### 124 | # 125 | # debug 126 | # 127 | ############################################################################### 128 | ifeq ($(debug),1) 129 | CFLAGS += -DDEBUG -g 130 | CFLAGS2 += -DDEBUG -g 131 | LINKLIBS = -L$(PREFX)/lib -ldebug 132 | endif 133 | 134 | ############################################################################### 135 | # 136 | # compiler flags and optimization levels 137 | # 138 | ############################################################################### 139 | 140 | CFLAGS += -I. -I$(SUBDIR) 141 | CFLAGS2 += -I. -I$(SUBDIR) 142 | LDFLAGS = 143 | 144 | ############################################################################### 145 | # 146 | # objects to build 147 | # 148 | ############################################################################### 149 | # ASM based alternative to deviceheader.o would be romtag.o 150 | 151 | OBJECTS = deviceheader.o deviceinit.o device.o scsiwifi.o 152 | OBJECTS += $(ASMOBJECTS) 153 | 154 | # used for secondary build 155 | OBJECTS2 = $(patsubst %.o,%.2o,$(OBJECTS)) 156 | 157 | ############################################################################### 158 | # 159 | # rules and commands 160 | # 161 | ############################################################################### 162 | 163 | all: $(DEVICEID) $(DEVICEID2) $(TESTTOOL) $(TESTTOOL2) 164 | 165 | clean: 166 | rm -f $(OBJECTS) $(OBJECTS2) 167 | rm -f $(DEVICEID) $(DEVICEID2) $(EXTRACLEAN) 168 | 169 | # not for cross compile :-) 170 | install: $(DEVICEID) $(DEVICEID2) 171 | copy $(DEVICEID) $(DEVICEID2) DEVS: 172 | 173 | 174 | #sdnet: $(DEVICEID) 175 | #expnet: $(DEVICEID2) 176 | 177 | $(DEVICEID) : $(OBJECTS) 178 | $(LINK) $(LDFLAGS) -o $@ $(OBJECTS) $(LINKLIBS) $(LINKOPTS) 179 | 180 | 181 | # separate ruleset for each subdirectory, ./src overrides all other paths for priority 182 | # of platform-optimized routines 183 | 184 | %.o : %.c 185 | $(CCX) -c $(CFLAGS) $(DEFINES) $(IPATH) -o $@ $< 186 | 187 | %.o : %.asm 188 | ${VASM} $(VASMFORMAT) $(ASMDEFS) -I "D:\DaynaChain\amiga-sdk-master\sdkinclude" -o $@ $< 189 | 190 | 191 | 192 | # secondary ruleset (used for expnet, will be ignored if DEVICEID2 is empty) 193 | $(DEVICEID2) : $(OBJECTS2) 194 | $(LINK) $(LDFLAGS) -o $@ $(OBJECTS2) $(LINKLIBS) 195 | 196 | %.2o : %.c 197 | $(CCX) -c $(CFLAGS2) $(DEFINES2) $(IPATH) $< -o $@ 198 | 199 | %.2o : %.asm 200 | ${VASM} $(VASMFORMAT2) $(ASMDEFS2) -o $@ $< 201 | -------------------------------------------------------------------------------- /sana2.h: -------------------------------------------------------------------------------- 1 | #ifndef SANA2_SANA2DEVICE_H 2 | #define SANA2_SANA2DEVICE_H 1 3 | /* 4 | ** $Id: sana2.h,v 1.1 2003/08/06 15:15:40 obarthel Exp $ 5 | ** Includes Release 50.1 6 | ** 7 | ** Structure definitions for SANA-II devices. 8 | ** 9 | ** (C) Copyright 1991-2003 Amiga, Inc. 10 | ** All Rights Reserved 11 | */ 12 | 13 | #ifndef EXEC_TYPES_H 14 | #include 15 | #endif 16 | 17 | #ifndef EXEC_PORTS_H 18 | #include 19 | #endif 20 | 21 | #ifndef EXEC_IO_H 22 | #include 23 | #endif 24 | 25 | #ifndef EXEC_TASKS_H 26 | #include 27 | #endif 28 | 29 | #ifndef EXEC_ERRORS_H 30 | #include 31 | #endif 32 | 33 | #ifndef DEVICES_TIMER_H 34 | #include 35 | #endif 36 | 37 | #ifndef UTILITY_TAGITEM_H 38 | #include 39 | #endif 40 | 41 | #ifndef UTILITY_HOOKS_H 42 | #include 43 | #endif 44 | 45 | /****************************************************************************/ 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | #ifdef __GNUC__ 52 | #ifdef __PPC__ 53 | #pragma pack(2) 54 | #endif 55 | #elif defined(__VBCC__) 56 | #pragma amiga-align 57 | #endif 58 | 59 | /****************************************************************************/ 60 | 61 | #define SANA2_MAX_ADDR_BITS (128) 62 | #define SANA2_MAX_ADDR_BYTES ((SANA2_MAX_ADDR_BITS+7)/8) 63 | 64 | struct IOSana2Req 65 | { 66 | struct IORequest ios2_Req; 67 | 68 | ULONG ios2_WireError; /* wire type specific error */ 69 | ULONG ios2_PacketType; /* packet type */ 70 | UBYTE ios2_SrcAddr[SANA2_MAX_ADDR_BYTES]; /* source address */ 71 | UBYTE ios2_DstAddr[SANA2_MAX_ADDR_BYTES]; /* dest address */ 72 | ULONG ios2_DataLength; /* length of packet data */ 73 | APTR ios2_Data; /* packet data */ 74 | APTR ios2_StatData; /* statistics data pointer */ 75 | APTR ios2_BufferManagement; /* see SANA-II OpenDevice adoc */ 76 | }; 77 | 78 | /* 79 | ** Defines for the io_Flags field 80 | */ 81 | #define SANA2IOB_RAW (7) /* raw packet IO requested */ 82 | #define SANA2IOB_BCAST (6) /* broadcast packet (received) */ 83 | #define SANA2IOB_MCAST (5) /* multicast packet (received) */ 84 | #define SANA2IOB_QUICK (IOB_QUICK) /* quick IO requested (0) */ 85 | 86 | #define SANA2IOF_RAW (1<) 349 | */ 350 | #define S2ERR_NO_ERROR 0 /* peachy-keen */ 351 | #define S2ERR_NO_RESOURCES 1 /* resource allocation failure */ 352 | #define S2ERR_BAD_ARGUMENT 3 /* garbage somewhere */ 353 | #define S2ERR_BAD_STATE 4 /* inappropriate state */ 354 | #define S2ERR_BAD_ADDRESS 5 /* who? */ 355 | #define S2ERR_MTU_EXCEEDED 6 /* too much to chew */ 356 | #define S2ERR_NOT_SUPPORTED 8 /* hardware can't support cmd */ 357 | #define S2ERR_SOFTWARE 9 /* software error detected */ 358 | #define S2ERR_OUTOFSERVICE 10 /* driver is OFFLINE */ 359 | #define S2ERR_TX_FAILURE 11 /* Transmission attempt failed */ 360 | 361 | /* 362 | ** From 363 | ** 364 | ** IOERR_OPENFAIL (-1) * device/unit failed to open * 365 | ** IOERR_ABORTED (-2) * request terminated early [after AbortIO()] * 366 | ** IOERR_NOCMD (-3) * command not supported by device * 367 | ** IOERR_BADLENGTH (-4) * not a valid length (usually IO_LENGTH) * 368 | ** IOERR_BADADDRESS (-5) * invalid address (misaligned or bad range) * 369 | ** IOERR_UNITBUSY (-6) * device opens ok, but requested unit is busy * 370 | ** IOERR_SELFTEST (-7) * hardware failed self-test * 371 | */ 372 | 373 | /* 374 | ** Defined errors for ios2_WireError 375 | */ 376 | #define S2WERR_GENERIC_ERROR 0 /* no specific info available */ 377 | #define S2WERR_NOT_CONFIGURED 1 /* unit not configured */ 378 | #define S2WERR_UNIT_ONLINE 2 /* unit is currently online */ 379 | #define S2WERR_UNIT_OFFLINE 3 /* unit is currently offline */ 380 | #define S2WERR_ALREADY_TRACKED 4 /* protocol already tracked */ 381 | #define S2WERR_NOT_TRACKED 5 /* protocol not tracked */ 382 | #define S2WERR_BUFF_ERROR 6 /* buff mgt func returned error */ 383 | #define S2WERR_SRC_ADDRESS 7 /* source address problem */ 384 | #define S2WERR_DST_ADDRESS 8 /* destination address problem */ 385 | #define S2WERR_BAD_BROADCAST 9 /* broadcast address problem */ 386 | #define S2WERR_BAD_MULTICAST 10 /* multicast address problem */ 387 | #define S2WERR_MULTICAST_FULL 11 /* multicast address list full */ 388 | #define S2WERR_BAD_EVENT 12 /* unsupported event class */ 389 | #define S2WERR_BAD_STATDATA 13 /* statdata failed sanity check */ 390 | /*** THERE IS NO WIRE ERROR CODE 14 ***/ 391 | #define S2WERR_IS_CONFIGURED 15 /* attempt to config twice */ 392 | #define S2WERR_NULL_POINTER 16 /* null pointer detected */ 393 | #define S2WERR_TOO_MANY_RETRIES 17 /* tx failed - too many retries */ 394 | #define S2WERR_RCVREL_HDW_ERR 18 /* Driver fixable HW error */ 395 | #define S2WERR_UNIT_DISCONNECTED 19 /* unit is currently not connected */ 396 | #define S2WERR_UNIT_CONNECTED 20 /* unit is currently connected */ 397 | #define S2WERR_INVALID_OPTION 21 /* invalid option rejected */ 398 | #define S2WERR_MISSING_OPTION 22 /* a mandatory option is missing */ 399 | #define S2WERR_AUTHENTICATION_FAILED 23 /* could not log in */ 400 | /* 401 | ** For our dsylexic friends 402 | */ 403 | #define S2WERR_TOO_MANY_RETIRES S2WERR_TOO_MANY_RETRIES 404 | 405 | /* 406 | ** Defined events 407 | */ 408 | #define S2EVENT_ERROR (1UL<< 0) /* error catch all */ 409 | #define S2EVENT_TX (1UL<< 1) /* transmitter error catch all */ 410 | #define S2EVENT_RX (1UL<< 2) /* receiver error catch all */ 411 | #define S2EVENT_ONLINE (1UL<< 3) /* unit is in service */ 412 | #define S2EVENT_OFFLINE (1UL<< 4) /* unit is not in service */ 413 | #define S2EVENT_BUFF (1UL<< 5) /* buff mgt function error */ 414 | #define S2EVENT_HARDWARE (1UL<< 6) /* hardware error catch all */ 415 | #define S2EVENT_SOFTWARE (1UL<< 7) /* software error catch all */ 416 | #define S2EVENT_CONFIGCHANGED (1UL<< 8) /* driver configuration changed */ 417 | #define S2EVENT_CONNECT (1UL<< 9) /* driver has opened session */ 418 | #define S2EVENT_DISCONNECT (1UL<<10) /* driver has closed session */ 419 | 420 | /****************************************************************************/ 421 | 422 | #ifdef __GNUC__ 423 | #ifdef __PPC__ 424 | #pragma pack() 425 | #endif 426 | #elif defined(__VBCC__) 427 | #pragma default-align 428 | #endif 429 | 430 | #ifdef __cplusplus 431 | } 432 | #endif 433 | 434 | /****************************************************************************/ 435 | 436 | #endif /* SANA2_SANA2DEVICE_H */ 437 | -------------------------------------------------------------------------------- /scsiwifi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SCSI DaynaPORT Device (scsidayna.device) by RobSmithDev 3 | * DaynaPORT Interface Commands 4 | * 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "macros.h" 16 | #include 17 | #include 18 | #include "debug.h" 19 | #include "scsiwifi.h" 20 | 21 | 22 | #define SCSI_INQUIRY 0x12 23 | #define SCSI_NETWORK_WIFI_READFRAME 0x08 24 | #define SCSI_NETWORK_WIFI_GETMACADDRESS 0x09 // gvpscsi.device doesn't like this command code 25 | #define SCSI_NETWORK_WIFI_WRITEFRAME 0x0A 26 | #define SCSI_NETWORK_WIFI_ADDMULTICAST 0x0D 27 | #define SCSI_NETWORK_WIFI_ENABLE 0x0E 28 | 29 | // These are custom extra SCSI commands specific to this device 30 | #define SCSI_NETWORK_WIFI_CMD 0x1c 31 | // Sub commands 32 | #define SCSI_NETWORK_WIFI_OPT_SCAN 0x01 33 | #define SCSI_NETWORK_WIFI_OPT_COMPLETE 0x02 34 | #define SCSI_NETWORK_WIFI_OPT_SCAN_RESULTS 0x03 35 | #define SCSI_NETWORK_WIFI_OPT_INFO 0x04 36 | #define SCSI_NETWORK_WIFI_OPT_JOIN 0x05 37 | #define SCSI_NETWORK_WIFI_OPT_ALTREAD 0x08 38 | #define SCSI_NETWORK_WIFI_OPT_GETMACADDRESS 0x09 39 | 40 | #define INQUIRE_BUFFER_SIZE 64 41 | 42 | #define NUM_TOKENS 7 43 | static char* CONFIG_TOKENS[NUM_TOKENS] = {"DEVICE","DEVICEID","PRIORITY","MODE","AUTOCONNECT","SSID","KEY"}; 44 | 45 | // Prepares the SCSI command and resets some of the result values 46 | #define SCSI_PREPCMD(device, cmd, sub, a, b, c, d) \ 47 | device->scsiCommand[0] = cmd; device->scsiCommand[1] = sub; \ 48 | device->scsiCommand[2] = a; device->scsiCommand[3] = b; \ 49 | device->scsiCommand[4] = c; device->scsiCommand[5] = d; \ 50 | device->Cmd.scsi_SenseActual = 0; device->Cmd.scsi_Actual = 0; \ 51 | device->Cmd.scsi_Status = 1; // Default to error 52 | 53 | // Internal SCSI device data 54 | struct SCSIDevice { 55 | struct ExecBase *sc_SysBase; 56 | struct UtilityBase *sc_UtilityBase; 57 | struct DosBase *sc_dosBase; 58 | struct IOStdReq* SCSIReq; 59 | struct MsgPort* Port; 60 | struct SCSICmd Cmd; 61 | char senseData[20]; 62 | USHORT scsiMode; 63 | UBYTE* scsiCommand; // buffer to hold command, 16-bit aligned (12 bytes) 64 | }; 65 | 66 | #define SysBase dev->sc_SysBase 67 | #define UtilityBase dev->sc_UtilityBase 68 | #define DOSBase dev->sc_dosBase 69 | 70 | typedef struct SCSIDevice* LSCSIDevice; 71 | 72 | // not ideal but couldn't get the compiler to give me __lmodu and __ldivu 73 | // I'm sure someone who knows what they're doing can do this much better :) 74 | void muldiv(USHORT num, USHORT divide, USHORT* result, USHORT* mod) { 75 | *result = 0; 76 | while (num >= divide) { 77 | (* result)++; 78 | num -= divide; 79 | } 80 | *mod = num; 81 | } 82 | 83 | // convert USHORT to string and appends a new line character 84 | void _ustoa(USHORT num, char* str) { 85 | char buffer[16]; 86 | char* s = buffer; 87 | USHORT divres, divmod; 88 | do { 89 | muldiv(num, 10, &divres, &divmod); 90 | *s++ = '0' + divmod; 91 | num = divres; 92 | } while (num); 93 | s--; 94 | 95 | while (s>=buffer) *str++ = *s--; 96 | *str++ = '\0'; 97 | } 98 | 99 | // convert SHORT to string and appends a new line character 100 | void _stoa(SHORT num, char* str) { 101 | char buffer[16]; 102 | char* s = buffer; 103 | USHORT divres, divmod, number; 104 | 105 | LONG neg = num < 0; 106 | if (neg) number = -num; else number = num; 107 | do { 108 | muldiv(number, 10, &divres, &divmod); 109 | *s++ = '0' + divmod; 110 | number = divres; 111 | } while (number); 112 | s--; 113 | 114 | if (neg) *str++ = '-'; 115 | 116 | while (s>=buffer) *str++ = *s--; 117 | *str++ = '\0'; 118 | } 119 | 120 | // Ansi to Unsigned Short 121 | USHORT _atous(char* str) { 122 | USHORT out = 0; 123 | while (*str) { 124 | if ((*str >= '0') && (*str <= '9')) { 125 | out *= 10; 126 | out += *str - '0'; 127 | } 128 | str++; 129 | } 130 | return out; 131 | } 132 | 133 | // Ansi to Signed Short 134 | SHORT _atos(char* str) { 135 | LONG out = 0; 136 | LONG neg = 0; 137 | while (*str) { 138 | if ((*str >= '0') && (*str <= '9')) { 139 | out *= 10; 140 | out += *str - '0'; 141 | } else if (*str == '-') neg = 1; // make it negative! 142 | str++; 143 | } 144 | if (neg) return (SHORT)(-out); 145 | return out; 146 | } 147 | 148 | // Looks at data, which should be TOKEN=VALUE format. 149 | // If valid then the value will be populated to the first character after the "=" symbol 150 | // Returns 0 if the line is invalid 151 | LONG tokeniseSetting(char* data, char** value) { 152 | *value = NULL; 153 | while (*data) { 154 | if (*data == '=') { 155 | *data = '\0'; 156 | *value = data+1; 157 | return 1; 158 | } 159 | data++; 160 | } 161 | return 0; 162 | } 163 | 164 | // Safe (I hope ;) implementation to prevent buffer overflows 165 | void strcpy_s(char* dest, char* src, USHORT maxLength) { 166 | USHORT i = strlen(src); 167 | if (i>=maxLength) i = maxLength; 168 | memcpy(dest, src, i-1); 169 | dest[i-1] = '\0'; 170 | } 171 | 172 | // Removes any trailing newline characters 173 | void removeNL(char* text) { 174 | while (*text) { 175 | if (*text == '\n') { 176 | *text='\0'; 177 | return; 178 | } 179 | text++; 180 | } 181 | } 182 | 183 | // Populates settings with default values 184 | void SCSIWifi_defaultSettings(struct ScsiDaynaSettings* settings) { 185 | strcpy(settings->deviceName, "scsi.device"); 186 | settings->deviceID = -1; // auto detect 187 | settings->taskPriority = 0; // -128 to 127 - probably should be 0 but works faster set as 1! 188 | settings->scsiMode = 1; // Driver mode. 0=DynaPORT, 1=24 Byte Patch (scsi.device), 2=Single Write Mode (gvpscsi.device) 189 | settings->autoConnect = 0; // auto connect to the WIFI? 190 | strcpy(settings->ssid, ""); 191 | strcpy(settings->key, ""); 192 | } 193 | 194 | // Loads settings from the ENV, returns 0 if the settings were bad and defaults were setup 195 | LONG SCSIWifi_loadSettings(void *utilityBase, void* dosBase, struct ScsiDaynaSettings* settings) { 196 | struct SCSIDevice devTmp; 197 | LSCSIDevice dev = &devTmp; 198 | devTmp.sc_dosBase = dosBase; 199 | devTmp.sc_UtilityBase = utilityBase; 200 | 201 | USHORT modeConfigured = 0; 202 | SCSIWifi_defaultSettings(settings); 203 | BPTR fh; 204 | if (fh = Open("ENV:scsidayna.prefs",MODE_OLDFILE)) { 205 | char buffer[128]; 206 | USHORT matches = 0; 207 | while (FGets(fh, buffer, 128)) { 208 | char* value; 209 | if (tokeniseSetting(buffer, &value)) { 210 | // find a match 211 | for (USHORT token = 0; token < NUM_TOKENS; token++) { 212 | matches++; 213 | if (Stricmp(CONFIG_TOKENS[token], buffer) == 0) { 214 | switch (token) { 215 | case 0: strcpy_s(settings->deviceName, value, 108); break; 216 | case 1: settings->deviceID = _atos(value); break; 217 | case 2: settings->taskPriority = _atos(value); 218 | if (settings->taskPriority>127) settings->taskPriority = 127; 219 | if (settings->taskPriority<-128) settings->taskPriority = -128; 220 | break; 221 | case 3: settings->scsiMode = _atous(value); 222 | if (settings->scsiMode>2) settings->scsiMode=2; 223 | modeConfigured = 1; 224 | break; 225 | case 4: settings->autoConnect = _atous(value); break; 226 | case 5: strcpy_s(settings->ssid, value, 64); break; 227 | case 6: strcpy_s(settings->key, value, 64); break; 228 | default: matches--; break; 229 | } 230 | break; 231 | } 232 | } 233 | } 234 | } 235 | if (matches < 1) SCSIWifi_defaultSettings(settings); 236 | Close(fh); 237 | return matches > 0; 238 | } 239 | 240 | // If no mode was set, but a GVP device was specified then jump to mode 2. It will default to 1 anyway 241 | if (!modeConfigured) { 242 | if ((ToUpper(settings->deviceName[0]) == 'G') && (ToUpper(settings->deviceName[0]) == 'V') && (ToUpper(settings->deviceName[0]) == 'P')) settings->scsiMode = 2; 243 | } 244 | 245 | return 0; 246 | } 247 | 248 | // Saves settings back to ENV or ENVARC 249 | LONG SCSIWifi_saveSettings(struct DosBase *dosBase, struct ScsiDaynaSettings* settings, LONG saveToENV) { 250 | struct SCSIDevice devTmp; 251 | LSCSIDevice dev = &devTmp; 252 | devTmp.sc_dosBase = dosBase; 253 | BPTR fh; 254 | if (fh = Open(saveToENV ? "ENV:scsidayna.prefs" : "ENVARC:scsidayna.prefs",MODE_NEWFILE)) { 255 | // Save each setting in tern 256 | USHORT good = 1; 257 | char tmp[20]; // temp buffer 258 | for (USHORT token = 0; token < NUM_TOKENS; token++) { 259 | if (!FPuts(fh, CONFIG_TOKENS[token])) good = 0; 260 | if (!FPuts(fh, "=")) good = 0; 261 | switch (token) { 262 | case 0: if (!FPuts(fh, settings->deviceName)) good = 0; break; 263 | case 1: _stoa(settings->deviceID, tmp); if (!FPuts(fh, tmp)) good = 0; break; 264 | case 2: _stoa(settings->taskPriority, tmp); if (!FPuts(fh, tmp)) good = 0; break; 265 | case 3: _ustoa(settings->scsiMode, tmp); if (!FPuts(fh, tmp)) good = 0; break; 266 | case 4: _ustoa(settings->autoConnect, tmp); if (!FPuts(fh, tmp)) good = 0; break; 267 | case 5: if (!FPuts(fh, settings->ssid)) good = 0; break; 268 | case 6: if (!FPuts(fh, settings->key)) good = 0; break; 269 | } 270 | if (!FPuts(fh, "\n")) good = 0; 271 | } 272 | 273 | Close(fh); 274 | return good; 275 | } 276 | return 0; 277 | } 278 | 279 | struct IORequest* _CreateExtIO(LSCSIDevice dev, struct MsgPort *replyPort, long size) { 280 | struct IORequest *io = NULL; 281 | 282 | if (replyPort) { 283 | if (io = AllocMem(size, MEMF_PUBLIC | MEMF_CLEAR)) { 284 | io->io_Message.mn_ReplyPort = replyPort; 285 | io->io_Message.mn_Length = size; 286 | io->io_Message.mn_Node.ln_Type = NT_REPLYMSG; 287 | } 288 | } 289 | return io; 290 | } 291 | 292 | void _DeleteExtIO(LSCSIDevice dev, struct IORequest *io) { 293 | if (io) { 294 | long bad = -1; 295 | io->io_Message.mn_Node.ln_Succ = (void *)bad; 296 | io->io_Device = (void *)bad; 297 | FreeMem(io, io->io_Message.mn_Length); 298 | } 299 | } 300 | 301 | struct MsgPort *_CreatePort(LSCSIDevice dev, UBYTE *name, LONG pri) { 302 | LONG sigBit; 303 | struct MsgPort *mp; 304 | 305 | if ((sigBit = AllocSignal(-1L)) == -1) return(NULL); 306 | 307 | mp = (struct MsgPort *)AllocMem((ULONG)sizeof(struct MsgPort),(ULONG)MEMF_PUBLIC | MEMF_CLEAR); 308 | if (!mp) { 309 | FreeSignal(sigBit); 310 | return(NULL); 311 | } 312 | mp->mp_Node.ln_Name = name; 313 | mp->mp_Node.ln_Pri = pri; 314 | mp->mp_Node.ln_Type = NT_MSGPORT; 315 | mp->mp_Flags = PA_SIGNAL; 316 | mp->mp_SigBit = sigBit; 317 | mp->mp_SigTask = (struct Task *)FindTask(0L); 318 | /* Find THIS task. */ 319 | 320 | if (name) AddPort(mp); 321 | else NEWLIST(&(mp->mp_MsgList)); /* init message list */ 322 | 323 | return(mp); 324 | } 325 | 326 | void _DeletePort(LSCSIDevice dev, struct MsgPort *mp) { 327 | if ( mp->mp_Node.ln_Name ) RemPort(mp); /* if it was public... */ 328 | 329 | mp->mp_SigTask = (struct Task *) -1; 330 | /* Make it difficult to re-use the port */ 331 | mp->mp_MsgList.lh_Head = (struct Node *) -1; 332 | 333 | FreeSignal( mp->mp_SigBit ); 334 | FreeMem( mp, (ULONG)sizeof(struct MsgPort) ); 335 | } 336 | 337 | // Close and free the open SCSI device 338 | void _SCSIWifi_close(LSCSIDevice dev) { 339 | if (!dev) return; 340 | if (dev->SCSIReq) { 341 | if (!(CheckIO((struct IORequest *)dev->SCSIReq))) { 342 | AbortIO((struct IORequest *)dev->SCSIReq); 343 | WaitIO((struct IORequest *)dev->SCSIReq); 344 | } 345 | CloseDevice((struct IORequest *)dev->SCSIReq); 346 | _DeleteExtIO(dev, (struct IORequest *)dev->SCSIReq); 347 | } 348 | if (dev->scsiCommand) FreeVec(dev->scsiCommand); 349 | if (dev->Port) _DeletePort(dev, dev->Port); 350 | FreeVec(dev); 351 | } 352 | 353 | // Returns NULL on error (or not found), and a valid struct if its the BlueScsi Network Device 354 | SCSIWIFIDevice SCSIWifi_open(struct SCSIDevice_OpenData* openData, enum SCSIWifi_OpenResult* errorCode) { 355 | LSCSIDevice dev; 356 | { 357 | struct SCSIDevice devTmp; 358 | dev = &devTmp; 359 | dev->sc_SysBase = openData->sysBase; 360 | dev->sc_UtilityBase = openData->utilityBase; 361 | dev->sc_dosBase = openData->dosBase; 362 | // dev->sysBase needs to be defined here for this to work! 363 | dev = (LSCSIDevice)AllocVec(sizeof(struct SCSIDevice),MEMF_PUBLIC|MEMF_CLEAR); 364 | } 365 | { 366 | if (!dev) { 367 | *errorCode = sworOutOfMem; 368 | return NULL; 369 | } 370 | 371 | dev->sc_SysBase = openData->sysBase; 372 | dev->sc_UtilityBase = openData->utilityBase; 373 | dev->sc_dosBase = openData->dosBase; 374 | 375 | dev->Port = _CreatePort(dev, NULL, 0); 376 | if (!dev->Port) { 377 | *errorCode = sworOutOfMem; 378 | return NULL; 379 | } 380 | dev->SCSIReq = (struct IOStdReq*)_CreateExtIO(dev, dev->Port, sizeof(struct IOStdReq)); 381 | if (!dev->SCSIReq) { 382 | *errorCode = sworOutOfMem; 383 | _SCSIWifi_close(dev); 384 | return NULL; 385 | } 386 | // 6 bytes for command, 6 used by some of the status replies 387 | dev->scsiCommand = AllocVec(12, MEMF_PUBLIC|MEMF_CLEAR); 388 | 389 | // Open driver 390 | BYTE err = OpenDevice(openData->deviceDriverName, openData->deviceID, (struct IORequest*)dev->SCSIReq, 0); 391 | if (err != 0) { 392 | *errorCode = sworOpenDeviceFailed; 393 | _DeleteExtIO(dev, (struct IORequest *)dev->SCSIReq); 394 | dev->SCSIReq = NULL; 395 | _SCSIWifi_close(dev); 396 | return NULL; 397 | } 398 | dev->scsiMode = openData->scsiMode; 399 | 400 | // Setup the SCSI command structure 401 | dev->SCSIReq->io_Length = sizeof(struct SCSICmd); 402 | dev->SCSIReq->io_Data = (APTR)&dev->Cmd; 403 | dev->SCSIReq->io_Command = HD_SCSICMD; 404 | 405 | dev->Cmd.scsi_CmdLength = 6; 406 | dev->Cmd.scsi_Command = dev->scsiCommand; 407 | dev->Cmd.scsi_SenseData = (UBYTE*)&dev->senseData; 408 | dev->Cmd.scsi_SenseLength = 20; 409 | 410 | UBYTE* tmpBuffer = AllocVec(INQUIRE_BUFFER_SIZE+16, MEMF_PUBLIC); 411 | if (!tmpBuffer) { 412 | *errorCode = sworOutOfMem; 413 | _SCSIWifi_close(dev); 414 | return NULL; 415 | } 416 | SCSI_PREPCMD(dev, SCSI_INQUIRY, 0, 0, 0, INQUIRE_BUFFER_SIZE, 0); 417 | dev->Cmd.scsi_Data = (UWORD*)tmpBuffer; 418 | dev->Cmd.scsi_Length = INQUIRE_BUFFER_SIZE; 419 | dev->Cmd.scsi_Flags = SCSIF_READ | SCSIF_AUTOSENSE; 420 | 421 | DoIO( (struct IORequest*)dev->SCSIReq ); 422 | 423 | // Failed 424 | if (dev->Cmd.scsi_Status) { 425 | *errorCode = sworInquireFail; 426 | FreeVec(tmpBuffer); 427 | _SCSIWifi_close(dev); 428 | return NULL; 429 | } 430 | // Check the result 431 | if (dev->Cmd.scsi_Actual > 26) { 432 | // A little hacky but will work for us 433 | tmpBuffer[13] = '\0'; 434 | tmpBuffer[25] = '\0'; 435 | // Check it's the device we're looking for 436 | if ((Stricmp(&tmpBuffer[8], "Dayna") == 0) && 437 | (Stricmp(&tmpBuffer[16], "SCSI/Link") == 0)) { 438 | FreeVec(tmpBuffer); 439 | *errorCode = sworOK; 440 | return (SCSIWIFIDevice)dev; 441 | } 442 | } 443 | *errorCode = sworNotDaynaDevice; 444 | FreeVec(tmpBuffer); 445 | _SCSIWifi_close(dev); 446 | } 447 | return NULL; 448 | } 449 | 450 | // Close and free the open SCSI device 451 | void SCSIWifi_close(SCSIWIFIDevice device) { 452 | if (!device) return; 453 | _SCSIWifi_close((LSCSIDevice)device); 454 | } 455 | 456 | // Triggers a WIFI scan. Returns 1 if successful 457 | LONG SCSIWifi_scan(SCSIWIFIDevice device, enum SCSIWifi_ScanStatus* status) { 458 | LSCSIDevice dev = (LSCSIDevice)device; 459 | *status = swssError; 460 | 461 | SCSI_PREPCMD(dev, SCSI_NETWORK_WIFI_CMD, SCSI_NETWORK_WIFI_OPT_SCAN, 0, 0, 0, 0); 462 | 463 | dev->Cmd.scsi_Data = (APTR)&dev->scsiCommand; 464 | dev->Cmd.scsi_Length = 4; // NEEDS to be 4 465 | dev->Cmd.scsi_Flags = SCSIF_READ | SCSIF_AUTOSENSE; 466 | 467 | DoIO( (struct IORequest*)dev->SCSIReq ); 468 | 469 | // Failed 470 | if (dev->Cmd.scsi_Status) return 0; 471 | 472 | // Check the result 473 | if (dev->Cmd.scsi_Actual == 1) { 474 | if ((char)dev->scsiCommand[6]==-1) 475 | *status = swssBusy; else 476 | *status = swssError; 477 | return 1; 478 | } 479 | 480 | return 0; 481 | } 482 | 483 | // Check how a current WIFI scan is progressing 484 | LONG SCSIWifi_scanComplete(SCSIWIFIDevice device, enum SCSIWifi_ScanStatus* status) { 485 | LSCSIDevice dev = (LSCSIDevice)device; 486 | 487 | *status = swssError; 488 | 489 | SCSI_PREPCMD(dev, SCSI_NETWORK_WIFI_CMD, SCSI_NETWORK_WIFI_OPT_COMPLETE, 0, 0, 0, 0); 490 | 491 | dev->Cmd.scsi_Data = (APTR)&dev->scsiCommand[6]; 492 | dev->Cmd.scsi_Length = 4; // NEEDS to be 4 493 | dev->Cmd.scsi_Flags = SCSIF_READ | SCSIF_AUTOSENSE; 494 | 495 | DoIO( (struct IORequest*)dev->SCSIReq ); 496 | 497 | // Failed 498 | if (dev->Cmd.scsi_Status) return 0; 499 | 500 | // Check the result 501 | if (dev->Cmd.scsi_Actual == 1) { 502 | switch (dev->scsiCommand[6]) { 503 | case 1: *status = swssComplete; break; 504 | case 0: *status = swssBusy; break; 505 | default: *status = swssNotRunning; break; 506 | } 507 | return 1; 508 | } 509 | return 0; 510 | } 511 | 512 | // Get the results from the WIFI scan 513 | LONG SCSIWifi_getScanResults(SCSIWIFIDevice device, struct SCSIWifi_ScanResults* results) { 514 | LSCSIDevice dev = (LSCSIDevice)device; 515 | memset(results, 0, sizeof(struct SCSIWifi_ScanResults)); 516 | 517 | SCSI_PREPCMD(dev, SCSI_NETWORK_WIFI_CMD, SCSI_NETWORK_WIFI_OPT_SCAN_RESULTS, 0, 0, 0, 0); 518 | 519 | dev->Cmd.scsi_Data = (APTR)results; 520 | dev->Cmd.scsi_Length = sizeof(struct SCSIWifi_ScanResults); 521 | dev->Cmd.scsi_Flags = SCSIF_READ | SCSIF_AUTOSENSE; 522 | 523 | DoIO( (struct IORequest*)dev->SCSIReq ); 524 | 525 | // Failed 526 | if (dev->Cmd.scsi_Status) return 0; 527 | 528 | // Check the result - the format exactly matches the struct we're supplying 529 | if (dev->Cmd.scsi_Actual >= 2) { 530 | UWORD size = results->count; // couldn't get DIVIDE in VBCC working :( 531 | results->count = 0; 532 | while (size >= sizeof(struct SCSIWifi_NetworkEntry)) { 533 | size -= sizeof(struct SCSIWifi_NetworkEntry); 534 | results->count++; 535 | } 536 | return 1; 537 | } 538 | return 0; 539 | } 540 | 541 | // Enable/Disable the WIFI device (this actually resets its circular buffer) 542 | LONG SCSIWifi_enable(SCSIWIFIDevice device, LONG setEnable) { 543 | LSCSIDevice dev = (LSCSIDevice)device; 544 | SCSI_PREPCMD(dev, SCSI_NETWORK_WIFI_ENABLE, 0, 0, 0, 0, setEnable ? 0x80 : 0); 545 | 546 | dev->Cmd.scsi_Data = NULL; 547 | dev->Cmd.scsi_Length = 0; 548 | dev->Cmd.scsi_Flags = SCSIF_READ | SCSIF_AUTOSENSE; 549 | 550 | DoIO( (struct IORequest*)dev->SCSIReq ); 551 | 552 | if (dev->Cmd.scsi_Status) return 0; 553 | 554 | return 1; 555 | } 556 | 557 | // Fetch the MAC address from the Wifi card 558 | LONG SCSIWifi_getMACAddress(SCSIWIFIDevice device, struct SCSIWifi_MACAddress* macAddress) { 559 | LSCSIDevice dev = (LSCSIDevice)device; 560 | 561 | SCSI_PREPCMD(dev, SCSI_NETWORK_WIFI_CMD, SCSI_NETWORK_WIFI_OPT_GETMACADDRESS, 0, 0, 0, 0); 562 | 563 | macAddress->valid = 0; 564 | dev->Cmd.scsi_Data = (APTR)&dev->scsiCommand[6]; 565 | dev->Cmd.scsi_Length = 6; 566 | dev->Cmd.scsi_Flags = SCSIF_READ | SCSIF_AUTOSENSE; 567 | 568 | DoIO( (struct IORequest*)dev->SCSIReq ); 569 | 570 | if (dev->Cmd.scsi_Status) return 0; 571 | 572 | if (dev->Cmd.scsi_Actual == 6) { 573 | memcpy(macAddress->address, &dev->scsiCommand[6], 6); 574 | macAddress->valid = 1; 575 | return 1; 576 | } 577 | return 0; 578 | } 579 | 580 | // Attempt ot join the specified WIFI network - Only way to find out if it worked is to periodically call SCSIWifi_getNetwork 581 | LONG SCSIWifi_joinNetwork(SCSIWIFIDevice device, struct SCSIWifi_JoinRequest* wifi) { 582 | LSCSIDevice dev = (LSCSIDevice)device; 583 | 584 | SCSI_PREPCMD(dev, SCSI_NETWORK_WIFI_CMD, SCSI_NETWORK_WIFI_OPT_JOIN, 0, 585 | sizeof(struct SCSIWifi_JoinRequest) >> 8, 586 | sizeof(struct SCSIWifi_JoinRequest) & 0xFF, 587 | 0); 588 | 589 | dev->Cmd.scsi_Data = (APTR)wifi; 590 | dev->Cmd.scsi_Length = sizeof(struct SCSIWifi_JoinRequest); 591 | dev->Cmd.scsi_Flags = SCSIF_WRITE | SCSIF_AUTOSENSE; 592 | 593 | DoIO( (struct IORequest*)dev->SCSIReq ); 594 | 595 | if (dev->Cmd.scsi_Status) return 0; 596 | 597 | return 1; 598 | } 599 | 600 | // Fetch information about the currently connected network 601 | LONG SCSIWifi_getNetwork(SCSIWIFIDevice device, struct SCSIWifi_NetworkEntry* connection) { 602 | LSCSIDevice dev = (LSCSIDevice)device; 603 | memset(connection, 0, sizeof(struct SCSIWifi_NetworkEntry)); 604 | 605 | SCSI_PREPCMD(dev, SCSI_NETWORK_WIFI_CMD, SCSI_NETWORK_WIFI_OPT_INFO, 0, 0, 0, 0); 606 | 607 | UBYTE* netBuffer = AllocVec(sizeof(struct SCSIWifi_NetworkEntry) + 2,MEMF_PUBLIC|MEMF_CLEAR); 608 | if (!netBuffer) return 0; 609 | 610 | dev->Cmd.scsi_Data = (APTR)netBuffer; 611 | dev->Cmd.scsi_Length = sizeof(struct SCSIWifi_NetworkEntry) + 2; 612 | dev->Cmd.scsi_Flags = SCSIF_READ | SCSIF_AUTOSENSE; 613 | 614 | DoIO( (struct IORequest*)dev->SCSIReq ); 615 | 616 | if (dev->Cmd.scsi_Status) { 617 | FreeVec(netBuffer); 618 | return 0; 619 | } 620 | 621 | // Check the result 622 | if (dev->Cmd.scsi_Actual > 2) { 623 | UWORD size = (netBuffer[0] << 8) + netBuffer[1]; 624 | if (size > sizeof(struct SCSIWifi_NetworkEntry)) size = sizeof(struct SCSIWifi_NetworkEntry); 625 | if (size > dev->Cmd.scsi_Actual-2) size = dev->Cmd.scsi_Actual - 2; 626 | memcpy(connection, &netBuffer[2], size); 627 | FreeVec(netBuffer); 628 | 629 | return (size == sizeof(struct SCSIWifi_NetworkEntry)) ? 1 : 0; 630 | } 631 | 632 | FreeVec(netBuffer); 633 | return 0; 634 | } 635 | 636 | // Add a Multicast Ethernet address to the adapter 637 | LONG SCSIWifi_addMulticastAddress(SCSIWIFIDevice device, struct SCSIWifi_MACAddress* macAddress) { 638 | LSCSIDevice dev = (LSCSIDevice)device; 639 | 640 | SCSI_PREPCMD(dev, SCSI_NETWORK_WIFI_ADDMULTICAST, 0, 0, 6, 0, 0); 641 | memcpy(&dev->scsiCommand[6], macAddress->address, 6); 642 | 643 | dev->Cmd.scsi_Data = (APTR)&dev->scsiCommand[6]; 644 | dev->Cmd.scsi_Length = 6; 645 | dev->Cmd.scsi_Flags = SCSIF_WRITE | SCSIF_AUTOSENSE; 646 | 647 | DoIO( (struct IORequest*)dev->SCSIReq ); 648 | 649 | LONG ret = 1; 650 | if (dev->Cmd.scsi_Status) ret = 0; 651 | 652 | return ret; 653 | } 654 | 655 | // Send an ethernet frame (this is actually queued and sent inside the bluescsi/scsi2sd) 656 | LONG SCSIWifi_sendFrame(SCSIWIFIDevice device, UBYTE* packet, UWORD packetSize) { 657 | LSCSIDevice dev = (LSCSIDevice)device; 658 | 659 | SCSI_PREPCMD(dev, SCSI_NETWORK_WIFI_WRITEFRAME, 0, 0, packetSize >> 8, packetSize & 0xFF, 0); 660 | dev->Cmd.scsi_Data = (APTR)packet; 661 | dev->Cmd.scsi_Length = packetSize; 662 | dev->Cmd.scsi_Flags = SCSIF_WRITE | SCSIF_AUTOSENSE; 663 | 664 | DoIO( (struct IORequest*)dev->SCSIReq ); 665 | 666 | if (dev->Cmd.scsi_Status) return 0; 667 | return 1; 668 | } 669 | 670 | 671 | 672 | // On ENTRY, packetSize should be the memory size of packetBuffer, which SHOULD be NETWORK_PACKET_MAX_SIZE + 6 673 | // If returns TRUE and packetSize=0 then no data is waiting to be read 674 | // Else packetSize will be what was read with the first 6 bytes being in the following format: 675 | // packetSize will *need* to be NETWORK_PACKET_MAX_SIZE+6 676 | // Byte: 0 High Byte of packet size 677 | // 1: Low Byte of packet size 678 | // 2: 0xA8/A8/0 - magic number. 679 | // 3, 4 = 0 680 | // 5: 0 if this was the last packet, or 0x10 if there are more to read 681 | // last 4 bytes are the CRC for the packet which we dont care about! 682 | LONG SCSIWifi_receiveFrame(SCSIWIFIDevice device, UBYTE* packetBuffer, UWORD* packetSize) { 683 | LSCSIDevice dev = (LSCSIDevice)device; 684 | 685 | switch (dev->scsiMode) { 686 | case 1: // scsi.device mode 687 | SCSI_PREPCMD(dev, SCSI_NETWORK_WIFI_CMD, SCSI_NETWORK_WIFI_OPT_ALTREAD, 0xA8, (*packetSize) >> 8, (*packetSize) & 0xFF, 0); 688 | break; 689 | 690 | case 2: // gvpscsi.device mode 691 | SCSI_PREPCMD(dev, SCSI_NETWORK_WIFI_CMD, SCSI_NETWORK_WIFI_OPT_ALTREAD, 0xA9, (*packetSize) >> 8, (*packetSize) & 0xFF, 0); 692 | break; 693 | 694 | default: 695 | SCSI_PREPCMD(dev, SCSI_NETWORK_WIFI_READFRAME, 0, 0, (*packetSize) >> 8, (*packetSize) & 0xFF, 0); 696 | break; 697 | } 698 | dev->Cmd.scsi_Data = (APTR)packetBuffer; 699 | dev->Cmd.scsi_Length = *packetSize; 700 | dev->Cmd.scsi_Flags = SCSIF_READ | SCSIF_AUTOSENSE; 701 | 702 | DoIO( (struct IORequest*)dev->SCSIReq ); 703 | 704 | if ((dev->Cmd.scsi_Status) || (dev->Cmd.scsi_Actual < 6)) return 0; 705 | 706 | *packetSize = dev->Cmd.scsi_Actual; 707 | 708 | return 1; 709 | } 710 | -------------------------------------------------------------------------------- /licence.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright © 2007 Free Software Foundation, Inc. 5 | 6 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | The GNU General Public License is a free, copyleft license for software and other kinds of works. 10 | 11 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. 12 | 13 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. 14 | 15 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. 16 | 17 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 18 | 19 | Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. 20 | 21 | For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. 22 | 23 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. 24 | 25 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. 26 | 27 | The precise terms and conditions for copying, distribution and modification follow. 28 | 29 | TERMS AND CONDITIONS 30 | 0. Definitions. 31 | “This License” refers to version 3 of the GNU General Public License. 32 | 33 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. 34 | 35 | “The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. 36 | 37 | To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. 38 | 39 | A “covered work” means either the unmodified Program or a work based on the Program. 40 | 41 | To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. 42 | 43 | To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. 44 | 45 | An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 46 | 47 | 1. Source Code. 48 | The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. 49 | 50 | A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. 51 | 52 | The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. 53 | 54 | The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. 55 | 56 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. 57 | 58 | The Corresponding Source for a work in source code form is that same work. 59 | 60 | 2. Basic Permissions. 61 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. 62 | 63 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. 64 | 65 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 66 | 67 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 68 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. 69 | 70 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 71 | 72 | 4. Conveying Verbatim Copies. 73 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. 74 | 75 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 76 | 77 | 5. Conveying Modified Source Versions. 78 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: 79 | 80 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date. 81 | b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. 82 | c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. 83 | d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. 84 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 85 | 86 | 6. Conveying Non-Source Forms. 87 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: 88 | 89 | a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. 90 | b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. 91 | c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. 92 | d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. 93 | e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. 94 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. 95 | 96 | A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. 97 | 98 | “Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. 99 | 100 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). 101 | 102 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. 103 | 104 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 105 | 106 | 7. Additional Terms. 107 | “Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. 108 | 109 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. 110 | 111 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: 112 | 113 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or 114 | b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or 115 | c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or 116 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or 117 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or 118 | f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. 119 | All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. 120 | 121 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. 122 | 123 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 124 | 125 | 8. Termination. 126 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). 127 | 128 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. 129 | 130 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. 131 | 132 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 133 | 134 | 9. Acceptance Not Required for Having Copies. 135 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 136 | 137 | 10. Automatic Licensing of Downstream Recipients. 138 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. 139 | 140 | An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. 141 | 142 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 143 | 144 | 11. Patents. 145 | A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. 146 | 147 | A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. 148 | 149 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. 150 | 151 | In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. 152 | 153 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. 154 | 155 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. 156 | 157 | A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. 158 | 159 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 160 | 161 | 12. No Surrender of Others' Freedom. 162 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 163 | 164 | 13. Use with the GNU Affero General Public License. 165 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 166 | 167 | 14. Revised Versions of this License. 168 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 169 | 170 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. 171 | 172 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. 173 | 174 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 175 | 176 | 15. Disclaimer of Warranty. 177 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 178 | 179 | 16. Limitation of Liability. 180 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 181 | 182 | 17. Interpretation of Sections 15 and 16. 183 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. 184 | 185 | END OF TERMS AND CONDITIONS 186 | 187 | How to Apply These Terms to Your New Programs 188 | If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. 189 | 190 | To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. 191 | 192 | 193 | Copyright (C) 194 | 195 | This program is free software: you can redistribute it and/or modify 196 | it under the terms of the GNU General Public License as published by 197 | the Free Software Foundation, either version 3 of the License, or 198 | (at your option) any later version. 199 | 200 | This program is distributed in the hope that it will be useful, 201 | but WITHOUT ANY WARRANTY; without even the implied warranty of 202 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 203 | GNU General Public License for more details. 204 | 205 | You should have received a copy of the GNU General Public License 206 | along with this program. If not, see . 207 | Also add information on how to contact you by electronic and paper mail. 208 | 209 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: 210 | 211 | Copyright (C) 212 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 213 | This is free software, and you are welcome to redistribute it 214 | under certain conditions; type `show c' for details. 215 | The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. 216 | 217 | You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . 218 | 219 | The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . -------------------------------------------------------------------------------- /device.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SCSI DaynaPORT Device (scsidayna.device) by RobSmithDev 3 | * 4 | * based LARGELY on the MNT ZZ9000 Network Driver 5 | * Copyright (C) 2016-2023, Lukas F. Hartmann 6 | * MNT Research GmbH, Berlin 7 | * https://mntre.com 8 | * 9 | * Based on code copyright (C) 2018 Henryk Richter 10 | * Released under GPLv3+ with permission. 11 | * 12 | * More Info: https://mntre.com/zz9000 13 | * 14 | * SPDX-License-Identifier: GPL-3.0-or-later 15 | * GNU General Public License v3.0 or later 16 | * 17 | * https://spdx.org/licenses/GPL-3.0-or-later.html 18 | */ 19 | 20 | #define DEVICE_MAIN 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include "scsiwifi.h" 40 | #include 41 | #include 42 | #include "debug.h" 43 | 44 | 45 | #ifdef HAVE_VERSION_H 46 | #include "version.h" 47 | #endif 48 | /* NSD support is optional */ 49 | #ifdef NEWSTYLE 50 | #include 51 | #endif /* NEWSTYLE */ 52 | #ifdef DEVICES_NEWSTYLE_H 53 | 54 | const UWORD dev_supportedcmds[] = { 55 | NSCMD_DEVICEQUERY, 56 | CMD_READ, 57 | CMD_WRITE, 58 | /* ... add all cmds here that are supported by BeginIO */ 59 | 0 60 | }; 61 | 62 | const struct NSDeviceQueryResult NSDQueryAnswer = { 63 | 0, 64 | 16, /* up to SupportedCommands (inclusive) TODO: correct number */ 65 | NSDEVTYPE_SANA2, /* TODO: proper device type */ 66 | 0, /* subtype */ 67 | (UWORD*)dev_supportedcmds 68 | }; 69 | #endif /* DEVICES_NEWSTYLE_H */ 70 | 71 | #include "device.h" 72 | #include "macros.h" 73 | 74 | 75 | __saveds void frame_proc(); 76 | char *frame_proc_name = "SCSIDaynaPacketTask"; 77 | 78 | static UBYTE HW_MAC[] = {0x00,0x00,0x00,0x00,0x00,0x00}; 79 | 80 | struct ProcInit 81 | { 82 | struct Message msg; 83 | struct devbase *db; 84 | BOOL error; 85 | UBYTE pad[2]; 86 | }; 87 | 88 | // Free's anything left after init 89 | void freeInit(DEVBASEP) { 90 | if (db->db_scsiSettings) FreeVec(db->db_scsiSettings); 91 | db->db_scsiSettings = NULL; 92 | if (DOSBase) CloseLibrary(DOSBase); 93 | DOSBase = NULL; 94 | if (UtilityBase) CloseLibrary(UtilityBase); 95 | UtilityBase = NULL; 96 | } 97 | 98 | 99 | void DevTermIO( DEVBASEP, struct IORequest *ioreq ); 100 | 101 | __saveds struct Device *DevInit( ASMR(d0) DEVBASEP ASMREG(d0), 102 | ASMR(a0) BPTR seglist ASMREG(a0), 103 | ASMR(a6) struct Library *_SysBase ASMREG(a6) ) { 104 | db->db_SysBase = _SysBase; 105 | db->db_SegList = seglist; 106 | db->db_DOSBase = NULL; 107 | db->db_UtilityBase = NULL; 108 | db->db_scsiSettings = NULL; 109 | db->db_online = 0; 110 | 111 | volatile struct List db_EventList; 112 | struct SignalSemaphore db_EventListSem; 113 | 114 | DOSBase = OpenLibrary("dos.library", 36); 115 | if (!DOSBase) { 116 | D(("scsidayna: Failed to open dos.library (36)\n")); 117 | return 0; 118 | } 119 | 120 | UtilityBase = OpenLibrary("utility.library", 37); 121 | if (!UtilityBase) { 122 | D(("scsidayna: Failed to open utility.library (37)\n")); 123 | freeInit(db); 124 | return 0; 125 | } 126 | 127 | // Load in the settings. Theres a few 128 | db->db_scsiSettings = AllocVec(sizeof(struct ScsiDaynaSettings),MEMF_CLEAR); 129 | if (!db->db_scsiSettings) { 130 | D(("scsidayna: Out of memory (settings)\n")); 131 | freeInit(db); 132 | return 0; 133 | } 134 | struct ScsiDaynaSettings* settings = (struct ScsiDaynaSettings*)db->db_scsiSettings; 135 | 136 | if (SCSIWifi_loadSettings((void*)UtilityBase, (void*)DOSBase, settings)) 137 | D(("scsidayna: settings loaded")); else D(("scsidayna: Invalid or missing settings file, reverting to defaults\n")); 138 | 139 | if (strlen(settings->deviceName)<1) { 140 | D(("scsidayna: SCSI device name not set\n")); 141 | freeInit(db); 142 | return 0; 143 | } 144 | 145 | struct SCSIDevice_OpenData openData; 146 | openData.sysBase = (struct ExecBase*)SysBase; 147 | openData.utilityBase = (void*)UtilityBase; 148 | openData.dosBase = (void*)DOSBase; 149 | openData.deviceDriverName = settings->deviceName; 150 | openData.deviceID = settings->deviceID; 151 | openData.scsiMode = settings->scsiMode; 152 | db->db_scsiMode = settings->scsiMode; 153 | 154 | 155 | enum SCSIWifi_OpenResult scsiResult; 156 | SCSIWIFIDevice* wifiDevice; 157 | 158 | if ((settings->deviceID<0) || (settings->deviceID>7)) { 159 | D(("scsidayna: Searching for DaynaPORT Device to Configure\n")); 160 | // Highly likely it will be on 4 as its in the example so start there! 161 | for (USHORT deviceID=4; deviceID<4+8; deviceID++) { 162 | openData.deviceID = deviceID & 7; 163 | D(("scsidayna: Searching on DeviceID %ld\n", openData.deviceID)); 164 | wifiDevice = SCSIWifi_open(&openData, &scsiResult); 165 | if (wifiDevice) break; 166 | } 167 | } else { 168 | D(("scsidayna: Opening Device to Configure\n")); 169 | openData.deviceID = settings->deviceID; 170 | wifiDevice = SCSIWifi_open(&openData, &scsiResult); 171 | } 172 | if (!wifiDevice) { 173 | switch (scsiResult) { 174 | case sworOpenDeviceFailed: 175 | D(("scsidayna: Failed to open SCSI device \"%s\" ID %ld\n", settings->deviceName, settings->deviceID)); 176 | break; 177 | case sworOutOfMem: D(("scsidayna: Out of memory opening SCSI device\n")); break; 178 | case sworInquireFail: D(("scsidayna: Inquiry of SCSI device failed\n")); break; 179 | case sworNotDaynaDevice: D(("scsidayna: Device is not a DaynaPort SCSI device\n")); break; 180 | } 181 | freeInit(db); 182 | 183 | return 0; 184 | } 185 | db->db_scsiDeviceID = openData.deviceID; 186 | 187 | D(("scsidayna: successfully opened. Fetching MAC\n")); 188 | 189 | // Device open. Fetch MAC address 190 | struct SCSIWifi_MACAddress macAddress; 191 | if (!SCSIWifi_getMACAddress(wifiDevice, &macAddress)) { 192 | D(("scsidayna: Failed to fetch hardware MAC address\n")); 193 | SCSIWifi_close(wifiDevice); 194 | freeInit(db); 195 | return 0; 196 | } 197 | 198 | memcpy(HW_MAC, macAddress.address, 6); 199 | 200 | D(("scsidayna: MAC Address stored, checking WIFI status\n")); 201 | 202 | // Should we be attempting to connect to wifi? 203 | if ((settings->autoConnect) && (strlen(settings->ssid))) { 204 | // Fetch what the current network is 205 | struct SCSIWifi_NetworkEntry currentNetwork; 206 | if (!SCSIWifi_getNetwork(wifiDevice, ¤tNetwork)) memset(¤tNetwork, 0, sizeof(struct SCSIWifi_NetworkEntry)); 207 | if (strcmp(currentNetwork.ssid, settings->ssid) == 0) { 208 | D(("scsidayna: Already connected to requested WIFI network\n")); 209 | } else { 210 | struct SCSIWifi_JoinRequest request; 211 | strcpy(request.ssid, settings->ssid); 212 | strcpy(request.key, settings->key); 213 | SCSIWifi_joinNetwork(wifiDevice, &request); 214 | D(("scsidayna: Attempting to connect to WIFI network\n")); 215 | } 216 | } 217 | 218 | D(("scsidayna: Closing Device\n")); 219 | SCSIWifi_close(wifiDevice); 220 | 221 | D(("scsidayna: Closed\n")); 222 | return (struct Device*)db; 223 | } 224 | 225 | __saveds LONG DevOpen( ASMR(a1) struct IOSana2Req *ioreq ASMREG(a1), 226 | ASMR(d0) ULONG unit ASMREG(d0), 227 | ASMR(d1) ULONG flags ASMREG(d1), 228 | ASMR(a6) DEVBASEP ASMREG(a6) ) 229 | { 230 | LONG ok = 0,ret = IOERR_OPENFAIL; 231 | struct BufferManagement *bm; 232 | 233 | // promiscuous mode not supported 234 | if ((flags & SANA2OPF_PROM) && (unit)) { 235 | ioreq->ios2_Req.io_Error = IOERR_OPENFAIL; 236 | ioreq->ios2_Req.io_Unit = (struct Unit *) 0; 237 | ioreq->ios2_Req.io_Device = (struct Device *) 0; 238 | D(("scsidayna: SANA2OPF_PROM not supported %ld\n",unit)); 239 | return IOERR_OPENFAIL; 240 | } 241 | 242 | D(("scsidayna: DevOpen for %ld\n",unit)); 243 | 244 | db->db_Lib.lib_OpenCnt++; /* avoid Expunge, see below for separate "unit" open count */ 245 | 246 | if (unit==0 && db->db_Lib.lib_OpenCnt==1) { 247 | if ((bm = (struct BufferManagement*)AllocVec(sizeof(struct BufferManagement), MEMF_CLEAR|MEMF_PUBLIC))) { 248 | bm->bm_CopyToBuffer = (BMFunc)GetTagData(S2_CopyToBuff, 0, (struct TagItem *)ioreq->ios2_BufferManagement); 249 | bm->bm_CopyFromBuffer = (BMFunc)GetTagData(S2_CopyFromBuff, 0, (struct TagItem *)ioreq->ios2_BufferManagement); 250 | 251 | ioreq->ios2_BufferManagement = (VOID *)bm; 252 | ioreq->ios2_Req.io_Error = 0; 253 | ioreq->ios2_Req.io_Unit = (struct Unit *)unit; // not a real pointer, but id integer 254 | ioreq->ios2_Req.io_Device = (struct Device *)db; 255 | 256 | NewList(&db->db_ReadList); 257 | InitSemaphore(&db->db_ReadListSem); 258 | 259 | NewList(&db->db_WriteList); 260 | InitSemaphore(&db->db_WriteListSem); 261 | 262 | NewList(&db->db_EventList); 263 | InitSemaphore(&db->db_EventListSem); 264 | 265 | NewList(&db->db_ReadOrphanList); 266 | InitSemaphore(&db->db_ReadOrphanListSem); 267 | 268 | InitSemaphore(&db->db_ProcSem); 269 | db->db_online = 1; 270 | 271 | struct ProcInit init; 272 | struct MsgPort *port; 273 | 274 | if (port = CreateMsgPort()) { 275 | D(("scsidayna: Starting Server\n")); 276 | if (db->db_Proc = CreateNewProcTags(NP_Entry, frame_proc, NP_Name, 277 | frame_proc_name, NP_Priority, 0, TAG_DONE)) { 278 | init.error = 1; 279 | init.db = db; 280 | init.msg.mn_Length = sizeof(init); 281 | init.msg.mn_ReplyPort = port; 282 | 283 | D(("scsidayna: handover db: %lx\n",init.db)); 284 | 285 | PutMsg(&db->db_Proc->pr_MsgPort, (struct Message*)&init); 286 | WaitPort(port); 287 | 288 | if (init.error) { 289 | D(("scsidayna:process startup error\n")); 290 | ret = IOERR_OPENFAIL; 291 | ok = 0; 292 | } else { 293 | ret = 0; 294 | ok = 1; 295 | } 296 | } else { 297 | D(("scsidayna:couldn't create process\n")); 298 | } 299 | DeleteMsgPort(port); 300 | } 301 | } 302 | } 303 | 304 | if (ok) { 305 | D(("scsidayna: OK\n")); 306 | ret = 0; 307 | db->db_Lib.lib_Flags &= ~LIBF_DELEXP; 308 | } 309 | 310 | if (ret == IOERR_OPENFAIL) { 311 | ioreq->ios2_Req.io_Unit = (0); 312 | ioreq->ios2_Req.io_Device = (0); 313 | ioreq->ios2_Req.io_Error = ret; 314 | db->db_Lib.lib_OpenCnt--; 315 | D(("scsidayna: Err\n")); 316 | } 317 | ioreq->ios2_Req.io_Message.mn_Node.ln_Type = NT_REPLYMSG; 318 | 319 | D(("scsidayna: DevOpen return code %ld\n",ret)); 320 | 321 | return ret; 322 | } 323 | 324 | __saveds BPTR DevClose( ASMR(a1) struct IORequest *ioreq ASMREG(a1), 325 | ASMR(a6) DEVBASEP ASMREG(a6) ) 326 | { 327 | /* ULONG unit; */ 328 | BPTR ret = (0); 329 | 330 | D(("scsidayna: DevClose open count %ld\n",db->db_Lib.lib_OpenCnt)); 331 | 332 | if (!ioreq) 333 | return ret; 334 | 335 | db->db_Lib.lib_OpenCnt--; 336 | 337 | if (db->db_Lib.lib_OpenCnt == 0) { 338 | 339 | if (db->db_Proc) { 340 | D(("scsidayna: End Proc...\n")); 341 | Signal((struct Task*)db->db_Proc, SIGBREAKF_CTRL_C); 342 | db->db_Proc = 0; 343 | 344 | ObtainSemaphore(&db->db_ProcSem); 345 | ReleaseSemaphore(&db->db_ProcSem); 346 | } 347 | } 348 | 349 | ioreq->io_Device = (0); 350 | ioreq->io_Unit = (struct Unit *)(-1); 351 | 352 | if (db->db_Lib.lib_Flags & LIBF_DELEXP) 353 | ret = DevExpunge(db); 354 | 355 | return ret; 356 | } 357 | 358 | __saveds BPTR DevExpunge( ASMR(a6) DEVBASEP ASMREG(a6) ) 359 | { 360 | BPTR seglist = db->db_SegList; 361 | 362 | if( db->db_Lib.lib_OpenCnt ) 363 | { 364 | db->db_Lib.lib_Flags |= LIBF_DELEXP; 365 | return (0); 366 | } 367 | 368 | D(("scsidayna: Remove Device Node...\n")); 369 | Remove((struct Node*)db); 370 | 371 | freeInit(db); 372 | FreeMem( ((BYTE*)db)-db->db_Lib.lib_NegSize,(ULONG)(db->db_Lib.lib_PosSize + db->db_Lib.lib_NegSize)); 373 | 374 | return seglist; 375 | } 376 | 377 | __saveds VOID DevBeginIO( ASMR(a1) struct IOSana2Req *ioreq ASMREG(a1), 378 | ASMR(a6) DEVBASEP ASMREG(a6) ) 379 | { 380 | ULONG unit = (ULONG)ioreq->ios2_Req.io_Unit; 381 | int mtu; 382 | 383 | ioreq->ios2_Req.io_Message.mn_Node.ln_Type = NT_MESSAGE; 384 | ioreq->ios2_Req.io_Error = S2ERR_NO_ERROR; 385 | ioreq->ios2_WireError = S2WERR_GENERIC_ERROR; 386 | 387 | //D(("BeginIO command %ld unit %ld\n",(LONG)ioreq->ios2_Req.io_Command,unit)); 388 | 389 | switch( ioreq->ios2_Req.io_Command ) { 390 | case CMD_READ: 391 | if (ioreq->ios2_BufferManagement == NULL) { 392 | ioreq->ios2_Req.io_Error = S2ERR_BAD_ARGUMENT; 393 | ioreq->ios2_WireError = S2WERR_BUFF_ERROR; 394 | } else if (!db->db_currentWifiState) { 395 | ioreq->ios2_Req.io_Error = S2ERR_OUTOFSERVICE; 396 | ioreq->ios2_WireError = S2WERR_UNIT_OFFLINE; 397 | } else { 398 | ioreq->ios2_Req.io_Flags &= ~SANA2IOF_QUICK; 399 | ObtainSemaphore(&db->db_ReadListSem); 400 | AddTail((struct List*)&db->db_ReadList, (struct Node*)ioreq); 401 | ReleaseSemaphore(&db->db_ReadListSem); 402 | ioreq = NULL; 403 | } 404 | break; 405 | 406 | case S2_GETGLOBALSTATS: 407 | memcpy(ioreq->ios2_StatData, &db->db_DevStats, sizeof(struct Sana2DeviceStats)); 408 | break; 409 | 410 | case S2_BROADCAST: 411 | /* set broadcast addr: ff:ff:ff:ff:ff:ff */ 412 | if (ioreq->ios2_DstAddr) { 413 | memset(ioreq->ios2_DstAddr, 0xff, HW_ADDRFIELDSIZE); 414 | } else { 415 | D(("bcast: invalid dst addr\n")); 416 | } 417 | /* fall through */ 418 | case CMD_WRITE: 419 | if (ioreq->ios2_BufferManagement == NULL) { 420 | ioreq->ios2_Req.io_Error = S2ERR_BAD_ARGUMENT; 421 | ioreq->ios2_WireError = S2WERR_BUFF_ERROR; 422 | } 423 | else if (!db->db_currentWifiState) { 424 | ioreq->ios2_Req.io_Error = S2ERR_OUTOFSERVICE; 425 | ioreq->ios2_WireError = S2WERR_UNIT_OFFLINE; 426 | } 427 | else { 428 | ioreq->ios2_Req.io_Flags &= ~SANA2IOF_QUICK; 429 | ioreq->ios2_Req.io_Error = 0; 430 | ObtainSemaphore(&db->db_WriteListSem); 431 | // The sending process reads from the head of the list, 432 | // so add to the tail here, otherwise packets could go out 433 | // in swapped order 434 | AddTail((struct List*)&db->db_WriteList, (struct Node*)ioreq); 435 | ReleaseSemaphore(&db->db_WriteListSem); 436 | Signal((struct Task*)db->db_Proc, SIGBREAKF_CTRL_F); 437 | ioreq = NULL; 438 | } 439 | break; 440 | 441 | case S2_ONEVENT: 442 | if (((ioreq->ios2_WireError & S2EVENT_ONLINE) && (db->db_currentWifiState)) || 443 | ((ioreq->ios2_WireError & S2EVENT_OFFLINE) && (!db->db_currentWifiState))) { 444 | ioreq->ios2_Req.io_Error = 0; 445 | ioreq->ios2_WireError &= (S2EVENT_ONLINE|S2EVENT_OFFLINE); 446 | DevTermIO(db, (struct IORequest*)ioreq); 447 | ioreq = NULL; 448 | } else 449 | if ((ioreq->ios2_WireError & (S2EVENT_ONLINE|S2EVENT_OFFLINE|S2EVENT_ERROR|S2EVENT_TX|S2EVENT_RX|S2EVENT_BUFF|S2EVENT_HARDWARE|S2EVENT_SOFTWARE)) != ioreq->ios2_WireError) 450 | { 451 | /* we cannot handle such events */ 452 | ioreq->ios2_Req.io_Error = S2ERR_NOT_SUPPORTED; 453 | ioreq->ios2_WireError = S2WERR_BAD_EVENT; 454 | } 455 | else 456 | { 457 | /* Queue anything else */ 458 | ioreq->ios2_Req.io_Flags &= ~SANA2IOF_QUICK; 459 | ObtainSemaphore(&db->db_EventListSem); 460 | AddTail((struct List*)&db->db_EventList, (struct Node*)ioreq); 461 | ReleaseSemaphore(&db->db_EventListSem); 462 | ioreq = NULL; 463 | } 464 | break; 465 | 466 | case S2_READORPHAN: 467 | if (ioreq->ios2_BufferManagement == NULL) { 468 | ioreq->ios2_Req.io_Error = S2ERR_BAD_ARGUMENT; 469 | ioreq->ios2_WireError = S2WERR_BUFF_ERROR; 470 | } else if (!db->db_currentWifiState) { 471 | ioreq->ios2_Req.io_Error = S2ERR_OUTOFSERVICE; 472 | ioreq->ios2_WireError = S2WERR_UNIT_OFFLINE; 473 | } else 474 | { 475 | ioreq->ios2_Req.io_Flags &= ~SANA2IOF_QUICK; 476 | ObtainSemaphore(&db->db_ReadOrphanListSem); 477 | AddTail((struct List*)&db->db_ReadOrphanList, (struct Node*)ioreq); 478 | ReleaseSemaphore(&db->db_ReadOrphanListSem); 479 | ioreq = NULL; 480 | } 481 | break; 482 | 483 | case S2_ONLINE: 484 | db->db_online = 1; 485 | break; 486 | 487 | case S2_OFFLINE: 488 | db->db_online = 0; 489 | break; 490 | 491 | case S2_CONFIGINTERFACE: 492 | break; 493 | 494 | case S2_GETSTATIONADDRESS: 495 | memcpy(ioreq->ios2_SrcAddr, HW_MAC, HW_ADDRFIELDSIZE); /* current */ 496 | memcpy(ioreq->ios2_DstAddr, HW_MAC, HW_ADDRFIELDSIZE); /* default */ 497 | break; 498 | case S2_DEVICEQUERY: 499 | { 500 | struct Sana2DeviceQuery *devquery; 501 | 502 | devquery = ioreq->ios2_StatData; 503 | devquery->DevQueryFormat = 0; /* "this is format 0" */ 504 | devquery->DeviceLevel = 0; /* "this spec defines level 0" */ 505 | 506 | if (devquery->SizeAvailable >= 18) devquery->AddrFieldSize = HW_ADDRFIELDSIZE * 8; /* Bits! */ 507 | if (devquery->SizeAvailable >= 22) devquery->MTU = SCSIWIFI_PACKET_MTU_SIZE; 508 | if (devquery->SizeAvailable >= 26) devquery->BPS = 1000*1000*100; // unlikely 509 | if (devquery->SizeAvailable >= 30) devquery->HardwareType = S2WireType_Ethernet; 510 | if (devquery->SizeAvailable >= 34) devquery->RawMTU = SCSIWIFI_PACKET_MAX_SIZE; 511 | 512 | devquery->SizeSupplied = (devquery->SizeAvailable<34?devquery->SizeAvailable:34); 513 | } 514 | break; 515 | case S2_GETSPECIALSTATS: 516 | { 517 | struct Sana2SpecialStatHeader *s2ssh = (struct Sana2SpecialStatHeader *)ioreq->ios2_StatData; 518 | s2ssh->RecordCountSupplied = 0; 519 | } 520 | break; 521 | // Todo: Add S2_ADDMULTICASTADDRESS 522 | default: 523 | { 524 | ioreq->ios2_Req.io_Error = S2ERR_NOT_SUPPORTED; 525 | ioreq->ios2_WireError = S2WERR_GENERIC_ERROR; 526 | break; 527 | } 528 | } 529 | 530 | if (ioreq) { 531 | DevTermIO(db, (struct IORequest*)ioreq); 532 | } 533 | } 534 | 535 | /* 536 | ** SANA-2 Event management 537 | */ 538 | void DoEvent(DEVBASEP, long event) 539 | { 540 | struct IOSana2Req *ior, *ior2; 541 | 542 | D(("event is %lx\n",event)); 543 | 544 | ObtainSemaphore(&db->db_EventListSem ); 545 | 546 | for(ior = (struct IOSana2Req *) db->db_EventList.lh_Head; (ior2 = (struct IOSana2Req *) ior->ios2_Req.io_Message.mn_Node.ln_Succ) != NULL; ior = ior2 ) 547 | { 548 | if (ior->ios2_WireError & event) 549 | { 550 | Remove((struct Node*)ior); 551 | DevTermIO(db, (struct IORequest *)ior); 552 | } 553 | } 554 | 555 | ReleaseSemaphore(&db->db_EventListSem ); 556 | } 557 | 558 | __saveds LONG DevAbortIO( ASMR(a1) struct IORequest *ioreq ASMREG(a1), 559 | ASMR(a6) DEVBASEP ASMREG(a6) ) 560 | { 561 | LONG ret = 0; 562 | struct IOSana2Req* ios2 = (struct IOSana2Req*)ioreq; 563 | 564 | D(("scsidayna: AbortIO on %lx\n",(ULONG)ioreq)); 565 | 566 | Remove((struct Node*)ioreq); 567 | 568 | ioreq->io_Error = IOERR_ABORTED; 569 | ios2->ios2_WireError = 0; 570 | 571 | ReplyMsg((struct Message*)ioreq); 572 | return ret; 573 | } 574 | 575 | void DevTermIO( DEVBASEP, struct IORequest *ioreq ) 576 | { 577 | struct IOSana2Req* ios2 = (struct IOSana2Req*)ioreq; 578 | 579 | if (!(ios2->ios2_Req.io_Flags & SANA2IOF_QUICK)) { 580 | ReplyMsg((struct Message *)ioreq); 581 | } else { 582 | ioreq->io_Message.mn_Node.ln_Type = NT_REPLYMSG; 583 | } 584 | } 585 | 586 | 587 | ULONG write_frame(struct IOSana2Req *req, UBYTE* frame, SCSIWIFIDevice scsiDevice, DEVBASEP) 588 | { 589 | ULONG rc=0; 590 | struct BufferManagement *bm; 591 | USHORT sz=0; 592 | UBYTE* inputFrame = frame; 593 | 594 | if (req->ios2_Req.io_Flags & SANA2IOF_RAW) { 595 | sz = req->ios2_DataLength; 596 | } else { 597 | sz = req->ios2_DataLength + HW_ETH_HDR_SIZE; 598 | *((USHORT*)(frame+6+6)) = (USHORT)req->ios2_PacketType; 599 | memcpy(frame, req->ios2_DstAddr, HW_ADDRFIELDSIZE); 600 | memcpy(frame+6, HW_MAC, HW_ADDRFIELDSIZE); 601 | frame+=HW_ETH_HDR_SIZE; 602 | } 603 | 604 | if (sz>0) { 605 | bm = (struct BufferManagement *)req->ios2_BufferManagement; 606 | 607 | if (!(*bm->bm_CopyFromBuffer)(frame, req->ios2_Data, req->ios2_DataLength)) { 608 | rc = 0; 609 | req->ios2_Req.io_Error = S2ERR_SOFTWARE; 610 | req->ios2_WireError = S2WERR_BUFF_ERROR; 611 | DoEvent(db, S2EVENT_ERROR | S2EVENT_BUFF | S2EVENT_SOFTWARE); 612 | D(("bm_CopyFromBuffer FAIL")); 613 | } 614 | else { 615 | // buffer was 616 | if (SCSIWifi_sendFrame(scsiDevice, inputFrame, sz)) { 617 | rc = 1; 618 | //if (req->ios2_Req.io_Flags & SANA2IOF_RAW) D(("FRAME RAW SENT %ld bytes", sz)); else D(("FRAME SENT %ld bytes", sz)); 619 | req->ios2_Req.io_Error = req->ios2_WireError = 0; 620 | db->db_DevStats.PacketsSent++; 621 | } else { 622 | rc = 0; 623 | req->ios2_Req.io_Error = S2ERR_TX_FAILURE; 624 | req->ios2_WireError = S2WERR_GENERIC_ERROR; 625 | DoEvent(db, S2EVENT_ERROR | S2EVENT_TX | S2EVENT_HARDWARE); 626 | D(("SEND FAIL")); 627 | } 628 | } 629 | } else { 630 | D(("no size")); 631 | } 632 | 633 | return rc; 634 | } 635 | 636 | ULONG read_frame(DEVBASEP, struct IOSana2Req *req, UBYTE *frm, USHORT packetSize) 637 | { 638 | ULONG datasize; 639 | BYTE *frame_ptr; 640 | BOOL broadcast; 641 | ULONG res = 0; 642 | struct BufferManagement *bm; 643 | 644 | // This length includes 4 bytes for the CRC at the end, but we dont need that 645 | ULONG sz = ((ULONG)frm[0]<<8)|((ULONG)frm[1]); 646 | if (sz<4) return 1; 647 | sz -= 4; 648 | 649 | req->ios2_PacketType = ((USHORT)frm[12+6]<<8)|((USHORT)frm[13+6]); 650 | 651 | if (req->ios2_Req.io_Flags & SANA2IOF_RAW) { 652 | frame_ptr = frm+6; 653 | datasize = sz; 654 | req->ios2_Req.io_Flags = SANA2IOF_RAW; 655 | } 656 | else { 657 | frame_ptr = frm+6+HW_ETH_HDR_SIZE; 658 | datasize = sz-HW_ETH_HDR_SIZE; 659 | req->ios2_Req.io_Flags = 0; 660 | } 661 | 662 | req->ios2_DataLength = datasize; 663 | 664 | // copy frame to device user (probably tcp/ip system) 665 | bm = (struct BufferManagement *)req->ios2_BufferManagement; 666 | if (!(*bm->bm_CopyToBuffer)(req->ios2_Data, frame_ptr, datasize)) { 667 | req->ios2_Req.io_Error = S2ERR_SOFTWARE; 668 | req->ios2_WireError = S2WERR_BUFF_ERROR; 669 | DoEvent(db, S2EVENT_ERROR | S2EVENT_BUFF | S2EVENT_SOFTWARE); 670 | res = 0; 671 | } 672 | else { 673 | req->ios2_Req.io_Error = req->ios2_WireError = 0; 674 | res = 1; 675 | } 676 | 677 | memcpy(req->ios2_SrcAddr, frm+6+6, HW_ADDRFIELDSIZE); 678 | memcpy(req->ios2_DstAddr, frm+6, HW_ADDRFIELDSIZE); 679 | 680 | 681 | broadcast = TRUE; 682 | for (int i=0; iios2_Req.io_Flags |= SANA2IOF_BCAST; 690 | } 691 | return res; 692 | } 693 | 694 | 695 | void rejectAllPackets(DEVBASEP) { 696 | struct IOSana2Req *ior; 697 | 698 | D(("Reject all Packets\n")); 699 | 700 | ObtainSemaphore(&db->db_WriteListSem); 701 | for (ior = (struct IOSana2Req *)db->db_WriteList.lh_Head; ior->ios2_Req.io_Message.mn_Node.ln_Succ; ior = (struct IOSana2Req *)ior->ios2_Req.io_Message.mn_Node.ln_Succ) { 702 | ior->ios2_Req.io_Error = S2ERR_OUTOFSERVICE; 703 | ior->ios2_WireError = S2WERR_UNIT_OFFLINE; 704 | Remove((struct Node*)ior); 705 | DevTermIO(db, (struct IORequest*)ior); 706 | } 707 | ReleaseSemaphore(&db->db_WriteListSem); 708 | 709 | ObtainSemaphore(&db->db_ReadListSem); 710 | for (ior = (struct IOSana2Req *)db->db_ReadList.lh_Head; ior->ios2_Req.io_Message.mn_Node.ln_Succ; ior = (struct IOSana2Req *)ior->ios2_Req.io_Message.mn_Node.ln_Succ) { 711 | ior->ios2_Req.io_Error = S2ERR_OUTOFSERVICE; 712 | ior->ios2_WireError = S2WERR_UNIT_OFFLINE; 713 | Remove((struct Node*)ior); 714 | DevTermIO(db, (struct IORequest*)ior); 715 | } 716 | ReleaseSemaphore(&db->db_ReadListSem); 717 | 718 | ObtainSemaphore(&db->db_ReadOrphanListSem); 719 | for (ior = (struct IOSana2Req *)db->db_ReadOrphanList.lh_Head; ior->ios2_Req.io_Message.mn_Node.ln_Succ; ior = (struct IOSana2Req *)ior->ios2_Req.io_Message.mn_Node.ln_Succ) { 720 | ior->ios2_Req.io_Error = S2ERR_OUTOFSERVICE; 721 | ior->ios2_WireError = S2WERR_UNIT_OFFLINE; 722 | Remove((struct Node*)ior); 723 | DevTermIO(db, (struct IORequest*)ior); 724 | } 725 | ReleaseSemaphore(&db->db_ReadOrphanListSem); 726 | 727 | D(("Reject all Packets done\n")); 728 | } 729 | 730 | // This runs as a separate task! 731 | __saveds void frame_proc() { 732 | D(("scsidayna_task: frame_proc()\n")); 733 | 734 | struct ProcInit* init; 735 | { 736 | struct { void *db_SysBase; } *db = (void*)0x4; 737 | struct Process* proc; 738 | 739 | proc = (struct Process*)FindTask(NULL); 740 | WaitPort(&proc->pr_MsgPort); 741 | init = (struct ProcInit*)GetMsg(&proc->pr_MsgPort); 742 | } 743 | 744 | struct devbase* db = init->db; 745 | // This semaphore must be obtained by this process before it replies its init message, and then 746 | // hold it for its entire lifetime, otherwise the process exit won't be arbitrated properly. 747 | ObtainSemaphore(&db->db_ProcSem); 748 | 749 | // Need to open a seperate connection to the SCSI device, This has the advantage that it can communicate at the same time! 750 | 751 | struct ScsiDaynaSettings* settings = (struct ScsiDaynaSettings*)db->db_scsiSettings; 752 | struct SCSIDevice_OpenData openData; 753 | openData.sysBase = (struct ExecBase*)SysBase; 754 | openData.utilityBase = (void*)UtilityBase; 755 | openData.dosBase = (void*)DOSBase; 756 | openData.deviceDriverName = settings->deviceName; 757 | openData.deviceID = db->db_scsiDeviceID; 758 | openData.scsiMode = db->db_scsiMode; 759 | 760 | D(("Opening with scsimode %ld", openData.scsiMode)); 761 | 762 | enum SCSIWifi_OpenResult scsiResult; 763 | SCSIWIFIDevice scsiDevice = SCSIWifi_open(&openData, &scsiResult); 764 | 765 | char* packetData = AllocVec(SCSIWIFI_PACKET_MAX_SIZE + 6, MEMF_PUBLIC); 766 | struct MsgPort timerPort; 767 | timerPort.mp_Node.ln_Pri = 0; 768 | timerPort.mp_SigBit = AllocSignal(-1); 769 | timerPort.mp_SigTask = (struct Task *)FindTask(0); 770 | NewList(&timerPort.mp_MsgList); 771 | 772 | LONG errorDevOpen = 0; 773 | struct timerequest* time_req = NULL; 774 | 775 | if (((char)timerPort.mp_SigBit)>=0) { 776 | time_req = (struct timerequest*) CreateIORequest(&timerPort, sizeof (struct timerequest)); 777 | if (time_req) errorDevOpen = OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)time_req, 0); 778 | } 779 | 780 | if ((!scsiDevice) || (!packetData) || (errorDevOpen !=0) || (((char)timerPort.mp_SigBit) < 0) || (!time_req) ) { 781 | init->error = 1; 782 | if (errorDevOpen != 0) D(("scsidayna_task: Out of memory [3]\n")); else CloseDevice((struct IORequest *)time_req); 783 | if (!packetData) D(("scsidayna_task: Out of memory [1]\n")); else FreeVec(packetData); 784 | if (!time_req) D(("scsidayna_task: Out of memory [2]\n")); else DeleteIORequest((struct IORequest *)time_req); 785 | 786 | switch (scsiResult) { 787 | case sworOpenDeviceFailed: D(("scsidayna_task: Failed to open SCSI device \"%s\" ID %d\n", settings->deviceName, settings->deviceID)); break; 788 | case sworOutOfMem: D(("scsidayna_task: Out of memory opening SCSI device\n")); break; 789 | case sworInquireFail: D(("scsidayna_task: Inquiry of SCSI device failed\n")); break; 790 | case sworNotDaynaDevice: D(("scsidayna_task: Device is not a DaynaPort SCSI device\n")); break; 791 | } 792 | 793 | if (((char)timerPort.mp_SigBit)>=0) FreeSignal(timerPort.mp_SigBit); 794 | ReplyMsg((struct Message*)init); 795 | Forbid(); 796 | ReleaseSemaphore(&db->db_ProcSem); 797 | D(("scsidayna_task: shutdown\n")); 798 | return; 799 | } 800 | 801 | // Helpful! 802 | struct Library *TimerBase = (APTR) time_req->tr_node.io_Device; 803 | 804 | init->error = 0; 805 | ReplyMsg((struct Message*)init); 806 | 807 | unsigned long timerSignalMask = (1UL << timerPort.mp_SigBit); 808 | 809 | time_req->tr_node.io_Command = TR_ADDREQUEST; 810 | time_req->tr_time.tv_secs = 0; 811 | 812 | ULONG recv = 0; 813 | USHORT currentWifiState = 0; 814 | 815 | if (settings->taskPriority != 0) 816 | SetTaskPri((struct Task*)db->db_Proc,settings->taskPriority); 817 | 818 | struct timeval timeLastWifiCheck = {0UL,0UL}; 819 | struct timeval timeWifiCheck = {0UL,0UL}; 820 | USHORT lastWifiStatus = 1; // assume OK, although this should get overwritten straight away 821 | 822 | D(("scsidayna_task: starting loop 1.0\n")); 823 | while (!(recv & SIGBREAKF_CTRL_C)) { 824 | struct IOSana2Req *ior = NULL, *nextwrite; 825 | USHORT shouldBeEnabled = db->db_online; 826 | 827 | GetSysTime(&timeWifiCheck); 828 | // Every 5 seconds check WIFI status 829 | if (abs(timeWifiCheck.tv_secs-timeLastWifiCheck.tv_secs)>=5) { 830 | struct SCSIWifi_NetworkEntry wifi; 831 | if (SCSIWifi_getNetwork(scsiDevice, &wifi)) { 832 | if (wifi.rssi == 0) { 833 | D(("scsidayna_task: WIFI not connected\n")); 834 | lastWifiStatus = 0; 835 | } else { 836 | lastWifiStatus = 1; 837 | D(("scsidayna_task: WIFI connected with strength %ld dB\n", wifi.rssi)); 838 | } 839 | } 840 | timeLastWifiCheck.tv_secs = timeWifiCheck.tv_secs; 841 | } 842 | if (!lastWifiStatus) shouldBeEnabled = 0; 843 | 844 | // Handle state toggle - also goes offline if theres no connections 845 | if (currentWifiState != shouldBeEnabled) { 846 | currentWifiState = shouldBeEnabled; 847 | SCSIWifi_enable(scsiDevice, shouldBeEnabled); 848 | if (!shouldBeEnabled) rejectAllPackets(db); 849 | if (shouldBeEnabled) GetSysTime(&db->db_DevStats.LastStart); 850 | DoEvent(db, shouldBeEnabled ? S2EVENT_ONLINE : S2EVENT_OFFLINE); 851 | db->db_currentWifiState = currentWifiState; 852 | } 853 | 854 | if (currentWifiState) { 855 | UBYTE morePackets = 0; 856 | USHORT counter = 0; 857 | do { 858 | USHORT packetSize = SCSIWIFI_PACKET_MAX_SIZE + 6; 859 | if (SCSIWifi_receiveFrame(scsiDevice, packetData, &packetSize)) { 860 | morePackets = packetData[5]; 861 | db->db_DevStats.PacketsReceived++; 862 | 863 | if (packetSize > 6) { 864 | USHORT packet_type = ((USHORT)packetData[18]<<8)|((USHORT)packetData[19]); 865 | 866 | ObtainSemaphore(&db->db_ReadListSem); 867 | for (ior = (struct IOSana2Req *)db->db_ReadList.lh_Head; ior->ios2_Req.io_Message.mn_Node.ln_Succ; ior = (struct IOSana2Req *)ior->ios2_Req.io_Message.mn_Node.ln_Succ) { 868 | if (ior->ios2_PacketType == packet_type) { 869 | Remove((struct Node*)ior); 870 | read_frame(db, ior, packetData, packetSize); 871 | DevTermIO(db, (struct IORequest *)ior); 872 | counter++; 873 | ior = NULL; 874 | break; 875 | } 876 | } 877 | ReleaseSemaphore(&db->db_ReadListSem); 878 | 879 | // Nothing wanted it? 880 | if (ior) { 881 | db->db_DevStats.UnknownTypesReceived++; 882 | ObtainSemaphore(&db->db_ReadOrphanListSem); 883 | ior = (struct IOSana2Req *)RemHead((struct List*)&db->db_ReadOrphanList); 884 | ReleaseSemaphore(&db->db_ReadOrphanListSem); 885 | if (ior) { 886 | read_frame(db, ior, packetData, packetSize); 887 | DevTermIO(db, (struct IORequest *)ior); 888 | D(("Orphan Packet Picked Up (proto %lx) !\n", packet_type)); 889 | } 890 | } 891 | } 892 | } else { 893 | morePackets = 0; 894 | D(("RECV FAILED\n")); 895 | DoEvent(db, S2EVENT_ERROR | S2EVENT_HARDWARE | S2EVENT_RX); 896 | } 897 | recv = SetSignal(0, SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_F); 898 | // Keep going until we're told theres no more data, or we need to send, or terminate 899 | } while ((morePackets) && (!recv)); 900 | 901 | // Prevent delaying if there was data incoming 902 | if (counter >=2 ) morePackets = 1; 903 | 904 | // Send packets 905 | ObtainSemaphore(&db->db_WriteListSem); 906 | counter = 8; // Max of 8 per loop 907 | for(ior = (struct IOSana2Req *)db->db_WriteList.lh_Head; (nextwrite = (struct IOSana2Req *) ior->ios2_Req.io_Message.mn_Node.ln_Succ) != NULL; ior = nextwrite ) { 908 | ULONG res = write_frame(ior, packetData, scsiDevice, db); 909 | Remove((struct Node*)ior); 910 | DevTermIO(db, (struct IORequest *)ior); 911 | morePackets=1; 912 | counter--; 913 | if (!counter) break; 914 | } 915 | ReleaseSemaphore(&db->db_WriteListSem); 916 | 917 | if (recv & SIGBREAKF_CTRL_C) { 918 | D(("Terminate Requested")); 919 | } else { 920 | if (!morePackets) { 921 | // we use unit VBLANK therefore the granularity of our wait will be 1/50th (1/60th) 922 | // of a second. So essentially this will wait until the next vblank, unless 923 | // signaled, which is good enough to yield. 924 | time_req->tr_time.tv_micro = 1L; 925 | SendIO((struct IORequest *)time_req); 926 | recv = Wait(SIGBREAKF_CTRL_C | timerSignalMask | SIGBREAKF_CTRL_F); 927 | } 928 | } 929 | } else { 930 | // Not enabled? Pause for a decent amount of time 931 | time_req->tr_time.tv_micro = 250 * 1000L; 932 | SendIO((struct IORequest *)time_req); 933 | recv = Wait(SIGBREAKF_CTRL_C | timerSignalMask | SIGBREAKF_CTRL_F); 934 | AbortIO((struct IORequest *)time_req); 935 | } 936 | } 937 | 938 | SCSIWifi_enable(scsiDevice, 0); 939 | DoEvent(db, S2EVENT_OFFLINE); 940 | rejectAllPackets(db); 941 | FreeVec(packetData); 942 | CloseDevice((struct IORequest *)time_req); 943 | DeleteIORequest((struct IORequest *)time_req); 944 | FreeSignal(timerPort.mp_SigBit); 945 | SCSIWifi_close(scsiDevice); 946 | 947 | Forbid(); 948 | ReleaseSemaphore(&db->db_ProcSem); 949 | D(("scsidayna_task: shutdown\n")); 950 | } 951 | --------------------------------------------------------------------------------