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