wnaspi32: Win64 printf format warning fixes.
[wine] / dlls / wnaspi32 / winaspi32.c
1 /*
2  * Copyright 1997 Bruce Milner
3  * Copyright 1998 Andreas Mohr
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include "config.h"
21
22 #include <assert.h>
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <sys/types.h>
27 #include <errno.h>
28 #include <fcntl.h>
29 #include <string.h>
30 #ifdef HAVE_UNISTD_H
31 # include <unistd.h>
32 #endif
33
34 #include "windef.h"
35 #include "winbase.h"
36 #include "aspi.h"
37 #include "wnaspi32.h"
38 #include "winescsi.h"
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(aspi);
42
43 /* FIXME!
44  * 1) Residual byte length reporting not handled
45  * 2) Make this code re-entrant for multithreading
46  *    -- Added CriticalSection to OpenDevices function
47  * 3) Only linux supported so far
48  * 4) Leaves sg devices open. This may or may not be okay.  A better solution
49  *    would be to close the file descriptors when the thread/process using
50  *    them no longer needs them.
51  */
52
53 #ifdef linux
54
55 static ASPI_DEVICE_INFO *ASPI_open_devices = NULL;
56
57 static CRITICAL_SECTION ASPI_CritSection;
58 static CRITICAL_SECTION_DEBUG critsect_debug =
59 {
60     0, 0, &ASPI_CritSection,
61     { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
62       0, 0, { (DWORD_PTR)(__FILE__ ": ASPI_CritSection") }
63 };
64 static CRITICAL_SECTION ASPI_CritSection = { &critsect_debug, -1, 0, 0, 0, 0 };
65
66 #endif /* defined(linux) */
67
68
69 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
70 {
71 #ifdef linux
72         switch( fdwReason )
73         {
74         case DLL_PROCESS_ATTACH:
75             DisableThreadLibraryCalls(hInstDLL);
76             SCSI_Init();
77             break;
78         case DLL_PROCESS_DETACH:
79             DeleteCriticalSection( &ASPI_CritSection );
80             break;
81         }
82 #endif /* defined(linux) */
83         return TRUE;
84 }
85
86
87 #ifdef linux
88
89 static int
90 ASPI_OpenDevice(SRB_ExecSCSICmd *prb)
91 {
92     int fd;
93     DWORD       hc;
94     ASPI_DEVICE_INFO *curr;
95
96     /* search list of devices to see if we've opened it already.
97      * There is not an explicit open/close in ASPI land, so hopefully
98      * keeping a device open won't be a problem.
99      */
100
101     EnterCriticalSection(&ASPI_CritSection);
102     for (curr = ASPI_open_devices; curr; curr = curr->next) {
103         if (curr->hostId == prb->SRB_HaId &&
104             curr->target == prb->SRB_Target &&
105             curr->lun == prb->SRB_Lun) {
106             LeaveCriticalSection(&ASPI_CritSection);
107             return curr->fd;
108         }
109     }
110     LeaveCriticalSection(&ASPI_CritSection);
111
112     if (prb->SRB_HaId > ASPI_GetNumControllers())
113         return -1;
114
115     hc = ASPI_GetHCforController( prb->SRB_HaId );
116     fd = SCSI_OpenDevice( HIWORD(hc), LOWORD(hc), prb->SRB_Target, prb->SRB_Lun);
117
118     if (fd == -1)
119         return -1;
120
121     /* device is now open */
122     /* FIXME: Let users specify SCSI timeout in registry */
123     SCSI_LinuxSetTimeout( fd, SCSI_DEFAULT_TIMEOUT );
124
125     curr = HeapAlloc( GetProcessHeap(), 0, sizeof(ASPI_DEVICE_INFO) );
126     curr->fd = fd;
127     curr->hostId = prb->SRB_HaId;
128     curr->target = prb->SRB_Target;
129     curr->lun = prb->SRB_Lun;
130
131     /* insert new record at beginning of open device list */
132     EnterCriticalSection(&ASPI_CritSection);
133     curr->next = ASPI_open_devices;
134     ASPI_open_devices = curr;
135     LeaveCriticalSection(&ASPI_CritSection);
136     return fd;
137 }
138
139
140 static void
141 ASPI_DebugPrintCmd(SRB_ExecSCSICmd *prb)
142 {
143   BYTE  cmd;
144   int   i;
145   BYTE *cdb;
146
147   switch (prb->CDBByte[0]) {
148   case CMD_INQUIRY:
149     TRACE("INQUIRY {\n");
150     TRACE("\tEVPD: %d\n", prb->CDBByte[1] & 1);
151     TRACE("\tLUN: %d\n", (prb->CDBByte[1] & 0xc) >> 1);
152     TRACE("\tPAGE CODE: %d\n", prb->CDBByte[2]);
153     TRACE("\tALLOCATION LENGTH: %d\n", prb->CDBByte[4]);
154     TRACE("\tCONTROL: %d\n", prb->CDBByte[5]);
155     TRACE("}\n");
156     break;
157   case CMD_SCAN_SCAN:
158     TRACE("Transfer Length: %d\n", prb->CDBByte[4]);
159     break;
160   }
161
162   TRACE("Host Adapter: %d\n", prb->SRB_HaId);
163   TRACE("Flags: %d\n", prb->SRB_Flags);
164   if (TARGET_TO_HOST(prb)) {
165     TRACE("\tData transfer: Target to host. Length checked.\n");
166   }
167   else if (HOST_TO_TARGET(prb)) {
168     TRACE("\tData transfer: Host to target. Length checked.\n");
169   }
170   else if (NO_DATA_TRANSFERRED(prb)) {
171     TRACE("\tData transfer: none\n");
172   }
173   else {
174     WARN("\tTransfer by scsi cmd. Length not checked.\n");
175   }
176
177   TRACE("\tResidual byte length reporting %s\n", prb->SRB_Flags & 0x4 ? "enabled" : "disabled");
178   TRACE("\tLinking %s\n", prb->SRB_Flags & 0x2 ? "enabled" : "disabled");
179   TRACE("\tPosting %s\n", prb->SRB_Flags & 0x1 ? "enabled" : "disabled");
180   TRACE("Target: %d\n", prb->SRB_Target);
181   TRACE("Lun: %d\n", prb->SRB_Lun);
182   TRACE("BufLen: %d\n", prb->SRB_BufLen);
183   TRACE("SenseLen: %d\n", prb->SRB_SenseLen);
184   TRACE("BufPtr: %p\n", prb->SRB_BufPointer);
185   TRACE("CDB Length: %d\n", prb->SRB_CDBLen);
186   TRACE("POST Proc: %p\n", prb->SRB_PostProc);
187   cdb = &prb->CDBByte[0];
188   cmd = prb->CDBByte[0];
189   if (TRACE_ON(aspi)) {
190       TRACE("CDB buffer[");
191       for (i = 0; i < prb->SRB_CDBLen; i++) {
192           if (i != 0) TRACE(",");
193           TRACE("%02x", *cdb++);
194       }
195       TRACE("]\n");
196   }
197 }
198
199 static void
200 ASPI_PrintCDBArea(SRB_ExecSCSICmd *prb)
201 {
202     if (TRACE_ON(aspi))
203     {
204         int i;
205         TRACE("CDB[");
206         for (i = 0; i < prb->SRB_CDBLen; i++) {
207             if (i) TRACE(",");
208             TRACE("%02x", prb->CDBByte[i]);
209         }
210         TRACE("]\n");
211     }
212 }
213
214 static void
215 ASPI_PrintSenseArea(SRB_ExecSCSICmd *prb)
216 {
217   int   i;
218   BYTE  *rqbuf = prb->SenseArea;
219
220   if (TRACE_ON(aspi))
221   {
222       TRACE("Request Sense reports:\n");
223       if ((rqbuf[0]&0x7f)!=0x70) {
224               TRACE("\tInvalid sense header: 0x%02x instead of 0x70\n", rqbuf[0]&0x7f);
225               return;
226       }
227       TRACE("\tCurrent command read filemark: %s\n",(rqbuf[2]&0x80)?"yes":"no");
228       TRACE("\tEarly warning passed: %s\n",(rqbuf[2]&0x40)?"yes":"no");
229       TRACE("\tIncorrect blocklength: %s\n",(rqbuf[2]&0x20)?"yes":"no");
230       TRACE("\tSense Key: %d\n",rqbuf[2]&0xf);
231       if (rqbuf[0]&0x80)
232         TRACE("\tResidual Length: %d\n",rqbuf[3]*0x1000000+rqbuf[4]*0x10000+rqbuf[5]*0x100+rqbuf[6]);
233       TRACE("\tAdditional Sense Length: %d\n",rqbuf[7]);
234       TRACE("\tAdditional Sense Code: %d\n",rqbuf[12]);
235       TRACE("\tAdditional Sense Code Qualifier: %d\n",rqbuf[13]);
236       if (rqbuf[15]&0x80) {
237         TRACE("\tIllegal Param is in %s\n",(rqbuf[15]&0x40)?"the CDB":"the Data Out Phase");
238         if (rqbuf[15]&0x8) {
239           TRACE("Pointer at %d, bit %d\n",rqbuf[16]*256+rqbuf[17],rqbuf[15]&0x7);
240         }
241       }
242       TRACE("SenseArea[");
243       for (i = 0; i < prb->SRB_SenseLen; i++) {
244         if (i) TRACE(",");
245         TRACE("%02x", *rqbuf++);
246       }
247       TRACE("]\n");
248   }
249 }
250
251 static void
252 ASPI_DebugPrintResult(SRB_ExecSCSICmd *prb)
253 {
254
255   TRACE("SRB_Status: %x\n", prb->SRB_Status);
256   TRACE("SRB_HaStat: %x\n", prb->SRB_HaStat);
257   TRACE("SRB_TargStat: %x\n", prb->SRB_TargStat);
258   switch (prb->CDBByte[0]) {
259   case CMD_INQUIRY:
260     TRACE("Vendor: '%s'\n", prb->SRB_BufPointer + INQUIRY_VENDOR);
261     break;
262   case CMD_TEST_UNIT_READY:
263     ASPI_PrintSenseArea(prb);
264     break;
265   }
266 }
267
268 /* Posting must be done in such a way that as soon as the SRB_Status is set
269  * we don't touch the SRB anymore because it could possibly be freed
270  * if the app is doing ASPI polling
271  */
272 static DWORD
273 WNASPI32_DoPosting( SRB_ExecSCSICmd *lpPRB, DWORD status )
274 {
275         void (*SRB_PostProc)() = lpPRB->SRB_PostProc;
276         BYTE SRB_Flags = lpPRB->SRB_Flags;
277         if( status == SS_PENDING )
278         {
279                 WARN("Tried posting SS_PENDING\n");
280                 return SS_PENDING;
281         }
282         lpPRB->SRB_Status = status;
283         /* lpPRB is NOT safe, it could be freed in another thread */
284
285         if (SRB_PostProc)
286         {
287                 if (SRB_Flags & 0x1)
288                 {
289                         TRACE("Post Routine (%p) called\n", SRB_PostProc);
290                         /* Even though lpPRB could have been freed by
291                          * the program.. that's unlikely if it planned
292                          * to use it in the PostProc
293                          */
294                         (*SRB_PostProc)(lpPRB);
295                 }
296                 else if (SRB_Flags & SRB_EVENT_NOTIFY) {
297                         TRACE("Setting event %p\n", (HANDLE)SRB_PostProc);
298                         SetEvent((HANDLE)SRB_PostProc);
299                 }
300         }
301         return SS_PENDING;
302 }
303
304 static WORD
305 ASPI_ExecScsiCmd(SRB_ExecSCSICmd *lpPRB)
306 {
307   struct sg_header *sg_hd, *sg_reply_hdr;
308   WORD ret;
309   DWORD status;
310   int   in_len, out_len;
311   int   error_code = 0;
312   int   fd;
313   DWORD SRB_Status;
314
315   /* FIXME: hackmode */
316 #define MAKE_TARGET_TO_HOST(lpPRB) \
317         if (!TARGET_TO_HOST(lpPRB)) { \
318             WARN("program was not sending target_to_host for cmd %x (flags=%x),correcting.\n",lpPRB->CDBByte[0],lpPRB->SRB_Flags); \
319             lpPRB->SRB_Flags |= 0x08; \
320         }
321 #define MAKE_HOST_TO_TARGET(lpPRB) \
322         if (!HOST_TO_TARGET(lpPRB)) { \
323             WARN("program was not sending host_to_target for cmd %x (flags=%x),correcting.\n",lpPRB->CDBByte[0],lpPRB->SRB_Flags); \
324             lpPRB->SRB_Flags |= 0x10; \
325         }
326   switch (lpPRB->CDBByte[0]) {
327   case 0x12: /* INQUIRY */
328   case 0x5a: /* MODE_SENSE_10 */
329   case 0xa4: /* REPORT_KEY (DVD) MMC-2 */
330   case 0xad: /* READ DVD STRUCTURE MMC-2 */
331         MAKE_TARGET_TO_HOST(lpPRB)
332         break;
333   case 0xa3: /* SEND KEY (DVD) MMC-2 */
334         MAKE_HOST_TO_TARGET(lpPRB)
335         break;
336   default:
337         if ((((lpPRB->SRB_Flags & 0x18) == 0x00) ||
338              ((lpPRB->SRB_Flags & 0x18) == 0x18)
339             ) && lpPRB->SRB_BufLen
340         ) {
341             FIXME("command 0x%02x, no data transfer specified, but buflen is %d!!!\n",lpPRB->CDBByte[0],lpPRB->SRB_BufLen);
342         }
343         break;
344   }
345   ASPI_DebugPrintCmd(lpPRB);
346   if (lpPRB->SRB_HaId > ASPI_GetNumControllers()) {
347       ERR("Failed: Wanted hostadapter %d, but we have only %d.\n",
348           lpPRB->SRB_HaId,ASPI_GetNumControllers()
349       );
350       return WNASPI32_DoPosting( lpPRB, SS_INVALID_HA );
351   }
352   fd = ASPI_OpenDevice(lpPRB);
353   if (fd == -1) {
354       return WNASPI32_DoPosting( lpPRB, SS_NO_DEVICE );
355   }
356
357   sg_hd = NULL;
358   sg_reply_hdr = NULL;
359
360   lpPRB->SRB_Status = SS_PENDING;
361
362   if (!lpPRB->SRB_CDBLen) {
363       ERR("Failed: lpPRB->SRB_CDBLen = 0.\n");
364       return WNASPI32_DoPosting( lpPRB, SS_INVALID_SRB );
365   }
366
367   /* build up sg_header + scsi cmd */
368   if (HOST_TO_TARGET(lpPRB)) {
369     /* send header, command, and then data */
370     in_len = SCSI_OFF + lpPRB->SRB_CDBLen + lpPRB->SRB_BufLen;
371     sg_hd = HeapAlloc(GetProcessHeap(), 0, in_len);
372     memset(sg_hd, 0, SCSI_OFF);
373     memcpy(sg_hd + 1, &lpPRB->CDBByte[0], lpPRB->SRB_CDBLen);
374     if (lpPRB->SRB_BufLen) {
375       memcpy(((BYTE *) sg_hd) + SCSI_OFF + lpPRB->SRB_CDBLen, lpPRB->SRB_BufPointer, lpPRB->SRB_BufLen);
376     }
377   }
378   else {
379     /* send header and command - no data */
380     in_len = SCSI_OFF + lpPRB->SRB_CDBLen;
381     sg_hd = HeapAlloc(GetProcessHeap(), 0, in_len);
382     memset(sg_hd, 0, SCSI_OFF);
383     memcpy(sg_hd + 1, &lpPRB->CDBByte[0], lpPRB->SRB_CDBLen);
384   }
385
386   if (TARGET_TO_HOST(lpPRB)) {
387     out_len = SCSI_OFF + lpPRB->SRB_BufLen;
388     sg_reply_hdr = HeapAlloc(GetProcessHeap(), 0, out_len);
389     memset(sg_reply_hdr, 0, SCSI_OFF);
390     sg_hd->reply_len = out_len;
391   }
392   else {
393     out_len = SCSI_OFF;
394     sg_reply_hdr = HeapAlloc(GetProcessHeap(), 0, out_len);
395     memset(sg_reply_hdr, 0, SCSI_OFF);
396     sg_hd->reply_len = out_len;
397   }
398
399   SCSI_Fix_CMD_LEN(fd, lpPRB->CDBByte[0], lpPRB->SRB_CDBLen);
400
401   if(!SCSI_LinuxDeviceIo( fd,
402                           sg_hd, in_len,
403                           sg_reply_hdr, out_len,
404                           &status) )
405   {
406     goto error_exit;
407   }
408
409   if (sg_reply_hdr->result != 0) {
410     error_code = sg_reply_hdr->result;
411     WARN("reply header error (%d)\n", sg_reply_hdr->result);
412     goto error_exit;
413   }
414
415   if (TARGET_TO_HOST(lpPRB) && lpPRB->SRB_BufLen) {
416     memcpy(lpPRB->SRB_BufPointer, sg_reply_hdr + 1, lpPRB->SRB_BufLen);
417   }
418
419   /* copy in sense buffer to amount that is available in client */
420   if (lpPRB->SRB_SenseLen) {
421     int sense_len = lpPRB->SRB_SenseLen;
422     if (lpPRB->SRB_SenseLen > 16)
423       sense_len = 16;
424
425     /* CDB is fixed in WNASPI32 */
426     memcpy(lpPRB->SenseArea, &sg_reply_hdr->sense_buffer[0], sense_len);
427
428     ASPI_PrintCDBArea(lpPRB);
429     ASPI_PrintSenseArea(lpPRB);
430   }
431
432   SRB_Status = SS_COMP;
433   lpPRB->SRB_HaStat = HASTAT_OK;
434   lpPRB->SRB_TargStat = sg_reply_hdr->target_status << 1;
435
436   HeapFree(GetProcessHeap(), 0, sg_reply_hdr);
437   HeapFree(GetProcessHeap(), 0, sg_hd);
438
439   /* FIXME: Should this be != 0 maybe? */
440   if( lpPRB->SRB_TargStat == 2 ) {
441     SRB_Status = SS_ERR;
442     switch (lpPRB->CDBByte[0]) {
443     case 0xa4: /* REPORT_KEY (DVD) MMC-2 */
444     case 0xa3: /* SEND KEY (DVD) MMC-2 */
445           SRB_Status = SS_COMP;
446           lpPRB->SRB_TargStat = 0;
447           FIXME("Program wants to do DVD Region switching, but fails (non compliant DVD drive). Ignoring....\n");
448           break;
449     }
450   }
451
452   ASPI_DebugPrintResult(lpPRB);
453   /* now do posting */
454   ret = WNASPI32_DoPosting( lpPRB, SRB_Status );
455
456   switch (lpPRB->CDBByte[0]) {
457   case CMD_INQUIRY:
458       if (SRB_Status == SS_COMP)
459           return SS_COMP; /* some junk expects ss_comp here. */
460       /*FALLTHROUGH*/
461   default:
462       break;
463   }
464
465   /* In real WNASPI32 stuff really is always pending because ASPI does things
466      in the background, but we are not doing that (yet) */
467
468   return ret;
469
470 error_exit:
471   SRB_Status = SS_ERR;
472   if (error_code == EBUSY) {
473       WNASPI32_DoPosting( lpPRB, SS_ASPI_IS_BUSY );
474       TRACE("Device busy\n");
475   } else
476       FIXME("Failed\n");
477
478   /* I'm not sure exactly error codes work here
479    * We probably should set lpPRB->SRB_TargStat, SRB_HaStat ?
480    */
481   WARN("error_exit\n");
482   HeapFree(GetProcessHeap(), 0, sg_reply_hdr);
483   HeapFree(GetProcessHeap(), 0, sg_hd);
484   WNASPI32_DoPosting( lpPRB, SRB_Status );
485   return SS_PENDING;
486 }
487
488 #endif /* defined(linux) */
489
490
491 /*******************************************************************
492  *     GetASPI32SupportInfo             [WNASPI32.1]
493  *
494  * Checks if the ASPI subsystem is initialized correctly.
495  *
496  * RETURNS
497  *    HIWORD: 0.
498  *    HIBYTE of LOWORD: status (SS_COMP or SS_FAILED_INIT)
499  *    LOBYTE of LOWORD: # of host adapters.
500  */
501 DWORD __cdecl GetASPI32SupportInfo(void)
502 {
503     DWORD controllers = ASPI_GetNumControllers();
504
505     if (!controllers)
506         return SS_NO_ADAPTERS << 8;
507     return (SS_COMP << 8) | controllers ;
508 }
509
510 /***********************************************************************
511  *             SendASPI32Command (WNASPI32.2)
512  */
513 DWORD __cdecl SendASPI32Command(LPSRB lpSRB)
514 {
515 #ifdef linux
516   static const char szId[] = "ASPI for WIN32";
517   static const char szWh[] = "Wine host";
518   switch (lpSRB->common.SRB_Cmd) {
519   case SC_HA_INQUIRY:
520     lpSRB->inquiry.SRB_Status = SS_COMP;       /* completed successfully */
521     lpSRB->inquiry.HA_Count = ASPI_GetNumControllers();
522     lpSRB->inquiry.HA_SCSI_ID = 7;             /* not always ID 7 */
523     memcpy(lpSRB->inquiry.HA_ManagerId, szId, sizeof szId); /* max 15 chars, don't change */
524     memcpy(lpSRB->inquiry.HA_Identifier, szWh, sizeof szWh); /* FIXME: return host adapter name */
525     memset(lpSRB->inquiry.HA_Unique, 0, 16); /* default HA_Unique content */
526     lpSRB->inquiry.HA_Unique[6] = 0x02; /* Maximum Transfer Length (128K, Byte> 4-7) */
527     lpSRB->inquiry.HA_Unique[3] = 0x08; /* Maximum number of SCSI targets */
528     FIXME("ASPI: Partially implemented SC_HA_INQUIRY for adapter %d.\n", lpSRB->inquiry.SRB_HaId);
529     return SS_COMP;
530
531   case SC_GET_DEV_TYPE: {
532     /* FIXME: We should return SS_NO_DEVICE if the device is not configured */
533     /* FIXME: We should return SS_INVALID_HA if HostAdapter!=0 */
534     SRB         tmpsrb;
535     unsigned char inqbuf[200];
536     DWORD       ret;
537
538     memset(&tmpsrb,0,sizeof(tmpsrb));
539
540     /* Copy header */
541     memcpy(&tmpsrb.common,&(lpSRB->common),sizeof(tmpsrb.common));
542
543     tmpsrb.cmd.SRB_Flags        |= 8; /* target to host */
544     tmpsrb.cmd.SRB_Cmd          = SC_EXEC_SCSI_CMD;
545     tmpsrb.cmd.SRB_Target       = lpSRB->devtype.SRB_Target;
546     tmpsrb.cmd.SRB_Lun          = lpSRB->devtype.SRB_Lun;
547     tmpsrb.cmd.SRB_BufLen       = sizeof(inqbuf);
548     tmpsrb.cmd.SRB_BufPointer   = inqbuf;
549     tmpsrb.cmd.CDBByte[0]       = 0x12; /* INQUIRY  */
550                                   /* FIXME: handle lun */
551     tmpsrb.cmd.CDBByte[4]       = sizeof(inqbuf);
552     tmpsrb.cmd.SRB_CDBLen       = 6;
553
554     ret = ASPI_ExecScsiCmd(&tmpsrb.cmd);
555
556     lpSRB->devtype.SRB_Status   = tmpsrb.cmd.SRB_Status;
557     lpSRB->devtype.SRB_DeviceType = inqbuf[0]&0x1f;
558
559     TRACE("returning devicetype %d for target %d\n",inqbuf[0]&0x1f,tmpsrb.cmd.SRB_Target);
560     if (ret!=SS_PENDING) /* Any error is passed down directly */
561         return ret;
562     /* FIXME: knows that the command is finished already, pass final Status */
563     return tmpsrb.cmd.SRB_Status;
564   }
565   case SC_EXEC_SCSI_CMD:
566     return ASPI_ExecScsiCmd(&lpSRB->cmd);
567   case SC_ABORT_SRB:
568     FIXME("Not implemented SC_ABORT_SRB\n");
569     break;
570   case SC_RESET_DEV:
571     FIXME("Not implemented SC_RESET_DEV\n");
572     break;
573   case SC_GET_DISK_INFO:
574     /* here we have to find out the int13 / bios association.
575      * We just say we do not have any.
576      */
577     FIXME("SC_GET_DISK_INFO always return 'int13 unassociated disk'.\n");
578     lpSRB->diskinfo.SRB_DriveFlags = 0; /* disk is not int13 served */
579     return SS_COMP;
580   default:
581     FIXME("Unknown command %d\n", lpSRB->common.SRB_Cmd);
582   }
583   return SS_INVALID_SRB;
584 #else
585   return SS_INVALID_SRB;
586 #endif
587 }
588
589
590 /***********************************************************************
591  *             GetASPI32DLLVersion   (WNASPI32.4)
592  */
593 DWORD __cdecl GetASPI32DLLVersion(void)
594 {
595 #ifdef linux
596         TRACE("Returning version 1\n");
597         return (DWORD)1;
598 #else
599         FIXME("Please add SCSI support for your operating system, returning 0\n");
600         return (DWORD)0;
601 #endif
602 }
603
604 /***********************************************************************
605  *             GetASPI32Buffer   (WNASPI32.8)
606  * Supposed to return a DMA capable large SCSI buffer.
607  * Our implementation does not use those at all, all buffer stuff is
608  * done in the kernel SG device layer. So we just heapalloc the buffer.
609  */
610 BOOL __cdecl GetASPI32Buffer(PASPI32BUFF pab)
611 {
612     pab->AB_BufPointer = HeapAlloc(GetProcessHeap(),
613                 pab->AB_ZeroFill?HEAP_ZERO_MEMORY:0,
614                 pab->AB_BufLen
615     );
616     if (!pab->AB_BufPointer) return FALSE;
617     return TRUE;
618 }
619
620 /***********************************************************************
621  *             FreeASPI32Buffer   (WNASPI32.14)
622  */
623 BOOL __cdecl FreeASPI32Buffer(PASPI32BUFF pab)
624 {
625     HeapFree(GetProcessHeap(),0,pab->AB_BufPointer);
626     return TRUE;
627 }
628
629 /***********************************************************************
630  *             TranslateASPI32Address   (WNASPI32.7)
631  */
632 BOOL __cdecl TranslateASPI32Address(LPDWORD pdwPath, LPDWORD pdwDEVNODE)
633 {
634     FIXME("(%p, %p), stub !\n", pdwPath, pdwDEVNODE);
635     return TRUE;
636 }