modified by ohneta

Dependents:   HelloESP8266Interface_mine

Fork of NetworkSocketAPI by NetworkSocketAPI

NetworkInterface.h

Committer:
bridadan
Date:
2015-05-14
Revision:
1:291a9d61e58a
Parent:
0:d35446f60233
Child:
2:ce08986b18b5

File content as of revision 1:291a9d61e58a:

/* NetworkInterface Base Class
 * Copyright (c) 2015 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#ifndef NETWORKINTERFACE_H
#define NETWORKINTERFACE_H

/** NetworkInterface class.
 *   This is a common interface that is shared between all hardware that connect
 *   to a network over IP.
 */
class NetworkInterface {
 
public:

    /**
     *    Initialize the network interface with DHCP.
     *
     *    \returns 0 on success, a negative number on failure
     */
    virtual int init() = 0; 
    
    /**
     *    Initialize the network interface with a static IP address.
     *
     *    @param ip The static IP address to use
     *    @param mask The IP address mask
     *    @param gateway The gateway to use
     *
     *    \returns 0 on success, a negative number on failure
     */
    virtual int init(char* ip, char* mask, char *gateway) = 0;
    
    /**
     *    Start the interface, using DHCP if needed.
     *
     *    @param timeout_ms Time in miliseconds to wait while attempting to connect before timing out
     *
     *    \returns 0 on success, a negative number on failure
     */
    virtual int connect(unsigned int timeout_ms=15000) = 0;
    
    /**
     *    Start the interface, specifically for wifi based hardware, using DHCP if needed. This only needs to be implemented on wifi hardware.
     *
     *    @param ssid The SSID of the access point
     *    @param phrase The passphrase, if needed, to connect
     *    @param gateway The security type of the access point
     *
     *    \returns 0 on success, a negative number on failure
     */
    virtual int connect(char* ssid, char* phrase, char* security_type) = 0;
    
    /**
     *    Stop the interface, bringing down dhcp if necessary.
     *
     *    \returns 0 on success, a negative number on failure
     */
    virtual int disconnect() = 0;
    
    /**
     *    Get the current IP address.
     *
     *    \returns a pointer to a string containing the IP address.
     */
    virtual char* getIPAddress() = 0;
    
    /**
     *    Get the current gateway address.
     *
     *    \returns a pointer to a string containing the gateway address.
     */
    virtual char* getGateway() = 0;
    
    
    /**
     *    Get the current network mask.
     *
     *    \returns a pointer to a string containing the network mask.
     */
    virtual char* getNetworkMask() = 0;
    
    /**
     *    Get the current status of the interface connection.
     *
     *    \returns true if connected, false otherwise.
     */
    virtual bool isConnected(void) = 0;
};

#endif