Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed-os/features/FEATURE_LWIP/lwip-interface/EthernetInterface.cpp@0:fb8047b156bb, 2020-01-15 (annotated)
- Committer:
- rahul_dahiya
- Date:
- Wed Jan 15 15:57:15 2020 +0530
- Revision:
- 0:fb8047b156bb
STM32F7 LWIP
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rahul_dahiya |
0:fb8047b156bb | 1 | /* LWIP implementation of NetworkInterfaceAPI |
| rahul_dahiya |
0:fb8047b156bb | 2 | * Copyright (c) 2015 ARM Limited |
| rahul_dahiya |
0:fb8047b156bb | 3 | * |
| rahul_dahiya |
0:fb8047b156bb | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| rahul_dahiya |
0:fb8047b156bb | 5 | * you may not use this file except in compliance with the License. |
| rahul_dahiya |
0:fb8047b156bb | 6 | * You may obtain a copy of the License at |
| rahul_dahiya |
0:fb8047b156bb | 7 | * |
| rahul_dahiya |
0:fb8047b156bb | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| rahul_dahiya |
0:fb8047b156bb | 9 | * |
| rahul_dahiya |
0:fb8047b156bb | 10 | * Unless required by applicable law or agreed to in writing, software |
| rahul_dahiya |
0:fb8047b156bb | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| rahul_dahiya |
0:fb8047b156bb | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| rahul_dahiya |
0:fb8047b156bb | 13 | * See the License for the specific language governing permissions and |
| rahul_dahiya |
0:fb8047b156bb | 14 | * limitations under the License. |
| rahul_dahiya |
0:fb8047b156bb | 15 | */ |
| rahul_dahiya |
0:fb8047b156bb | 16 | |
| rahul_dahiya |
0:fb8047b156bb | 17 | #include "EthernetInterface.h" |
| rahul_dahiya |
0:fb8047b156bb | 18 | #include "lwip_stack.h" |
| rahul_dahiya |
0:fb8047b156bb | 19 | |
| rahul_dahiya |
0:fb8047b156bb | 20 | |
| rahul_dahiya |
0:fb8047b156bb | 21 | /* Interface implementation */ |
| rahul_dahiya |
0:fb8047b156bb | 22 | EthernetInterface::EthernetInterface() |
| rahul_dahiya |
0:fb8047b156bb | 23 | : _dhcp(true), _ip_address(), _netmask(), _gateway() |
| rahul_dahiya |
0:fb8047b156bb | 24 | { |
| rahul_dahiya |
0:fb8047b156bb | 25 | } |
| rahul_dahiya |
0:fb8047b156bb | 26 | |
| rahul_dahiya |
0:fb8047b156bb | 27 | nsapi_error_t EthernetInterface::set_network(const char *ip_address, const char *netmask, const char *gateway) |
| rahul_dahiya |
0:fb8047b156bb | 28 | { |
| rahul_dahiya |
0:fb8047b156bb | 29 | _dhcp = false; |
| rahul_dahiya |
0:fb8047b156bb | 30 | |
| rahul_dahiya |
0:fb8047b156bb | 31 | strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address)); |
| rahul_dahiya |
0:fb8047b156bb | 32 | _ip_address[sizeof(_ip_address) - 1] = '\0'; |
| rahul_dahiya |
0:fb8047b156bb | 33 | strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask)); |
| rahul_dahiya |
0:fb8047b156bb | 34 | _netmask[sizeof(_netmask) - 1] = '\0'; |
| rahul_dahiya |
0:fb8047b156bb | 35 | strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway)); |
| rahul_dahiya |
0:fb8047b156bb | 36 | _gateway[sizeof(_gateway) - 1] = '\0'; |
| rahul_dahiya |
0:fb8047b156bb | 37 | |
| rahul_dahiya |
0:fb8047b156bb | 38 | return NSAPI_ERROR_OK; |
| rahul_dahiya |
0:fb8047b156bb | 39 | } |
| rahul_dahiya |
0:fb8047b156bb | 40 | |
| rahul_dahiya |
0:fb8047b156bb | 41 | nsapi_error_t EthernetInterface::set_dhcp(bool dhcp) |
| rahul_dahiya |
0:fb8047b156bb | 42 | { |
| rahul_dahiya |
0:fb8047b156bb | 43 | _dhcp = dhcp; |
| rahul_dahiya |
0:fb8047b156bb | 44 | return NSAPI_ERROR_OK; |
| rahul_dahiya |
0:fb8047b156bb | 45 | } |
| rahul_dahiya |
0:fb8047b156bb | 46 | |
| rahul_dahiya |
0:fb8047b156bb | 47 | nsapi_error_t EthernetInterface::connect() |
| rahul_dahiya |
0:fb8047b156bb | 48 | { |
| rahul_dahiya |
0:fb8047b156bb | 49 | return mbed_lwip_bringup_2(_dhcp, false, |
| rahul_dahiya |
0:fb8047b156bb | 50 | _ip_address[0] ? _ip_address : 0, |
| rahul_dahiya |
0:fb8047b156bb | 51 | _netmask[0] ? _netmask : 0, |
| rahul_dahiya |
0:fb8047b156bb | 52 | _gateway[0] ? _gateway : 0, |
| rahul_dahiya |
0:fb8047b156bb | 53 | DEFAULT_STACK); |
| rahul_dahiya |
0:fb8047b156bb | 54 | } |
| rahul_dahiya |
0:fb8047b156bb | 55 | |
| rahul_dahiya |
0:fb8047b156bb | 56 | nsapi_error_t EthernetInterface::disconnect() |
| rahul_dahiya |
0:fb8047b156bb | 57 | { |
| rahul_dahiya |
0:fb8047b156bb | 58 | return mbed_lwip_bringdown_2(false); |
| rahul_dahiya |
0:fb8047b156bb | 59 | } |
| rahul_dahiya |
0:fb8047b156bb | 60 | |
| rahul_dahiya |
0:fb8047b156bb | 61 | const char *EthernetInterface::get_mac_address() |
| rahul_dahiya |
0:fb8047b156bb | 62 | { |
| rahul_dahiya |
0:fb8047b156bb | 63 | return mbed_lwip_get_mac_address(); |
| rahul_dahiya |
0:fb8047b156bb | 64 | } |
| rahul_dahiya |
0:fb8047b156bb | 65 | |
| rahul_dahiya |
0:fb8047b156bb | 66 | const char *EthernetInterface::get_ip_address() |
| rahul_dahiya |
0:fb8047b156bb | 67 | { |
| rahul_dahiya |
0:fb8047b156bb | 68 | if (mbed_lwip_get_ip_address(_ip_address, sizeof _ip_address)) { |
| rahul_dahiya |
0:fb8047b156bb | 69 | return _ip_address; |
| rahul_dahiya |
0:fb8047b156bb | 70 | } |
| rahul_dahiya |
0:fb8047b156bb | 71 | |
| rahul_dahiya |
0:fb8047b156bb | 72 | return NULL; |
| rahul_dahiya |
0:fb8047b156bb | 73 | } |
| rahul_dahiya |
0:fb8047b156bb | 74 | |
| rahul_dahiya |
0:fb8047b156bb | 75 | const char *EthernetInterface::get_netmask() |
| rahul_dahiya |
0:fb8047b156bb | 76 | { |
| rahul_dahiya |
0:fb8047b156bb | 77 | if (mbed_lwip_get_netmask(_netmask, sizeof _netmask)) { |
| rahul_dahiya |
0:fb8047b156bb | 78 | return _netmask; |
| rahul_dahiya |
0:fb8047b156bb | 79 | } |
| rahul_dahiya |
0:fb8047b156bb | 80 | |
| rahul_dahiya |
0:fb8047b156bb | 81 | return 0; |
| rahul_dahiya |
0:fb8047b156bb | 82 | } |
| rahul_dahiya |
0:fb8047b156bb | 83 | |
| rahul_dahiya |
0:fb8047b156bb | 84 | const char *EthernetInterface::get_gateway() |
| rahul_dahiya |
0:fb8047b156bb | 85 | { |
| rahul_dahiya |
0:fb8047b156bb | 86 | if (mbed_lwip_get_gateway(_gateway, sizeof _gateway)) { |
| rahul_dahiya |
0:fb8047b156bb | 87 | return _gateway; |
| rahul_dahiya |
0:fb8047b156bb | 88 | } |
| rahul_dahiya |
0:fb8047b156bb | 89 | |
| rahul_dahiya |
0:fb8047b156bb | 90 | return 0; |
| rahul_dahiya |
0:fb8047b156bb | 91 | } |
| rahul_dahiya |
0:fb8047b156bb | 92 | |
| rahul_dahiya |
0:fb8047b156bb | 93 | NetworkStack *EthernetInterface::get_stack() |
| rahul_dahiya |
0:fb8047b156bb | 94 | { |
| rahul_dahiya |
0:fb8047b156bb | 95 | return nsapi_create_stack(&lwip_stack); |
| rahul_dahiya |
0:fb8047b156bb | 96 | } |