mbed-os
Fork of mbed-os by
features/unsupported/net/cellular/UbloxUSBModem/UbloxGSMModemInitializer.cpp@1:3deb71413561, 2017-07-20 (annotated)
- Committer:
- xuaner
- Date:
- Thu Jul 20 14:26:57 2017 +0000
- Revision:
- 1:3deb71413561
- Parent:
- 0:f269e3021894
mbed_os
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | /* Copyright (c) 2010-2012 mbed.org, MIT License |
elessair | 0:f269e3021894 | 2 | * |
elessair | 0:f269e3021894 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
elessair | 0:f269e3021894 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
elessair | 0:f269e3021894 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
elessair | 0:f269e3021894 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
elessair | 0:f269e3021894 | 7 | * Software is furnished to do so, subject to the following conditions: |
elessair | 0:f269e3021894 | 8 | * |
elessair | 0:f269e3021894 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
elessair | 0:f269e3021894 | 10 | * substantial portions of the Software. |
elessair | 0:f269e3021894 | 11 | * |
elessair | 0:f269e3021894 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
elessair | 0:f269e3021894 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
elessair | 0:f269e3021894 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
elessair | 0:f269e3021894 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
elessair | 0:f269e3021894 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
elessair | 0:f269e3021894 | 17 | */ |
elessair | 0:f269e3021894 | 18 | |
elessair | 0:f269e3021894 | 19 | #include "UbloxGSMModemInitializer.h" |
elessair | 0:f269e3021894 | 20 | #include "core/dbg.h" |
elessair | 0:f269e3021894 | 21 | |
elessair | 0:f269e3021894 | 22 | #define __DEBUG__ 0 |
elessair | 0:f269e3021894 | 23 | #ifndef __MODULE__ |
elessair | 0:f269e3021894 | 24 | #define __MODULE__ "UbloxGSMModemInitializer.cpp" |
elessair | 0:f269e3021894 | 25 | #endif |
elessair | 0:f269e3021894 | 26 | |
elessair | 0:f269e3021894 | 27 | //----------------------------------------------------------------------- |
elessair | 0:f269e3021894 | 28 | // mamm, u-blox Modem |
elessair | 0:f269e3021894 | 29 | //----------------------------------------------------------------------- |
elessair | 0:f269e3021894 | 30 | |
elessair | 0:f269e3021894 | 31 | UbloxGSMModemInitializer::UbloxGSMModemInitializer(USBHost* pHost) : WANDongleInitializer(pHost) |
elessair | 0:f269e3021894 | 32 | { |
elessair | 0:f269e3021894 | 33 | |
elessair | 0:f269e3021894 | 34 | } |
elessair | 0:f269e3021894 | 35 | |
elessair | 0:f269e3021894 | 36 | uint16_t UbloxGSMModemInitializer::getMSDVid() { return 0x1546; } |
elessair | 0:f269e3021894 | 37 | uint16_t UbloxGSMModemInitializer::getMSDPid() { return 0x0000; } |
elessair | 0:f269e3021894 | 38 | |
elessair | 0:f269e3021894 | 39 | uint16_t UbloxGSMModemInitializer::getSerialVid() { return 0x1546; } |
elessair | 0:f269e3021894 | 40 | uint16_t UbloxGSMModemInitializer::getSerialPid() { return 0x1102; } |
elessair | 0:f269e3021894 | 41 | |
elessair | 0:f269e3021894 | 42 | bool UbloxGSMModemInitializer::switchMode(USBDeviceConnected* pDev) |
elessair | 0:f269e3021894 | 43 | { |
elessair | 0:f269e3021894 | 44 | for (int i = 0; i < pDev->getNbIntf(); i++) |
elessair | 0:f269e3021894 | 45 | { |
elessair | 0:f269e3021894 | 46 | if (pDev->getInterface(i)->intf_class == MSD_CLASS) |
elessair | 0:f269e3021894 | 47 | { |
elessair | 0:f269e3021894 | 48 | USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT); |
elessair | 0:f269e3021894 | 49 | if ( pEp != NULL ) |
elessair | 0:f269e3021894 | 50 | { |
elessair | 0:f269e3021894 | 51 | ERR("MSD descriptor found on device %p, intf %d", (void *)pDev, i); |
elessair | 0:f269e3021894 | 52 | } |
elessair | 0:f269e3021894 | 53 | } |
elessair | 0:f269e3021894 | 54 | } |
elessair | 0:f269e3021894 | 55 | return false; |
elessair | 0:f269e3021894 | 56 | } |
elessair | 0:f269e3021894 | 57 | |
elessair | 0:f269e3021894 | 58 | #define UBX_SERIALCOUNT 7 |
elessair | 0:f269e3021894 | 59 | |
elessair | 0:f269e3021894 | 60 | int UbloxGSMModemInitializer::getSerialPortCount() |
elessair | 0:f269e3021894 | 61 | { |
elessair | 0:f269e3021894 | 62 | return UBX_SERIALCOUNT; |
elessair | 0:f269e3021894 | 63 | } |
elessair | 0:f269e3021894 | 64 | |
elessair | 0:f269e3021894 | 65 | /*virtual*/ void UbloxGSMModemInitializer::setVidPid(uint16_t vid, uint16_t pid) |
elessair | 0:f269e3021894 | 66 | { |
elessair | 0:f269e3021894 | 67 | if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) ) |
elessair | 0:f269e3021894 | 68 | { |
elessair | 0:f269e3021894 | 69 | m_hasSwitched = true; |
elessair | 0:f269e3021894 | 70 | m_currentSerialIntf = 0; |
elessair | 0:f269e3021894 | 71 | m_endpointsToFetch = UBX_SERIALCOUNT*2; |
elessair | 0:f269e3021894 | 72 | } |
elessair | 0:f269e3021894 | 73 | else |
elessair | 0:f269e3021894 | 74 | { |
elessair | 0:f269e3021894 | 75 | m_hasSwitched = false; |
elessair | 0:f269e3021894 | 76 | m_endpointsToFetch = 1; |
elessair | 0:f269e3021894 | 77 | } |
elessair | 0:f269e3021894 | 78 | } |
elessair | 0:f269e3021894 | 79 | |
elessair | 0:f269e3021894 | 80 | /*virtual*/ bool UbloxGSMModemInitializer::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 |
elessair | 0:f269e3021894 | 81 | { |
elessair | 0:f269e3021894 | 82 | if( m_hasSwitched ) |
elessair | 0:f269e3021894 | 83 | { |
elessair | 0:f269e3021894 | 84 | DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol); |
elessair | 0:f269e3021894 | 85 | if( intf_class == 0x0A ) |
elessair | 0:f269e3021894 | 86 | { |
elessair | 0:f269e3021894 | 87 | if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 1) ) |
elessair | 0:f269e3021894 | 88 | { |
elessair | 0:f269e3021894 | 89 | m_serialIntfMap[m_currentSerialIntf++] = intf_nb; |
elessair | 0:f269e3021894 | 90 | return true; |
elessair | 0:f269e3021894 | 91 | } |
elessair | 0:f269e3021894 | 92 | m_currentSerialIntf++; |
elessair | 0:f269e3021894 | 93 | } |
elessair | 0:f269e3021894 | 94 | } |
elessair | 0:f269e3021894 | 95 | else |
elessair | 0:f269e3021894 | 96 | { |
elessair | 0:f269e3021894 | 97 | if( (intf_nb == 0) && (intf_class == MSD_CLASS) ) |
elessair | 0:f269e3021894 | 98 | { |
elessair | 0:f269e3021894 | 99 | return true; |
elessair | 0:f269e3021894 | 100 | } |
elessair | 0:f269e3021894 | 101 | } |
elessair | 0:f269e3021894 | 102 | return false; |
elessair | 0:f269e3021894 | 103 | } |
elessair | 0:f269e3021894 | 104 | |
elessair | 0:f269e3021894 | 105 | /*virtual*/ bool UbloxGSMModemInitializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used |
elessair | 0:f269e3021894 | 106 | { |
elessair | 0:f269e3021894 | 107 | if( m_hasSwitched ) |
elessair | 0:f269e3021894 | 108 | { |
elessair | 0:f269e3021894 | 109 | DBG("USBEndpoint on Interface #%d; Type:%d; Direction:%d", intf_nb, type, dir); |
elessair | 0:f269e3021894 | 110 | if( (type == BULK_ENDPOINT) && m_endpointsToFetch ) |
elessair | 0:f269e3021894 | 111 | { |
elessair | 0:f269e3021894 | 112 | m_endpointsToFetch--; |
elessair | 0:f269e3021894 | 113 | return true; |
elessair | 0:f269e3021894 | 114 | } |
elessair | 0:f269e3021894 | 115 | } |
elessair | 0:f269e3021894 | 116 | else |
elessair | 0:f269e3021894 | 117 | { |
elessair | 0:f269e3021894 | 118 | if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch ) |
elessair | 0:f269e3021894 | 119 | { |
elessair | 0:f269e3021894 | 120 | m_endpointsToFetch--; |
elessair | 0:f269e3021894 | 121 | return true; |
elessair | 0:f269e3021894 | 122 | } |
elessair | 0:f269e3021894 | 123 | } |
elessair | 0:f269e3021894 | 124 | return false; |
elessair | 0:f269e3021894 | 125 | } |
elessair | 0:f269e3021894 | 126 | |
elessair | 0:f269e3021894 | 127 | /*virtual*/ int UbloxGSMModemInitializer::getType() |
elessair | 0:f269e3021894 | 128 | { |
elessair | 0:f269e3021894 | 129 | return WAN_DONGLE_TYPE_UBLOX_LISAU200; |
elessair | 0:f269e3021894 | 130 | } |
elessair | 0:f269e3021894 | 131 |