USB Host Library for Sprint Dongles

Fork of USBHostWANDongleSprint_bleedingedge by Donatien Garnier

Legacy Warning

This is an mbed 2 libary. To learn more about mbed OS 5, visit the docs.

Committer:
donatien
Date:
Wed Oct 10 08:20:39 2012 +0000
Revision:
5:99f453c4756b
Parent:
3:9ec92dd8a8cb
Child:
6:aaf432a6819b
Use one serial port only for now

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:bfed5767d0a5 1 /* Copyright (c) 2010-2012 mbed.org, MIT License
donatien 0:bfed5767d0a5 2 *
donatien 0:bfed5767d0a5 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
donatien 0:bfed5767d0a5 4 * and associated documentation files (the "Software"), to deal in the Software without
donatien 0:bfed5767d0a5 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
donatien 0:bfed5767d0a5 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
donatien 0:bfed5767d0a5 7 * Software is furnished to do so, subject to the following conditions:
donatien 0:bfed5767d0a5 8 *
donatien 0:bfed5767d0a5 9 * The above copyright notice and this permission notice shall be included in all copies or
donatien 0:bfed5767d0a5 10 * substantial portions of the Software.
donatien 0:bfed5767d0a5 11 *
donatien 0:bfed5767d0a5 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
donatien 0:bfed5767d0a5 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
donatien 0:bfed5767d0a5 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
donatien 0:bfed5767d0a5 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 0:bfed5767d0a5 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
donatien 0:bfed5767d0a5 17 */
donatien 0:bfed5767d0a5 18
donatien 3:9ec92dd8a8cb 19 #define __DEBUG__ 0
donatien 0:bfed5767d0a5 20 #ifndef __MODULE__
donatien 0:bfed5767d0a5 21 #define __MODULE__ "WANDongleInitializer.cpp"
donatien 0:bfed5767d0a5 22 #endif
donatien 0:bfed5767d0a5 23
donatien 0:bfed5767d0a5 24 #include "core/dbg.h"
donatien 0:bfed5767d0a5 25
donatien 0:bfed5767d0a5 26 #include <cstdint>
donatien 0:bfed5767d0a5 27 using std::uint16_t;
donatien 0:bfed5767d0a5 28
donatien 0:bfed5767d0a5 29 #include "WANDongleInitializer.h"
donatien 0:bfed5767d0a5 30
donatien 0:bfed5767d0a5 31 WANDongleInitializer::WANDongleInitializer(USBHost* pHost) : m_pHost(pHost)
donatien 0:bfed5767d0a5 32 {
donatien 0:bfed5767d0a5 33
donatien 0:bfed5767d0a5 34 }
donatien 0:bfed5767d0a5 35
donatien 0:bfed5767d0a5 36 WANDongleInitializer** WANDongleInitializer::getInitializers(USBHost* pHost)
donatien 0:bfed5767d0a5 37 {
donatien 0:bfed5767d0a5 38 static Sprint598UInitializer sprint598U(pHost);
donatien 0:bfed5767d0a5 39 const static WANDongleInitializer* list[] = { &sprint598U, NULL };
donatien 0:bfed5767d0a5 40 return (WANDongleInitializer**)list;
donatien 0:bfed5767d0a5 41 }
donatien 0:bfed5767d0a5 42
donatien 0:bfed5767d0a5 43 //Sierra Wireless 598U (Sprint)
donatien 0:bfed5767d0a5 44 Sprint598UInitializer::Sprint598UInitializer(USBHost* pHost) : WANDongleInitializer(pHost)
donatien 0:bfed5767d0a5 45 {
donatien 0:bfed5767d0a5 46
donatien 0:bfed5767d0a5 47 }
donatien 0:bfed5767d0a5 48
donatien 0:bfed5767d0a5 49 uint16_t Sprint598UInitializer::getMSDVid() { return 0x1199; }
donatien 0:bfed5767d0a5 50 uint16_t Sprint598UInitializer::getMSDPid() { return 0x0FFF; } //0x0f25?
donatien 0:bfed5767d0a5 51
donatien 0:bfed5767d0a5 52 uint16_t Sprint598UInitializer::getSerialVid() { return 0x1199; }
donatien 0:bfed5767d0a5 53 uint16_t Sprint598UInitializer::getSerialPid() { return 0x0025; }
donatien 0:bfed5767d0a5 54
donatien 0:bfed5767d0a5 55 bool Sprint598UInitializer::switchMode(USBDeviceConnected* pDev)
donatien 0:bfed5767d0a5 56 {
donatien 0:bfed5767d0a5 57 DBG("Device %p found, will now try to switch into serial mode", (void *)pDev);
donatien 0:bfed5767d0a5 58 m_pHost->controlWrite(pDev, /*requestType = */ 0x40, /*request = */ 0x0B, /*value = */ 0x00000001, /*index = */ 0, /*buf = */ NULL, /*len = */ 0);
donatien 0:bfed5767d0a5 59 return true;
donatien 0:bfed5767d0a5 60 }
donatien 0:bfed5767d0a5 61
donatien 1:3bcca949166d 62 USBEndpoint* Sprint598UInitializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx)
donatien 0:bfed5767d0a5 63 {
donatien 5:99f453c4756b 64 return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0);
donatien 0:bfed5767d0a5 65 }
donatien 0:bfed5767d0a5 66
donatien 0:bfed5767d0a5 67 int Sprint598UInitializer::getSerialPortCount()
donatien 0:bfed5767d0a5 68 {
donatien 5:99f453c4756b 69 return 1;
donatien 0:bfed5767d0a5 70 }
donatien 0:bfed5767d0a5 71
donatien 0:bfed5767d0a5 72 /*virtual*/ void Sprint598UInitializer::setVidPid(uint16_t vid, uint16_t pid)
donatien 0:bfed5767d0a5 73 {
donatien 0:bfed5767d0a5 74 if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) )
donatien 0:bfed5767d0a5 75 {
donatien 0:bfed5767d0a5 76 m_hasSwitched = true;
donatien 0:bfed5767d0a5 77 m_currentSerialIntf = 0;
donatien 5:99f453c4756b 78 m_endpointsToFetch = 2;
donatien 3:9ec92dd8a8cb 79 m_endpointsToSkip = 0;
donatien 0:bfed5767d0a5 80 }
donatien 0:bfed5767d0a5 81 else
donatien 0:bfed5767d0a5 82 {
donatien 0:bfed5767d0a5 83 m_hasSwitched = false;
donatien 0:bfed5767d0a5 84 m_endpointsToFetch = 0;
donatien 3:9ec92dd8a8cb 85 m_endpointsToSkip = 0;
donatien 0:bfed5767d0a5 86 }
donatien 0:bfed5767d0a5 87 }
donatien 0:bfed5767d0a5 88
donatien 0:bfed5767d0a5 89 /*virtual*/ bool Sprint598UInitializer::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
donatien 0:bfed5767d0a5 90 {
donatien 0:bfed5767d0a5 91 if( m_hasSwitched )
donatien 0:bfed5767d0a5 92 {
donatien 0:bfed5767d0a5 93 DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol);
donatien 2:34c976009b70 94 if( intf_class == 0xFF )
donatien 0:bfed5767d0a5 95 {
donatien 3:9ec92dd8a8cb 96 if( (m_currentSerialIntf == 0) )
donatien 0:bfed5767d0a5 97 {
donatien 0:bfed5767d0a5 98 m_currentSerialIntf++;
donatien 0:bfed5767d0a5 99 return true;
donatien 0:bfed5767d0a5 100 }
donatien 0:bfed5767d0a5 101 m_currentSerialIntf++;
donatien 0:bfed5767d0a5 102 }
donatien 0:bfed5767d0a5 103 }
donatien 0:bfed5767d0a5 104 return false;
donatien 0:bfed5767d0a5 105 }
donatien 0:bfed5767d0a5 106
donatien 0:bfed5767d0a5 107 /*virtual*/ bool Sprint598UInitializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
donatien 0:bfed5767d0a5 108 {
donatien 0:bfed5767d0a5 109 if( m_hasSwitched )
donatien 0:bfed5767d0a5 110 {
donatien 0:bfed5767d0a5 111 DBG("USBEndpoint on Interface #%d; Type:%d; Direction:%d", intf_nb, type, dir);
donatien 0:bfed5767d0a5 112 if( (type == BULK_ENDPOINT) && m_endpointsToFetch )
donatien 0:bfed5767d0a5 113 {
donatien 3:9ec92dd8a8cb 114 if(!m_endpointsToSkip)
donatien 3:9ec92dd8a8cb 115 {
donatien 3:9ec92dd8a8cb 116 m_endpointsToFetch--;
donatien 3:9ec92dd8a8cb 117 return true;
donatien 3:9ec92dd8a8cb 118 }
donatien 3:9ec92dd8a8cb 119 else
donatien 3:9ec92dd8a8cb 120 {
donatien 3:9ec92dd8a8cb 121 m_endpointsToSkip--;
donatien 3:9ec92dd8a8cb 122 }
donatien 0:bfed5767d0a5 123 }
donatien 0:bfed5767d0a5 124 }
donatien 0:bfed5767d0a5 125 return false;
donatien 0:bfed5767d0a5 126 }
donatien 0:bfed5767d0a5 127
donatien 0:bfed5767d0a5 128
donatien 0:bfed5767d0a5 129 /*virtual*/ WAN_DONGLE_TYPE Sprint598UInitializer::getType()
donatien 0:bfed5767d0a5 130 {
donatien 0:bfed5767d0a5 131 return WAN_DONGLE_TYPE_SPRINT598U;
donatien 0:bfed5767d0a5 132 }