mbed-os
Fork of mbed-os by
features/FEATURE_LWIP/lwip-interface/EthernetInterface.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 | /* LWIP implementation of NetworkInterfaceAPI |
elessair | 0:f269e3021894 | 2 | * Copyright (c) 2015 ARM Limited |
elessair | 0:f269e3021894 | 3 | * |
elessair | 0:f269e3021894 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
elessair | 0:f269e3021894 | 5 | * you may not use this file except in compliance with the License. |
elessair | 0:f269e3021894 | 6 | * You may obtain a copy of the License at |
elessair | 0:f269e3021894 | 7 | * |
elessair | 0:f269e3021894 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
elessair | 0:f269e3021894 | 9 | * |
elessair | 0:f269e3021894 | 10 | * Unless required by applicable law or agreed to in writing, software |
elessair | 0:f269e3021894 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
elessair | 0:f269e3021894 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
elessair | 0:f269e3021894 | 13 | * See the License for the specific language governing permissions and |
elessair | 0:f269e3021894 | 14 | * limitations under the License. |
elessair | 0:f269e3021894 | 15 | */ |
elessair | 0:f269e3021894 | 16 | |
elessair | 0:f269e3021894 | 17 | #include "EthernetInterface.h" |
elessair | 0:f269e3021894 | 18 | #include "lwip_stack.h" |
elessair | 0:f269e3021894 | 19 | |
elessair | 0:f269e3021894 | 20 | |
elessair | 0:f269e3021894 | 21 | /* Interface implementation */ |
elessair | 0:f269e3021894 | 22 | EthernetInterface::EthernetInterface() |
elessair | 0:f269e3021894 | 23 | : _dhcp(true), _ip_address(), _netmask(), _gateway() |
elessair | 0:f269e3021894 | 24 | { |
elessair | 0:f269e3021894 | 25 | } |
elessair | 0:f269e3021894 | 26 | |
elessair | 0:f269e3021894 | 27 | int EthernetInterface::set_network(const char *ip_address, const char *netmask, const char *gateway) |
elessair | 0:f269e3021894 | 28 | { |
elessair | 0:f269e3021894 | 29 | _dhcp = false; |
elessair | 0:f269e3021894 | 30 | strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address)); |
elessair | 0:f269e3021894 | 31 | strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask)); |
elessair | 0:f269e3021894 | 32 | strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway)); |
elessair | 0:f269e3021894 | 33 | return 0; |
elessair | 0:f269e3021894 | 34 | } |
elessair | 0:f269e3021894 | 35 | |
elessair | 0:f269e3021894 | 36 | int EthernetInterface::set_dhcp(bool dhcp) |
elessair | 0:f269e3021894 | 37 | { |
elessair | 0:f269e3021894 | 38 | _dhcp = dhcp; |
elessair | 0:f269e3021894 | 39 | return 0; |
elessair | 0:f269e3021894 | 40 | } |
elessair | 0:f269e3021894 | 41 | |
elessair | 0:f269e3021894 | 42 | int EthernetInterface::connect() |
elessair | 0:f269e3021894 | 43 | { |
elessair | 0:f269e3021894 | 44 | return mbed_lwip_bringup(_dhcp, |
elessair | 0:f269e3021894 | 45 | _ip_address[0] ? _ip_address : 0, |
elessair | 0:f269e3021894 | 46 | _netmask[0] ? _netmask : 0, |
elessair | 0:f269e3021894 | 47 | _gateway[0] ? _gateway : 0); |
elessair | 0:f269e3021894 | 48 | } |
elessair | 0:f269e3021894 | 49 | |
elessair | 0:f269e3021894 | 50 | int EthernetInterface::disconnect() |
elessair | 0:f269e3021894 | 51 | { |
elessair | 0:f269e3021894 | 52 | return mbed_lwip_bringdown(); |
elessair | 0:f269e3021894 | 53 | } |
elessair | 0:f269e3021894 | 54 | |
elessair | 0:f269e3021894 | 55 | const char *EthernetInterface::get_mac_address() |
elessair | 0:f269e3021894 | 56 | { |
elessair | 0:f269e3021894 | 57 | return mbed_lwip_get_mac_address(); |
elessair | 0:f269e3021894 | 58 | } |
elessair | 0:f269e3021894 | 59 | |
elessair | 0:f269e3021894 | 60 | const char *EthernetInterface::get_ip_address() |
elessair | 0:f269e3021894 | 61 | { |
elessair | 0:f269e3021894 | 62 | if (mbed_lwip_get_ip_address(_ip_address, sizeof _ip_address)) { |
elessair | 0:f269e3021894 | 63 | return _ip_address; |
elessair | 0:f269e3021894 | 64 | } |
elessair | 0:f269e3021894 | 65 | |
elessair | 0:f269e3021894 | 66 | return 0; |
elessair | 0:f269e3021894 | 67 | } |
elessair | 0:f269e3021894 | 68 | |
elessair | 0:f269e3021894 | 69 | const char *EthernetInterface::get_netmask() |
elessair | 0:f269e3021894 | 70 | { |
elessair | 0:f269e3021894 | 71 | if (mbed_lwip_get_netmask(_netmask, sizeof _netmask)) { |
elessair | 0:f269e3021894 | 72 | return _netmask; |
elessair | 0:f269e3021894 | 73 | } |
elessair | 0:f269e3021894 | 74 | |
elessair | 0:f269e3021894 | 75 | return 0; |
elessair | 0:f269e3021894 | 76 | } |
elessair | 0:f269e3021894 | 77 | |
elessair | 0:f269e3021894 | 78 | const char *EthernetInterface::get_gateway() |
elessair | 0:f269e3021894 | 79 | { |
elessair | 0:f269e3021894 | 80 | if (mbed_lwip_get_gateway(_gateway, sizeof _gateway)) { |
elessair | 0:f269e3021894 | 81 | return _gateway; |
elessair | 0:f269e3021894 | 82 | } |
elessair | 0:f269e3021894 | 83 | |
elessair | 0:f269e3021894 | 84 | return 0; |
elessair | 0:f269e3021894 | 85 | } |
elessair | 0:f269e3021894 | 86 | |
elessair | 0:f269e3021894 | 87 | NetworkStack *EthernetInterface::get_stack() |
elessair | 0:f269e3021894 | 88 | { |
elessair | 0:f269e3021894 | 89 | return nsapi_create_stack(&lwip_stack); |
elessair | 0:f269e3021894 | 90 | } |