Bonjour/Zerconf library

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PPPNetIf.h Source File

PPPNetIf.h

00001 
00002 /*
00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014  
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 */
00023 
00024 //This is a NetServer-like backend for PPP, using lwIP
00025 
00026 #ifndef PPPNETIF_H
00027 #define PPPNETIF_H
00028 
00029 #include "mbed.h"
00030 
00031 //For now, only a GPRS Modem is supported, 
00032 //but we could easily split this class into a base class + two derived classes
00033 // (PPP over GPRS + PPP over Serial Modem)
00034 #include "drv/gprs/GPRSModem.h"
00035 #include "if/lwip/LwipNetIf.h"
00036 
00037 enum PPPErr
00038 {
00039   __PPP_MIN = -0xFFFF,
00040   PPP_MODEM, //ATErr returned
00041   PPP_NETWORK,
00042   PPP_PROTOCOL,
00043   PPP_CLOSED,
00044   PPP_OK = 0
00045 };
00046 
00047 enum PPPStatus
00048 {
00049   PPP_CONNECTING,
00050   PPP_CONNECTED,
00051   PPP_DISCONNECTED,
00052 };
00053 
00054 class PPPNetIf : public LwipNetIf
00055 {
00056 public:
00057   PPPNetIf(GPRSModem* pIf);
00058   virtual ~PPPNetIf();
00059   
00060   #if 0
00061   PPPErr open(Serial* pSerial);
00062   #endif
00063   
00064   PPPErr GPRSConnect(const char* apn, const char* userId, const char* password); //Connect using GPRS
00065   PPPErr ATConnect(const char* number); //Connect using a "classic" voice modem or GSM
00066   
00067   virtual void poll();
00068   
00069   PPPErr disconnect();
00070   
00071   #if 0
00072   PPPErr close();
00073   #endif
00074   
00075 protected:
00076   GPRSModem* m_pIf;
00077   
00078 private:
00079   void pppCallback(int errCode, void *arg);
00080   
00081   static void sPppCallback(void *ctx, int errCode, void *arg) //Callback from ppp.c
00082   { return ((PPPNetIf*)ctx)->pppCallback(errCode, arg); }
00083   
00084   bool m_connected;
00085   /*bool m_open;*/
00086   volatile PPPStatus m_status;
00087   volatile int m_fd; //PPP Session descriptor
00088   
00089   //int m_id;
00090   
00091   uint8_t* m_buf;
00092 
00093 };
00094 
00095 #endif