freemyipod r226 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r225‎ | r226 | r227 >
Date:00:35, 26 October 2010
Author:theseven
Status:new
Tags:
Comment:
Implement infrastructure for target-specific USB requests
Modified paths:
  • /embios/trunk/usb/usb.c (modified) (history)
  • /embios/trunk/usb/usbtarget.h (added) (history)

Diff [purge]

Index: embios/trunk/usb/usbtarget.h
@@ -0,0 +1,34 @@
 2+//
 3+//
 4+// Copyright 2010 TheSeven
 5+//
 6+//
 7+// This file is part of emBIOS.
 8+//
 9+// emBIOS is free software: you can redistribute it and/or
 10+// modify it under the terms of the GNU General Public License as
 11+// published by the Free Software Foundation, either version 2 of the
 12+// License, or (at your option) any later version.
 13+//
 14+// emBIOS is distributed in the hope that it will be useful,
 15+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 17+// See the GNU General Public License for more details.
 18+//
 19+// You should have received a copy of the GNU General Public License along
 20+// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
 21+//
 22+//
 23+
 24+
 25+#ifndef __USBTARGET_H__
 26+#define __USBTARGET_H__
 27+
 28+
 29+#include "global.h"
 30+
 31+
 32+int usb_target_handle_request(uint32_t* buffer, int bufsize);
 33+
 34+
 35+#endif
Index: embios/trunk/usb/usb.c
@@ -46,6 +46,9 @@
4747 #ifdef HAVE_HMACSHA1
4848 #include "hmacsha1.h"
4949 #endif
 50+#ifdef USB_HAVE_TARGET_SPECIFIC_REQUESTS
 51+#include "usbtarget.h"
 52+#endif
5053
5154
5255 static uint8_t ctrlresp[2] CACHEALIGN_ATTR;
@@ -69,7 +72,8 @@
7073 DBGACTION_READBOOTFLASH,
7174 DBGACTION_WRITEBOOTFLASH,
7275 DBGACTION_HWKEYAES,
73 - DBGACTION_HMACSHA1
 76+ DBGACTION_HMACSHA1,
 77+ DBGACTION_TARGETSPECIFIC
7478 };
7579
7680 static uint32_t dbgstack[0x100] STACK_ATTR;
@@ -332,6 +336,15 @@
333337 int size = 0;
334338 if (endpoint == dbgendpoints[0])
335339 {
 340+#ifdef USB_HAVE_TARGET_SPECIFIC_REQUESTS
 341+ if (dbgrecvbuf[0] >= 0xffff0000)
 342+ {
 343+ if (!set_dbgaction(DBGACTION_TARGETSPECIFIC, 0))
 344+ memcpy(dbgasyncsendbuf, dbgrecvbuf, sizeof(dbgasyncsendbuf));
 345+ usb_setup_dbg_listener();
 346+ return;
 347+ }
 348+#endif
336349 switch (dbgrecvbuf[0])
337350 {
338351 case 1: // GET INFO
@@ -641,7 +654,7 @@
642655 dbgasyncsendbuf[0] = 1;
643656 dbgasyncsendbuf[1] = cread(dbgactionconsoles, (char*)&dbgasyncsendbuf[4],
644657 dbgactionlength, 0);
645 - usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16);
 658+ usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16 + dbgactionlength);
646659 break;
647660 case DBGACTION_CFLUSH:
648661 cflush(dbgactionconsoles);
@@ -685,7 +698,15 @@
686699 usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, 16);
687700 break;
688701 #endif
 702+#ifdef USB_HAVE_TARGET_SPECIFIC_REQUESTS
 703+ case DBGACTION_TARGETSPECIFIC:
 704+ {
 705+ int size = usb_target_handle_request(dbgasyncsendbuf, sizeof(dbgasyncsendbuf));
 706+ if (size) usb_drv_send_nonblocking(dbgendpoints[1], dbgasyncsendbuf, size);
 707+ break;
689708 }
 709+#endif
 710+ }
690711 dbgaction = DBGACTION_IDLE;
691712 }
692713 }