Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
346 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
427 farthen 6
//    This file is part of emCORE.
346 theseven 7
//
427 farthen 8
//    emCORE is free software: you can redistribute it and/or
346 theseven 9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
427 farthen 13
//    emCORE is distributed in the hope that it will be useful,
346 theseven 14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
427 farthen 19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
346 theseven 20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "usb/usbtarget.h"
26
#include "usb/usbdrv.h"
27
#include "storage_ata-target.h"
28
 
29
 
30
int usb_target_handle_request(uint32_t* buffer, int bufsize)
31
{
32
    int size = 0;
33
    switch (buffer[0])
34
    {
35
        case 0xffff0001:  // GET DISK INFO
36
        {
37
            buffer[0] = 1;
38
            buffer[1] = (uint32_t)ata_identify_data;
39
            buffer[2] = ata_total_sectors;
40
            buffer[3] = ata_total_sectors >> 32;
41
#ifdef ATA_HAVE_BBT
42
            buffer[4] = ata_virtual_sectors;
43
            buffer[5] = ata_virtual_sectors >> 32;
44
            buffer[6] = (uint32_t)ata_bbt;
432 theseven 45
            buffer[7] = 0;
346 theseven 46
#else
47
            buffer[4] = ata_total_sectors;
48
            buffer[5] = ata_total_sectors >> 32;
49
            buffer[6] = 0;
50
            buffer[7] = 0;
51
#endif
52
            size = 32;
53
            break;
54
        }
55
        case 0xffff0002:  // LOWLEVEL DISK ACCESS
56
        {
348 theseven 57
#ifdef ATA_HAVE_BBT
346 theseven 58
            int rc = ata_rw_sectors_internal((((uint64_t)(buffer[3])) << 32) | buffer[2],
59
                                             buffer[4], (void*)(buffer[5]), (bool)(buffer[1]));
348 theseven 60
#else
61
            int rc = ata_rw_sectors((((uint64_t)(buffer[3])) << 32) | buffer[2],
62
                                    buffer[4], (void*)(buffer[5]), (bool)(buffer[1]));
63
#endif
346 theseven 64
            buffer[0] = 1;
65
            buffer[1] = (uint32_t)rc;
66
            size = 16;
67
            break;
68
        }
69
        default:
70
            buffer[0] = 2;
71
            size = 16;
72
    }
73
    return size;
74
}