Don't let UI access transferQueue directly.
[MacTF.git] / USBFunctions.h
blob41a32f50909ece35937685ecf9bfdccbe2517193
1 //
2 // USBFunctions.h
3 // MacTF
4 //
5 // Created by Nathan Oates on Sun Aug 01 2004.
6 // Copyright (c) 2004 Nathan Oates. All rights reserved.
7 //
9 // Includes code from uproar - see below for License:
12 * uproar 0.1
13 * Copyright (c) 2001 Kasima Tharnpipitchai <me@kasima.org>
15 * This source code is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Public License as published
17 * by the Free Software Foundation; either version 2 of the License,
18 * or (at your option) any later version.
20 * This source code is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 * Please refer to the GNU Public License for more details.
25 * You should have received a copy of the GNU Public License along with
26 * this source code; if not, write to:
27 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #ifndef word
30 typedef unsigned short word;
31 #endif
32 #ifndef dword
33 typedef unsigned long dword;
34 #endif
35 #ifndef byte
36 typedef unsigned char byte;
37 #endif
39 #define USB_CmdNone 0x00000000
41 #define USB_Fail 0x00000001
42 #define USB_Success 0x00000002
43 #define USB_Cancel 0x00000003
45 #define USB_CmdReady 0x00000100
46 #define USB_CmdReset 0x00000101
47 #define USB_CmdTurbo 0x00000102
49 // Hdd Cmd
50 #define USB_CmdHddSize 0x00001000
51 #define USB_DataHddSize 0x00001001
53 #define USB_CmdHddDir 0x00001002
54 #define USB_DataHddDir 0x00001003
55 #define USB_DataHddDirEnd 0x00001004
57 #define USB_CmdHddDel 0x00001005
58 #define USB_CmdHddRename 0x00001006
59 #define USB_CmdHddCreateDir 0x00001007
61 #define USB_CmdHddFileSend 0x00001008
62 #define USB_DataHddFileStart 0x00001009
63 #define USB_DataHddFileData 0x0000100A
64 #define USB_DataHddFileEnd 0x0000100B
66 // -----------------------------------------------------------------------------
67 // Usb Error Code
68 #define USB_OK 0x00000000
69 #define USB_Err_Crc 0x00000001
70 #define USB_Err_UnknownCmd 0x00000002
71 #define USB_Err_InvalidCmd 0x00000003
72 #define USB_Err_Unknown 0x00000004
73 #define USB_Err_Size 0x00000005
74 #define USB_Err_RunFail 0x00000006
75 #define USB_Err_Memory 0x00000007
77 // -----------------------------------------------------------------------------
78 // File send direct
79 #define USB_FileToDevice 0x00
80 #define USB_FileToHost 0x01
82 // -----------------------------------------------------------------------------
83 // File Attribute
84 #define USB_FileTypeFolder 0x01
85 #define USB_FileTypeNormal 0x02
87 // -----------------------------------------------------------------------------
88 #define USB_FileTypeSize 114
89 #define USB_FileNameSize 95
93 #import <Foundation/Foundation.h>
95 #include <stdio.h>
96 #include <stdlib.h>
97 #include <string.h>
98 #include <ctype.h>
100 #include <mach/mach.h>
102 #include <CoreFoundation/CFNumber.h>
103 #import "DataHandler.h"
104 #include <IOKit/IOKitLib.h>
105 #include <IOKit/IOCFPlugIn.h>
106 #include <IOKit/usb/IOUSBLib.h>
108 //#define kBlockSize 0x08
109 #define kMaxXferSize 0xFFFF
111 #define kUproarSuccess 0
112 #define kUproarTrackNotFound -1
113 #define kUproarTrackExists -2
114 #define kUproarDeviceErr -3
115 #define kUproarNotEnoughSpace -4
118 typedef struct {
119 IOUSBDeviceInterface197 **dev;
120 IOUSBInterfaceInterface197 **intf;
121 } USBDeviceContext;
124 @interface USBFunctions : NSObject {
125 NSProgressIndicator* progressBar;
126 NSTextField* progressTime;
127 USBDeviceContext* myContext;
129 int debug;
130 int rate;
131 int kBlockSize;
132 int connectedSpeed;
134 int initDevice(USBDeviceContext *device);
136 int getDeviceInfo(USBDeviceContext *device,
137 UInt8 *devInfo);
140 - (void) closeDevice:(USBDeviceContext *)device;
142 void hexDump(UInt8 *buf, int len);
144 - (USBDeviceContext*) initializeUSB;
145 - (NSData*) getHDDSize:(USBDeviceContext*)device ;
146 - (NSData*) getFileList:(USBDeviceContext*)device forPath:(NSString*) path;
147 - (word) findCRC:(byte*)p length:(dword) n;
148 - (NSData*) prepareCommand:(unsigned int)cmd withData:(NSData*) inData ;
149 - (int) getFile:(NSDictionary*)fileInfo forPath:(NSString*) currentPath toSaveTo:(NSString*) savePath withLoop:(BOOL)looping ;
150 - (int) getFile:(NSDictionary*)fileInfo forPath:(NSString*) currentPath toSaveTo:(NSString*) savePath atOffset:(unsigned long long) offset withLoop:(BOOL)looping ;
152 - (NSData*) sendCommand:(NSData*) fullyPackagedCommand toDevice:(USBDeviceContext*)device expectResponse:(BOOL) getResponse careForReturn:(BOOL) careFactor;
153 - (NSMutableData*) swap: (NSData*) inData;
154 - (void) turnTurboOn:(BOOL) turnOn forDevice:(USBDeviceContext*)device withReset:(BOOL)reset;
155 - (void) uploadFile:(NSString*) fileToUpload ofSize:(long long)size fromPath:(NSString*)curPath withAttributes:(NSData*) typeFile toDevice:(USBDeviceContext*)dev ;
156 - (int) getSpeed;
157 - (void) setDebug:(int)mode;
158 -(void) setRate:(int) newRate ;
159 -(void) setProgressBar:(NSProgressIndicator*)bar time:(NSTextField*)timeField;
160 -(void) updateProgress:(NSDictionary*) inDict;
161 - (NSString*) elapsedTime:(NSTimeInterval) totalSeconds ;
162 - (void) deleteFile:(NSDictionary*)fileInfo fromPath:(NSString*)currentPath onDevice:(USBDeviceContext*)device;
163 - (void) renameFile:(NSString*) oldName withName:(NSString*)newName atPath:(NSString*)currentPath onDevice:(USBDeviceContext*)device;
164 - (void) makeFolder:(NSString*)newName atPath:(NSString*)currentPath onDevice:(USBDeviceContext*)device;
165 - (void) checkUSB:(USBDeviceContext*)device ;
167 @end