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