Small Testprogram to have WebAccess via Webserver to a 433Mhz tranmitter to control remotly some devices from remote, with TFTP, NTP and RMF. This could be a base to develop applications.
Dependencies: ChaNFSSD TFTPServer RMFWeb
NetServices/drv/umtsstick/UMTSStick.cpp@0:51f1ef89ec7b, 2014-06-06 (annotated)
- Committer:
- ED7418
- Date:
- Fri Jun 06 09:06:03 2014 +0000
- Revision:
- 0:51f1ef89ec7b
06062014
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ED7418 | 0:51f1ef89ec7b | 1 | |
ED7418 | 0:51f1ef89ec7b | 2 | /* |
ED7418 | 0:51f1ef89ec7b | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
ED7418 | 0:51f1ef89ec7b | 4 | |
ED7418 | 0:51f1ef89ec7b | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
ED7418 | 0:51f1ef89ec7b | 6 | of this software and associated documentation files (the "Software"), to deal |
ED7418 | 0:51f1ef89ec7b | 7 | in the Software without restriction, including without limitation the rights |
ED7418 | 0:51f1ef89ec7b | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
ED7418 | 0:51f1ef89ec7b | 9 | copies of the Software, and to permit persons to whom the Software is |
ED7418 | 0:51f1ef89ec7b | 10 | furnished to do so, subject to the following conditions: |
ED7418 | 0:51f1ef89ec7b | 11 | |
ED7418 | 0:51f1ef89ec7b | 12 | The above copyright notice and this permission notice shall be included in |
ED7418 | 0:51f1ef89ec7b | 13 | all copies or substantial portions of the Software. |
ED7418 | 0:51f1ef89ec7b | 14 | |
ED7418 | 0:51f1ef89ec7b | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
ED7418 | 0:51f1ef89ec7b | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
ED7418 | 0:51f1ef89ec7b | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
ED7418 | 0:51f1ef89ec7b | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
ED7418 | 0:51f1ef89ec7b | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ED7418 | 0:51f1ef89ec7b | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
ED7418 | 0:51f1ef89ec7b | 21 | THE SOFTWARE. |
ED7418 | 0:51f1ef89ec7b | 22 | */ |
ED7418 | 0:51f1ef89ec7b | 23 | |
ED7418 | 0:51f1ef89ec7b | 24 | #include "netCfg.h" |
ED7418 | 0:51f1ef89ec7b | 25 | #if NET_UMTS |
ED7418 | 0:51f1ef89ec7b | 26 | |
ED7418 | 0:51f1ef89ec7b | 27 | #include "UMTSStick.h" |
ED7418 | 0:51f1ef89ec7b | 28 | |
ED7418 | 0:51f1ef89ec7b | 29 | #define __DEBUG |
ED7418 | 0:51f1ef89ec7b | 30 | #include "dbg/dbg.h" |
ED7418 | 0:51f1ef89ec7b | 31 | |
ED7418 | 0:51f1ef89ec7b | 32 | UMTSStick::UMTSStick() : m_host(), m_pDev(NULL) |
ED7418 | 0:51f1ef89ec7b | 33 | { |
ED7418 | 0:51f1ef89ec7b | 34 | |
ED7418 | 0:51f1ef89ec7b | 35 | } |
ED7418 | 0:51f1ef89ec7b | 36 | |
ED7418 | 0:51f1ef89ec7b | 37 | UMTSStick::~UMTSStick() |
ED7418 | 0:51f1ef89ec7b | 38 | { |
ED7418 | 0:51f1ef89ec7b | 39 | |
ED7418 | 0:51f1ef89ec7b | 40 | } |
ED7418 | 0:51f1ef89ec7b | 41 | |
ED7418 | 0:51f1ef89ec7b | 42 | |
ED7418 | 0:51f1ef89ec7b | 43 | UMTSStickErr UMTSStick::getSerial(UsbSerial** ppUsbSerial) |
ED7418 | 0:51f1ef89ec7b | 44 | { |
ED7418 | 0:51f1ef89ec7b | 45 | m_host.init(); |
ED7418 | 0:51f1ef89ec7b | 46 | |
ED7418 | 0:51f1ef89ec7b | 47 | UMTSStickErr rc; |
ED7418 | 0:51f1ef89ec7b | 48 | |
ED7418 | 0:51f1ef89ec7b | 49 | rc = waitForDevice(); |
ED7418 | 0:51f1ef89ec7b | 50 | if(rc) |
ED7418 | 0:51f1ef89ec7b | 51 | return rc; |
ED7418 | 0:51f1ef89ec7b | 52 | |
ED7418 | 0:51f1ef89ec7b | 53 | //Device is now enumerated, read table |
ED7418 | 0:51f1ef89ec7b | 54 | |
ED7418 | 0:51f1ef89ec7b | 55 | uint16_t vid = m_pDev->getVid(); |
ED7418 | 0:51f1ef89ec7b | 56 | uint16_t pid = m_pDev->getPid(); |
ED7418 | 0:51f1ef89ec7b | 57 | |
ED7418 | 0:51f1ef89ec7b | 58 | DBG("Configuration set: vid:%04x pid:%04x\n", vid, pid); |
ED7418 | 0:51f1ef89ec7b | 59 | |
ED7418 | 0:51f1ef89ec7b | 60 | bool handled = false; |
ED7418 | 0:51f1ef89ec7b | 61 | bool cdfs = false; |
ED7418 | 0:51f1ef89ec7b | 62 | const UMTSSwitchingInfo* pInfo; |
ED7418 | 0:51f1ef89ec7b | 63 | for(int i = 0; i < UMTS_SWITCHING_COUNT; i++) |
ED7418 | 0:51f1ef89ec7b | 64 | { |
ED7418 | 0:51f1ef89ec7b | 65 | pInfo = &UMTSwitchingTable[i]; |
ED7418 | 0:51f1ef89ec7b | 66 | if( !checkDeviceState(pInfo, &cdfs) ) |
ED7418 | 0:51f1ef89ec7b | 67 | { |
ED7418 | 0:51f1ef89ec7b | 68 | handled = true; |
ED7418 | 0:51f1ef89ec7b | 69 | break; |
ED7418 | 0:51f1ef89ec7b | 70 | } |
ED7418 | 0:51f1ef89ec7b | 71 | |
ED7418 | 0:51f1ef89ec7b | 72 | } //for(int i = 0; i < UMTS_SWITCHING_COUNT; i++) |
ED7418 | 0:51f1ef89ec7b | 73 | |
ED7418 | 0:51f1ef89ec7b | 74 | if(!handled) |
ED7418 | 0:51f1ef89ec7b | 75 | { |
ED7418 | 0:51f1ef89ec7b | 76 | DBG("Don't know this device!\n"); |
ED7418 | 0:51f1ef89ec7b | 77 | return UMTSERR_NOTIMPLEMENTED; |
ED7418 | 0:51f1ef89ec7b | 78 | } |
ED7418 | 0:51f1ef89ec7b | 79 | |
ED7418 | 0:51f1ef89ec7b | 80 | //Check if the device is in CDFS mode, in this case switch |
ED7418 | 0:51f1ef89ec7b | 81 | if(cdfs) |
ED7418 | 0:51f1ef89ec7b | 82 | { |
ED7418 | 0:51f1ef89ec7b | 83 | DBG("Switching the device by sending a magic packet\n"); |
ED7418 | 0:51f1ef89ec7b | 84 | |
ED7418 | 0:51f1ef89ec7b | 85 | rc = switchMode(pInfo); |
ED7418 | 0:51f1ef89ec7b | 86 | if(rc) |
ED7418 | 0:51f1ef89ec7b | 87 | return rc; |
ED7418 | 0:51f1ef89ec7b | 88 | |
ED7418 | 0:51f1ef89ec7b | 89 | DBG("Now wait for device to reconnect\n"); |
ED7418 | 0:51f1ef89ec7b | 90 | |
ED7418 | 0:51f1ef89ec7b | 91 | m_host.releaseDevice(m_pDev); |
ED7418 | 0:51f1ef89ec7b | 92 | |
ED7418 | 0:51f1ef89ec7b | 93 | //Wait for device to reconnect |
ED7418 | 0:51f1ef89ec7b | 94 | wait(3); |
ED7418 | 0:51f1ef89ec7b | 95 | rc = waitForDevice(); |
ED7418 | 0:51f1ef89ec7b | 96 | if(rc) |
ED7418 | 0:51f1ef89ec7b | 97 | return rc; |
ED7418 | 0:51f1ef89ec7b | 98 | } |
ED7418 | 0:51f1ef89ec7b | 99 | |
ED7418 | 0:51f1ef89ec7b | 100 | rc = findSerial(ppUsbSerial); |
ED7418 | 0:51f1ef89ec7b | 101 | if(rc) |
ED7418 | 0:51f1ef89ec7b | 102 | return rc; |
ED7418 | 0:51f1ef89ec7b | 103 | |
ED7418 | 0:51f1ef89ec7b | 104 | return UMTSERR_OK; |
ED7418 | 0:51f1ef89ec7b | 105 | } |
ED7418 | 0:51f1ef89ec7b | 106 | |
ED7418 | 0:51f1ef89ec7b | 107 | UMTSStickErr UMTSStick::waitForDevice() |
ED7418 | 0:51f1ef89ec7b | 108 | { |
ED7418 | 0:51f1ef89ec7b | 109 | bool ready = false; |
ED7418 | 0:51f1ef89ec7b | 110 | while(!ready) |
ED7418 | 0:51f1ef89ec7b | 111 | { |
ED7418 | 0:51f1ef89ec7b | 112 | while(!m_host.devicesCount()) |
ED7418 | 0:51f1ef89ec7b | 113 | {} |
ED7418 | 0:51f1ef89ec7b | 114 | wait(1); |
ED7418 | 0:51f1ef89ec7b | 115 | if(m_host.devicesCount()) |
ED7418 | 0:51f1ef89ec7b | 116 | ready = true; |
ED7418 | 0:51f1ef89ec7b | 117 | } |
ED7418 | 0:51f1ef89ec7b | 118 | |
ED7418 | 0:51f1ef89ec7b | 119 | wait(2); //Wait for device to be initialized |
ED7418 | 0:51f1ef89ec7b | 120 | |
ED7418 | 0:51f1ef89ec7b | 121 | if(!m_host.devicesCount()) |
ED7418 | 0:51f1ef89ec7b | 122 | return UMTSERR_DISCONNECTED; |
ED7418 | 0:51f1ef89ec7b | 123 | |
ED7418 | 0:51f1ef89ec7b | 124 | m_pDev = m_host.getDevice(0); |
ED7418 | 0:51f1ef89ec7b | 125 | |
ED7418 | 0:51f1ef89ec7b | 126 | while(!m_pDev->enumerated()) |
ED7418 | 0:51f1ef89ec7b | 127 | { |
ED7418 | 0:51f1ef89ec7b | 128 | m_host.poll(); |
ED7418 | 0:51f1ef89ec7b | 129 | if(!m_host.devicesCount()) |
ED7418 | 0:51f1ef89ec7b | 130 | return UMTSERR_DISCONNECTED; |
ED7418 | 0:51f1ef89ec7b | 131 | } |
ED7418 | 0:51f1ef89ec7b | 132 | |
ED7418 | 0:51f1ef89ec7b | 133 | return UMTSERR_OK; |
ED7418 | 0:51f1ef89ec7b | 134 | } |
ED7418 | 0:51f1ef89ec7b | 135 | |
ED7418 | 0:51f1ef89ec7b | 136 | UMTSStickErr UMTSStick::checkDeviceState(const UMTSSwitchingInfo* pInfo, bool* pCdfs) |
ED7418 | 0:51f1ef89ec7b | 137 | { |
ED7418 | 0:51f1ef89ec7b | 138 | uint16_t vid = m_pDev->getVid(); |
ED7418 | 0:51f1ef89ec7b | 139 | uint16_t pid = m_pDev->getPid(); |
ED7418 | 0:51f1ef89ec7b | 140 | bool handled = false; |
ED7418 | 0:51f1ef89ec7b | 141 | if( (vid == pInfo->cdfsVid) && (pid == pInfo->cdfsPid) ) |
ED7418 | 0:51f1ef89ec7b | 142 | { |
ED7418 | 0:51f1ef89ec7b | 143 | DBG("Match on dongles list\n"); |
ED7418 | 0:51f1ef89ec7b | 144 | if( !pInfo->targetClass ) //No specific interface to check, vid/pid couple is specific to CDFS mode |
ED7418 | 0:51f1ef89ec7b | 145 | { |
ED7418 | 0:51f1ef89ec7b | 146 | DBG("Found device in CDFS mode\n"); |
ED7418 | 0:51f1ef89ec7b | 147 | handled = true; |
ED7418 | 0:51f1ef89ec7b | 148 | *pCdfs = true; |
ED7418 | 0:51f1ef89ec7b | 149 | } |
ED7418 | 0:51f1ef89ec7b | 150 | else //if( !pInfo->targetClass ) |
ED7418 | 0:51f1ef89ec7b | 151 | { |
ED7418 | 0:51f1ef89ec7b | 152 | //Has to check if there is an interface of class targetClass |
ED7418 | 0:51f1ef89ec7b | 153 | byte* desc = NULL; |
ED7418 | 0:51f1ef89ec7b | 154 | int c = 0; |
ED7418 | 0:51f1ef89ec7b | 155 | |
ED7418 | 0:51f1ef89ec7b | 156 | while( !m_pDev->getInterfaceDescriptor(1, c++, &desc) ) |
ED7418 | 0:51f1ef89ec7b | 157 | { |
ED7418 | 0:51f1ef89ec7b | 158 | if( desc[5] == pInfo->targetClass ) |
ED7418 | 0:51f1ef89ec7b | 159 | { |
ED7418 | 0:51f1ef89ec7b | 160 | DBG("Found device in Serial mode\n"); |
ED7418 | 0:51f1ef89ec7b | 161 | handled = true; |
ED7418 | 0:51f1ef89ec7b | 162 | *pCdfs = false; |
ED7418 | 0:51f1ef89ec7b | 163 | break; |
ED7418 | 0:51f1ef89ec7b | 164 | } |
ED7418 | 0:51f1ef89ec7b | 165 | } |
ED7418 | 0:51f1ef89ec7b | 166 | |
ED7418 | 0:51f1ef89ec7b | 167 | if(!handled) |
ED7418 | 0:51f1ef89ec7b | 168 | { |
ED7418 | 0:51f1ef89ec7b | 169 | //All interfaces were tried, so we are in CDFS mode |
ED7418 | 0:51f1ef89ec7b | 170 | DBG("Found device in CDFS mode\n"); |
ED7418 | 0:51f1ef89ec7b | 171 | handled = true; |
ED7418 | 0:51f1ef89ec7b | 172 | *pCdfs = true; |
ED7418 | 0:51f1ef89ec7b | 173 | } |
ED7418 | 0:51f1ef89ec7b | 174 | } //if( !pInfo->targetClass ) |
ED7418 | 0:51f1ef89ec7b | 175 | } //if( (vid == pInfo->cdfsVid) && (pid == pInfo->cdfsPid) ) |
ED7418 | 0:51f1ef89ec7b | 176 | else |
ED7418 | 0:51f1ef89ec7b | 177 | { |
ED7418 | 0:51f1ef89ec7b | 178 | //Try every vid/pid couple of the serial list |
ED7418 | 0:51f1ef89ec7b | 179 | for( int i = 0; i < 16 ; i++) |
ED7418 | 0:51f1ef89ec7b | 180 | { |
ED7418 | 0:51f1ef89ec7b | 181 | if(!pInfo->serialPidList[i]) |
ED7418 | 0:51f1ef89ec7b | 182 | break; |
ED7418 | 0:51f1ef89ec7b | 183 | if( (pInfo->serialVid == vid) && (pInfo->serialPidList[i] == pid) ) |
ED7418 | 0:51f1ef89ec7b | 184 | { |
ED7418 | 0:51f1ef89ec7b | 185 | DBG("Found device in Serial mode\n"); |
ED7418 | 0:51f1ef89ec7b | 186 | handled = true; |
ED7418 | 0:51f1ef89ec7b | 187 | *pCdfs = false; |
ED7418 | 0:51f1ef89ec7b | 188 | break; |
ED7418 | 0:51f1ef89ec7b | 189 | } |
ED7418 | 0:51f1ef89ec7b | 190 | } |
ED7418 | 0:51f1ef89ec7b | 191 | } //if( (vid == pInfo->cdfsVid) && (pid == pInfo->cdfsPid) ) |
ED7418 | 0:51f1ef89ec7b | 192 | |
ED7418 | 0:51f1ef89ec7b | 193 | if(!handled) |
ED7418 | 0:51f1ef89ec7b | 194 | return UMTSERR_NOTFOUND; |
ED7418 | 0:51f1ef89ec7b | 195 | |
ED7418 | 0:51f1ef89ec7b | 196 | return UMTSERR_OK; |
ED7418 | 0:51f1ef89ec7b | 197 | } |
ED7418 | 0:51f1ef89ec7b | 198 | |
ED7418 | 0:51f1ef89ec7b | 199 | UMTSStickErr UMTSStick::switchMode(const UMTSSwitchingInfo* pInfo) |
ED7418 | 0:51f1ef89ec7b | 200 | { |
ED7418 | 0:51f1ef89ec7b | 201 | if(!pInfo->huaweiPacket) //Send SCSI packet on first bulk ep |
ED7418 | 0:51f1ef89ec7b | 202 | { |
ED7418 | 0:51f1ef89ec7b | 203 | //Find first bulk ep |
ED7418 | 0:51f1ef89ec7b | 204 | byte* desc = NULL; |
ED7418 | 0:51f1ef89ec7b | 205 | int c = 0; |
ED7418 | 0:51f1ef89ec7b | 206 | |
ED7418 | 0:51f1ef89ec7b | 207 | UsbEndpoint *pEpOut = NULL; |
ED7418 | 0:51f1ef89ec7b | 208 | |
ED7418 | 0:51f1ef89ec7b | 209 | while( !m_pDev->getInterfaceDescriptor(1, c++, &desc) ) |
ED7418 | 0:51f1ef89ec7b | 210 | { |
ED7418 | 0:51f1ef89ec7b | 211 | byte* p = desc; |
ED7418 | 0:51f1ef89ec7b | 212 | int epNum = 0; |
ED7418 | 0:51f1ef89ec7b | 213 | p = p + p[0]; //Move to next descriptor (which should be an ep descriptor) |
ED7418 | 0:51f1ef89ec7b | 214 | while (epNum < desc[4]) //Eps count in this if |
ED7418 | 0:51f1ef89ec7b | 215 | { |
ED7418 | 0:51f1ef89ec7b | 216 | if (p[1] != USB_DESCRIPTOR_TYPE_ENDPOINT) |
ED7418 | 0:51f1ef89ec7b | 217 | break; |
ED7418 | 0:51f1ef89ec7b | 218 | |
ED7418 | 0:51f1ef89ec7b | 219 | if( (p[3] == 0x02) && !(p[2] & 0x80) ) //Bulk endpoint, out |
ED7418 | 0:51f1ef89ec7b | 220 | { |
ED7418 | 0:51f1ef89ec7b | 221 | DBG("Found bulk ep %02x\n", p[2]); |
ED7418 | 0:51f1ef89ec7b | 222 | pEpOut = new UsbEndpoint( m_pDev, p[2], false, USB_BULK, *((uint16_t*)&p[4]) ); |
ED7418 | 0:51f1ef89ec7b | 223 | break; |
ED7418 | 0:51f1ef89ec7b | 224 | } |
ED7418 | 0:51f1ef89ec7b | 225 | |
ED7418 | 0:51f1ef89ec7b | 226 | p = p + p[0]; //Move to next ep desc |
ED7418 | 0:51f1ef89ec7b | 227 | epNum++; |
ED7418 | 0:51f1ef89ec7b | 228 | } |
ED7418 | 0:51f1ef89ec7b | 229 | if(pEpOut) |
ED7418 | 0:51f1ef89ec7b | 230 | break; |
ED7418 | 0:51f1ef89ec7b | 231 | } |
ED7418 | 0:51f1ef89ec7b | 232 | |
ED7418 | 0:51f1ef89ec7b | 233 | if(!pEpOut) |
ED7418 | 0:51f1ef89ec7b | 234 | return UMTSERR_NOTFOUND; |
ED7418 | 0:51f1ef89ec7b | 235 | |
ED7418 | 0:51f1ef89ec7b | 236 | //Send SCSI packet |
ED7418 | 0:51f1ef89ec7b | 237 | |
ED7418 | 0:51f1ef89ec7b | 238 | DBG("Sending SCSI Packet to switch\n"); |
ED7418 | 0:51f1ef89ec7b | 239 | byte ramCdfsBuf[31]; |
ED7418 | 0:51f1ef89ec7b | 240 | memcpy(ramCdfsBuf, pInfo->cdfsPacket, 31); |
ED7418 | 0:51f1ef89ec7b | 241 | pEpOut->transfer((volatile byte*)ramCdfsBuf, 31); |
ED7418 | 0:51f1ef89ec7b | 242 | while(pEpOut->status() == USBERR_PROCESSING); |
ED7418 | 0:51f1ef89ec7b | 243 | int ret = pEpOut->status(); |
ED7418 | 0:51f1ef89ec7b | 244 | if((ret < 0) && (ret !=USBERR_DISCONNECTED)) //Packet was not transfered |
ED7418 | 0:51f1ef89ec7b | 245 | { |
ED7418 | 0:51f1ef89ec7b | 246 | DBG("Usb error %d\n", ret); |
ED7418 | 0:51f1ef89ec7b | 247 | delete pEpOut; |
ED7418 | 0:51f1ef89ec7b | 248 | return UMTSERR_USBERR; |
ED7418 | 0:51f1ef89ec7b | 249 | } |
ED7418 | 0:51f1ef89ec7b | 250 | |
ED7418 | 0:51f1ef89ec7b | 251 | delete pEpOut; |
ED7418 | 0:51f1ef89ec7b | 252 | } |
ED7418 | 0:51f1ef89ec7b | 253 | else |
ED7418 | 0:51f1ef89ec7b | 254 | { |
ED7418 | 0:51f1ef89ec7b | 255 | UsbErr usbErr; |
ED7418 | 0:51f1ef89ec7b | 256 | //Send the Huawei-specific control packet |
ED7418 | 0:51f1ef89ec7b | 257 | usbErr = m_pDev->controlSend(0, 0x03, 1, 0, NULL, 0); |
ED7418 | 0:51f1ef89ec7b | 258 | if(usbErr && (usbErr != USBERR_DISCONNECTED)) |
ED7418 | 0:51f1ef89ec7b | 259 | return UMTSERR_USBERR; |
ED7418 | 0:51f1ef89ec7b | 260 | } |
ED7418 | 0:51f1ef89ec7b | 261 | |
ED7418 | 0:51f1ef89ec7b | 262 | DBG("The stick should be switching in serial mode now\n"); |
ED7418 | 0:51f1ef89ec7b | 263 | |
ED7418 | 0:51f1ef89ec7b | 264 | return UMTSERR_OK; |
ED7418 | 0:51f1ef89ec7b | 265 | } |
ED7418 | 0:51f1ef89ec7b | 266 | |
ED7418 | 0:51f1ef89ec7b | 267 | UMTSStickErr UMTSStick::findSerial(UsbSerial** ppUsbSerial) |
ED7418 | 0:51f1ef89ec7b | 268 | { |
ED7418 | 0:51f1ef89ec7b | 269 | byte* desc = NULL; |
ED7418 | 0:51f1ef89ec7b | 270 | int c = 0; |
ED7418 | 0:51f1ef89ec7b | 271 | |
ED7418 | 0:51f1ef89ec7b | 272 | int epOut = 0; |
ED7418 | 0:51f1ef89ec7b | 273 | int epIn = 0; |
ED7418 | 0:51f1ef89ec7b | 274 | |
ED7418 | 0:51f1ef89ec7b | 275 | while( !m_pDev->getInterfaceDescriptor(1, c++, &desc) ) |
ED7418 | 0:51f1ef89ec7b | 276 | { |
ED7418 | 0:51f1ef89ec7b | 277 | byte* p = desc; |
ED7418 | 0:51f1ef89ec7b | 278 | int epNum = 0; |
ED7418 | 0:51f1ef89ec7b | 279 | |
ED7418 | 0:51f1ef89ec7b | 280 | DBG("Interface of type %02x\n", desc[5]); |
ED7418 | 0:51f1ef89ec7b | 281 | |
ED7418 | 0:51f1ef89ec7b | 282 | if(desc[5] != 0xFF) //Not a serial-like if |
ED7418 | 0:51f1ef89ec7b | 283 | continue; |
ED7418 | 0:51f1ef89ec7b | 284 | |
ED7418 | 0:51f1ef89ec7b | 285 | p = p + p[0]; //Move to next descriptor (which should be an ep descriptor) |
ED7418 | 0:51f1ef89ec7b | 286 | while (epNum < desc[4]) //Eps count in this if |
ED7418 | 0:51f1ef89ec7b | 287 | { |
ED7418 | 0:51f1ef89ec7b | 288 | if (p[1] == USB_DESCRIPTOR_TYPE_ENDPOINT) |
ED7418 | 0:51f1ef89ec7b | 289 | { |
ED7418 | 0:51f1ef89ec7b | 290 | if( (p[3] == 0x02) && !(p[2] & 0x80) && !epOut ) //Bulk endpoint, out |
ED7418 | 0:51f1ef89ec7b | 291 | { |
ED7418 | 0:51f1ef89ec7b | 292 | DBG("Found bulk out ep %02x of payload size %04x\n", p[2], *((uint16_t*)&p[4])); |
ED7418 | 0:51f1ef89ec7b | 293 | epOut = p[2] & 0x7F; |
ED7418 | 0:51f1ef89ec7b | 294 | } |
ED7418 | 0:51f1ef89ec7b | 295 | |
ED7418 | 0:51f1ef89ec7b | 296 | if( (p[3] == 0x02) && (p[2] & 0x80) && !epIn ) //Bulk endpoint, in |
ED7418 | 0:51f1ef89ec7b | 297 | { |
ED7418 | 0:51f1ef89ec7b | 298 | DBG("Found bulk in ep %02x of payload size %04x\n", p[2], *((uint16_t*)&p[4])); |
ED7418 | 0:51f1ef89ec7b | 299 | epIn = p[2] & 0x7F; |
ED7418 | 0:51f1ef89ec7b | 300 | } |
ED7418 | 0:51f1ef89ec7b | 301 | |
ED7418 | 0:51f1ef89ec7b | 302 | if(epOut && epIn) |
ED7418 | 0:51f1ef89ec7b | 303 | break; |
ED7418 | 0:51f1ef89ec7b | 304 | } |
ED7418 | 0:51f1ef89ec7b | 305 | |
ED7418 | 0:51f1ef89ec7b | 306 | p = p + p[0]; //Move to next ep desc |
ED7418 | 0:51f1ef89ec7b | 307 | epNum++; |
ED7418 | 0:51f1ef89ec7b | 308 | } |
ED7418 | 0:51f1ef89ec7b | 309 | |
ED7418 | 0:51f1ef89ec7b | 310 | if(epOut && epIn) |
ED7418 | 0:51f1ef89ec7b | 311 | break; |
ED7418 | 0:51f1ef89ec7b | 312 | } |
ED7418 | 0:51f1ef89ec7b | 313 | |
ED7418 | 0:51f1ef89ec7b | 314 | if(!epOut || !epIn) |
ED7418 | 0:51f1ef89ec7b | 315 | return UMTSERR_NOTFOUND; |
ED7418 | 0:51f1ef89ec7b | 316 | |
ED7418 | 0:51f1ef89ec7b | 317 | DBG("Endpoints found, create serial object\n"); |
ED7418 | 0:51f1ef89ec7b | 318 | |
ED7418 | 0:51f1ef89ec7b | 319 | *ppUsbSerial = new UsbSerial(m_pDev, epIn, epOut); |
ED7418 | 0:51f1ef89ec7b | 320 | |
ED7418 | 0:51f1ef89ec7b | 321 | DBG("UsbSerial object created\n"); |
ED7418 | 0:51f1ef89ec7b | 322 | |
ED7418 | 0:51f1ef89ec7b | 323 | return UMTSERR_OK; |
ED7418 | 0:51f1ef89ec7b | 324 | } |
ED7418 | 0:51f1ef89ec7b | 325 | |
ED7418 | 0:51f1ef89ec7b | 326 | #endif |