modified by ohneta
Dependents: HelloESP8266Interface_mine
Fork of NetworkSocketAPI by
NetworkInterface.h@4:f09f0932db4a, 2015-05-31 (annotated)
- Committer:
- austin.blackstone@arm.com
- Date:
- Sun May 31 13:08:12 2015 -0500
- Revision:
- 4:f09f0932db4a
- Parent:
- 3:167dd63981b6
- Child:
- 5:fa54ca1af2cd
added WEP and WPA security types.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 0:d35446f60233 | 1 | /* NetworkInterface Base Class |
sam_grove | 0:d35446f60233 | 2 | * Copyright (c) 2015 ARM Limited |
sam_grove | 0:d35446f60233 | 3 | * |
sam_grove | 0:d35446f60233 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sam_grove | 0:d35446f60233 | 5 | * you may not use this file except in compliance with the License. |
sam_grove | 0:d35446f60233 | 6 | * You may obtain a copy of the License at |
sam_grove | 0:d35446f60233 | 7 | * |
sam_grove | 0:d35446f60233 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sam_grove | 0:d35446f60233 | 9 | * |
sam_grove | 0:d35446f60233 | 10 | * Unless required by applicable law or agreed to in writing, software |
sam_grove | 0:d35446f60233 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sam_grove | 0:d35446f60233 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sam_grove | 0:d35446f60233 | 13 | * See the License for the specific language governing permissions and |
sam_grove | 0:d35446f60233 | 14 | * limitations under the License. |
sam_grove | 0:d35446f60233 | 15 | */ |
sam_grove | 3:167dd63981b6 | 16 | |
bridadan | 1:291a9d61e58a | 17 | #ifndef NETWORKINTERFACE_H |
bridadan | 1:291a9d61e58a | 18 | #define NETWORKINTERFACE_H |
bridadan | 1:291a9d61e58a | 19 | |
bridadan | 1:291a9d61e58a | 20 | /** NetworkInterface class. |
bridadan | 1:291a9d61e58a | 21 | * This is a common interface that is shared between all hardware that connect |
bridadan | 1:291a9d61e58a | 22 | * to a network over IP. |
bridadan | 1:291a9d61e58a | 23 | */ |
sam_grove | 3:167dd63981b6 | 24 | class NetworkInterface |
sam_grove | 3:167dd63981b6 | 25 | { |
bridadan | 1:291a9d61e58a | 26 | public: |
austin.blackstone@arm.com | 4:f09f0932db4a | 27 | |
austin.blackstone@arm.com | 4:f09f0932db4a | 28 | /** |
austin.blackstone@arm.com | 4:f09f0932db4a | 29 | * |
austin.blackstone@arm.com | 4:f09f0932db4a | 30 | * |
austin.blackstone@arm.com | 4:f09f0932db4a | 31 | * |
austin.blackstone@arm.com | 4:f09f0932db4a | 32 | */ |
sam_grove | 3:167dd63981b6 | 33 | typedef enum { |
sam_grove | 3:167dd63981b6 | 34 | NI_NONE = 0, |
austin.blackstone@arm.com | 4:f09f0932db4a | 35 | NI_WEP, |
austin.blackstone@arm.com | 4:f09f0932db4a | 36 | NI_WPA, |
sam_grove | 3:167dd63981b6 | 37 | NI_WPA2, |
sam_grove | 3:167dd63981b6 | 38 | } ni_security_t; |
bridadan | 1:291a9d61e58a | 39 | |
bridadan | 1:291a9d61e58a | 40 | /** |
bridadan | 1:291a9d61e58a | 41 | * Initialize the network interface with DHCP. |
bridadan | 1:291a9d61e58a | 42 | * |
bridadan | 1:291a9d61e58a | 43 | * \returns 0 on success, a negative number on failure |
bridadan | 1:291a9d61e58a | 44 | */ |
sam_grove | 3:167dd63981b6 | 45 | virtual int init(void) const = 0; |
sam_grove | 3:167dd63981b6 | 46 | |
bridadan | 1:291a9d61e58a | 47 | /** |
bridadan | 1:291a9d61e58a | 48 | * Initialize the network interface with a static IP address. |
bridadan | 1:291a9d61e58a | 49 | * |
bridadan | 1:291a9d61e58a | 50 | * @param ip The static IP address to use |
bridadan | 1:291a9d61e58a | 51 | * @param mask The IP address mask |
bridadan | 1:291a9d61e58a | 52 | * @param gateway The gateway to use |
bridadan | 1:291a9d61e58a | 53 | * |
bridadan | 1:291a9d61e58a | 54 | * \returns 0 on success, a negative number on failure |
bridadan | 1:291a9d61e58a | 55 | */ |
sam_grove | 3:167dd63981b6 | 56 | int init(const char *ip, const char *mask, const char *gateway) const { |
sam_grove | 3:167dd63981b6 | 57 | return -1; |
sam_grove | 3:167dd63981b6 | 58 | } |
sam_grove | 3:167dd63981b6 | 59 | |
sam_grove | 3:167dd63981b6 | 60 | /** |
sam_grove | 3:167dd63981b6 | 61 | * Start the interface, using DHCP if needed. |
sam_grove | 3:167dd63981b6 | 62 | * |
sam_grove | 3:167dd63981b6 | 63 | * @param timeout_ms Time in miliseconds to wait while attempting to connect before timing out |
sam_grove | 3:167dd63981b6 | 64 | * |
sam_grove | 3:167dd63981b6 | 65 | * \returns 0 on success, a negative number on failure |
sam_grove | 3:167dd63981b6 | 66 | */ |
sam_grove | 3:167dd63981b6 | 67 | virtual int connect(const unsigned int timeout_ms=15000) const { |
sam_grove | 3:167dd63981b6 | 68 | return -1; |
sam_grove | 3:167dd63981b6 | 69 | } |
sam_grove | 3:167dd63981b6 | 70 | |
bridadan | 1:291a9d61e58a | 71 | /** |
bridadan | 1:291a9d61e58a | 72 | * Start the interface, using DHCP if needed. |
bridadan | 1:291a9d61e58a | 73 | * |
bridadan | 1:291a9d61e58a | 74 | * @param timeout_ms Time in miliseconds to wait while attempting to connect before timing out |
bridadan | 1:291a9d61e58a | 75 | * |
bridadan | 1:291a9d61e58a | 76 | * \returns 0 on success, a negative number on failure |
bridadan | 1:291a9d61e58a | 77 | */ |
sam_grove | 3:167dd63981b6 | 78 | virtual int connect(const char *ap, const char *pass_phrase = 0, const ni_security_t security = NI_NONE, const unsigned int timeout_ms=15000) const { |
sam_grove | 3:167dd63981b6 | 79 | return -1; |
sam_grove | 3:167dd63981b6 | 80 | } |
sam_grove | 3:167dd63981b6 | 81 | |
bridadan | 1:291a9d61e58a | 82 | /** |
bridadan | 1:291a9d61e58a | 83 | * Stop the interface, bringing down dhcp if necessary. |
bridadan | 1:291a9d61e58a | 84 | * |
bridadan | 1:291a9d61e58a | 85 | * \returns 0 on success, a negative number on failure |
bridadan | 1:291a9d61e58a | 86 | */ |
sam_grove | 3:167dd63981b6 | 87 | virtual int disconnect(void) const = 0; |
sam_grove | 3:167dd63981b6 | 88 | |
bridadan | 1:291a9d61e58a | 89 | /** |
bridadan | 1:291a9d61e58a | 90 | * Get the current IP address. |
bridadan | 1:291a9d61e58a | 91 | * |
bridadan | 1:291a9d61e58a | 92 | * \returns a pointer to a string containing the IP address. |
bridadan | 1:291a9d61e58a | 93 | */ |
sam_grove | 3:167dd63981b6 | 94 | virtual char *getIPAddress(void) const = 0; |
sam_grove | 3:167dd63981b6 | 95 | |
bridadan | 1:291a9d61e58a | 96 | /** |
bridadan | 1:291a9d61e58a | 97 | * Get the current gateway address. |
bridadan | 1:291a9d61e58a | 98 | * |
bridadan | 1:291a9d61e58a | 99 | * \returns a pointer to a string containing the gateway address. |
bridadan | 1:291a9d61e58a | 100 | */ |
sam_grove | 3:167dd63981b6 | 101 | virtual char *getGateway(void) const = 0; |
sam_grove | 3:167dd63981b6 | 102 | |
sam_grove | 3:167dd63981b6 | 103 | |
bridadan | 1:291a9d61e58a | 104 | /** |
bridadan | 1:291a9d61e58a | 105 | * Get the current network mask. |
bridadan | 1:291a9d61e58a | 106 | * |
bridadan | 1:291a9d61e58a | 107 | * \returns a pointer to a string containing the network mask. |
bridadan | 1:291a9d61e58a | 108 | */ |
sam_grove | 3:167dd63981b6 | 109 | virtual char *getNetworkMask(void) const = 0; |
sam_grove | 3:167dd63981b6 | 110 | |
sam_grove | 3:167dd63981b6 | 111 | /** |
sam_grove | 3:167dd63981b6 | 112 | * Get the devices MAC address. |
sam_grove | 3:167dd63981b6 | 113 | * |
sam_grove | 3:167dd63981b6 | 114 | * \returns a pointer to a string containing the mac address. |
sam_grove | 3:167dd63981b6 | 115 | */ |
sam_grove | 3:167dd63981b6 | 116 | virtual char *getMACAddress(void) const = 0; |
sam_grove | 3:167dd63981b6 | 117 | |
bridadan | 1:291a9d61e58a | 118 | /** |
bridadan | 1:291a9d61e58a | 119 | * Get the current status of the interface connection. |
bridadan | 1:291a9d61e58a | 120 | * |
bridadan | 1:291a9d61e58a | 121 | * \returns true if connected, false otherwise. |
bridadan | 1:291a9d61e58a | 122 | */ |
sam_grove | 3:167dd63981b6 | 123 | virtual int isConnected(void) const = 0; |
bridadan | 1:291a9d61e58a | 124 | }; |
bridadan | 1:291a9d61e58a | 125 | |
bridadan | 1:291a9d61e58a | 126 | #endif |