Committer:
mbed714
Date:
Tue Nov 09 19:32:44 2010 +0000
Revision:
3:0c324737064d
Parent:
0:98aadd37a5c5

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed714 0:98aadd37a5c5 1
mbed714 0:98aadd37a5c5 2 /*
mbed714 0:98aadd37a5c5 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
mbed714 0:98aadd37a5c5 4
mbed714 0:98aadd37a5c5 5 Permission is hereby granted, free of charge, to any person obtaining a copy
mbed714 0:98aadd37a5c5 6 of this software and associated documentation files (the "Software"), to deal
mbed714 0:98aadd37a5c5 7 in the Software without restriction, including without limitation the rights
mbed714 0:98aadd37a5c5 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mbed714 0:98aadd37a5c5 9 copies of the Software, and to permit persons to whom the Software is
mbed714 0:98aadd37a5c5 10 furnished to do so, subject to the following conditions:
mbed714 0:98aadd37a5c5 11
mbed714 0:98aadd37a5c5 12 The above copyright notice and this permission notice shall be included in
mbed714 0:98aadd37a5c5 13 all copies or substantial portions of the Software.
mbed714 0:98aadd37a5c5 14
mbed714 0:98aadd37a5c5 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mbed714 0:98aadd37a5c5 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mbed714 0:98aadd37a5c5 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mbed714 0:98aadd37a5c5 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mbed714 0:98aadd37a5c5 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed714 0:98aadd37a5c5 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mbed714 0:98aadd37a5c5 21 THE SOFTWARE.
mbed714 0:98aadd37a5c5 22 */
mbed714 0:98aadd37a5c5 23
mbed714 0:98aadd37a5c5 24 #include "netCfg.h"
mbed714 0:98aadd37a5c5 25 #if NET_UMTS
mbed714 0:98aadd37a5c5 26
mbed714 0:98aadd37a5c5 27 #include "UMTSStickNetIf.h"
mbed714 0:98aadd37a5c5 28
mbed714 0:98aadd37a5c5 29 #define __DEBUG
mbed714 0:98aadd37a5c5 30 #include "dbg/dbg.h"
mbed714 0:98aadd37a5c5 31
mbed714 0:98aadd37a5c5 32 UMTSStickNetIf::UMTSStickNetIf() : PPPNetIf(NULL), m_umtsStick(), m_pUsbSerial(NULL)
mbed714 0:98aadd37a5c5 33 {
mbed714 0:98aadd37a5c5 34 PPPNetIf::m_pIf = new GPRSModem();
mbed714 0:98aadd37a5c5 35 }
mbed714 0:98aadd37a5c5 36
mbed714 0:98aadd37a5c5 37 UMTSStickNetIf::~UMTSStickNetIf()
mbed714 0:98aadd37a5c5 38 {
mbed714 0:98aadd37a5c5 39 delete PPPNetIf::m_pIf;
mbed714 0:98aadd37a5c5 40 if(m_pUsbSerial)
mbed714 0:98aadd37a5c5 41 delete m_pUsbSerial;
mbed714 0:98aadd37a5c5 42 }
mbed714 0:98aadd37a5c5 43
mbed714 0:98aadd37a5c5 44 UMTSStickErr UMTSStickNetIf::setup() //UMTSStickErr is from /drv/umtsstick/UMTSStick.h
mbed714 0:98aadd37a5c5 45 {
mbed714 0:98aadd37a5c5 46 return m_umtsStick.getSerial(&m_pUsbSerial);
mbed714 0:98aadd37a5c5 47 }
mbed714 0:98aadd37a5c5 48
mbed714 0:98aadd37a5c5 49 PPPErr UMTSStickNetIf::connect(const char* apn /*= NULL*/, const char* userId /*= NULL*/, const char* password /*= NULL*/) //Connect using GPRS
mbed714 0:98aadd37a5c5 50 {
mbed714 0:98aadd37a5c5 51 if(!m_pUsbSerial)
mbed714 0:98aadd37a5c5 52 return PPP_MODEM;
mbed714 0:98aadd37a5c5 53
mbed714 0:98aadd37a5c5 54 ATErr atErr;
mbed714 0:98aadd37a5c5 55 for(int i=0; i<3; i++)
mbed714 0:98aadd37a5c5 56 {
mbed714 0:98aadd37a5c5 57 atErr = m_pIf->open(m_pUsbSerial); //3 tries
mbed714 0:98aadd37a5c5 58 if(!atErr)
mbed714 0:98aadd37a5c5 59 break;
mbed714 0:98aadd37a5c5 60 wait(4);
mbed714 0:98aadd37a5c5 61 }
mbed714 0:98aadd37a5c5 62
mbed714 0:98aadd37a5c5 63 if(atErr)
mbed714 0:98aadd37a5c5 64 return PPP_MODEM;
mbed714 0:98aadd37a5c5 65
mbed714 0:98aadd37a5c5 66 PPPErr pppErr;
mbed714 0:98aadd37a5c5 67 for(int i=0; i<3; i++)
mbed714 0:98aadd37a5c5 68 {
mbed714 0:98aadd37a5c5 69 pppErr = PPPNetIf::GPRSConnect(apn, userId, password);
mbed714 0:98aadd37a5c5 70 if(!pppErr)
mbed714 0:98aadd37a5c5 71 break;
mbed714 0:98aadd37a5c5 72 wait(4);
mbed714 0:98aadd37a5c5 73 }
mbed714 0:98aadd37a5c5 74 if(pppErr)
mbed714 0:98aadd37a5c5 75 return pppErr;
mbed714 0:98aadd37a5c5 76
mbed714 0:98aadd37a5c5 77 return PPP_OK;
mbed714 0:98aadd37a5c5 78 }
mbed714 0:98aadd37a5c5 79
mbed714 0:98aadd37a5c5 80 PPPErr UMTSStickNetIf::disconnect()
mbed714 0:98aadd37a5c5 81 {
mbed714 0:98aadd37a5c5 82 PPPErr pppErr = PPPNetIf::disconnect();
mbed714 0:98aadd37a5c5 83 if(pppErr)
mbed714 0:98aadd37a5c5 84 return pppErr;
mbed714 0:98aadd37a5c5 85
mbed714 0:98aadd37a5c5 86 m_pIf->close();
mbed714 0:98aadd37a5c5 87
mbed714 0:98aadd37a5c5 88 return PPP_OK;
mbed714 0:98aadd37a5c5 89 }
mbed714 0:98aadd37a5c5 90
mbed714 0:98aadd37a5c5 91
mbed714 0:98aadd37a5c5 92 #endif