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