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.
emac_TestNetworkStack.cpp
00001 /* 00002 * Copyright (c) 2018, ARM Limited, All Rights Reserved 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00006 * not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #if MBED_CONF_APP_TEST_WIFI || MBED_CONF_APP_TEST_ETHERNET 00019 00020 #include "unity.h" 00021 00022 #include "EMACMemoryManager.h" 00023 #include "emac_TestNetworkStack.h" 00024 #include "emac_initialize.h" 00025 00026 EmacTestNetworkStack::EmacTestNetworkStack() 00027 : m_interface(NULL) 00028 { 00029 00030 } 00031 00032 nsapi_error_t EmacTestNetworkStack::gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version) 00033 { 00034 return NSAPI_ERROR_OK ; 00035 } 00036 00037 nsapi_error_t EmacTestNetworkStack::add_dns_server(const SocketAddress &address) 00038 { 00039 return NSAPI_ERROR_OK ; 00040 } 00041 00042 nsapi_error_t EmacTestNetworkStack::call_in(int delay, mbed::Callback<void()> func) 00043 { 00044 // Implemented as empty to save memory 00045 return NSAPI_ERROR_DEVICE_ERROR ; 00046 } 00047 00048 EmacTestNetworkStack::call_in_callback_cb_t EmacTestNetworkStack::get_call_in_callback() 00049 { 00050 call_in_callback_cb_t cb(this, &EmacTestNetworkStack::call_in); 00051 return cb; 00052 } 00053 00054 nsapi_error_t EmacTestNetworkStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) 00055 { 00056 return NSAPI_ERROR_OK ; 00057 } 00058 00059 nsapi_error_t EmacTestNetworkStack::socket_close(nsapi_socket_t handle) 00060 { 00061 return NSAPI_ERROR_OK ; 00062 } 00063 00064 nsapi_error_t EmacTestNetworkStack::socket_bind(nsapi_socket_t handle, const SocketAddress &address) 00065 { 00066 return NSAPI_ERROR_OK ; 00067 } 00068 00069 nsapi_error_t EmacTestNetworkStack::socket_listen(nsapi_socket_t handle, int backlog) 00070 { 00071 return NSAPI_ERROR_OK ; 00072 } 00073 00074 nsapi_error_t EmacTestNetworkStack::socket_connect(nsapi_socket_t handle, const SocketAddress &address) 00075 { 00076 return NSAPI_ERROR_OK ; 00077 } 00078 00079 nsapi_error_t EmacTestNetworkStack::socket_accept(nsapi_socket_t server, nsapi_socket_t *handle, SocketAddress *address) 00080 { 00081 return NSAPI_ERROR_OK ; 00082 } 00083 00084 nsapi_size_or_error_t EmacTestNetworkStack::socket_send(nsapi_socket_t handle, const void *data, nsapi_size_t size) 00085 { 00086 return NSAPI_ERROR_OK ; 00087 } 00088 00089 nsapi_size_or_error_t EmacTestNetworkStack::socket_recv(nsapi_socket_t handle, void *data, nsapi_size_t size) 00090 { 00091 return NSAPI_ERROR_OK ; 00092 } 00093 00094 nsapi_size_or_error_t EmacTestNetworkStack::socket_sendto(nsapi_socket_t handle, const SocketAddress &address, const void *data, nsapi_size_t size) 00095 { 00096 return size; 00097 } 00098 00099 nsapi_size_or_error_t EmacTestNetworkStack::socket_recvfrom(nsapi_socket_t handle, SocketAddress *address, void *data, nsapi_size_t size) 00100 { 00101 return NSAPI_ERROR_DEVICE_ERROR ; 00102 } 00103 00104 nsapi_error_t EmacTestNetworkStack::setsockopt(nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen) 00105 { 00106 return NSAPI_ERROR_OK ; 00107 } 00108 00109 nsapi_error_t EmacTestNetworkStack::getsockopt(nsapi_socket_t handle, int level, int optname, void *optval, unsigned *optlen) 00110 { 00111 return NSAPI_ERROR_OK ; 00112 } 00113 00114 void EmacTestNetworkStack::socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) 00115 { 00116 00117 } 00118 00119 nsapi_error_t EmacTestNetworkStack::add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out) 00120 { 00121 // Test network stack supports only one interface 00122 TEST_ASSERT_MESSAGE(!m_interface, "Only one interface supported!"); 00123 00124 m_interface = &EmacTestNetworkStack::Interface::get_instance(); 00125 TEST_ASSERT_MESSAGE(m_interface, "Invalid interface!"); 00126 00127 m_interface->m_emac = &emac; 00128 00129 EmacTestMemoryManager *memory_manager = &EmacTestMemoryManager::get_instance(); 00130 emac.set_memory_manager(*memory_manager); 00131 00132 *interface_out = m_interface; 00133 00134 return NSAPI_ERROR_OK ; 00135 } 00136 00137 EmacTestNetworkStack::Interface::Interface() 00138 : m_emac(NULL) 00139 { 00140 00141 } 00142 00143 00144 void EmacTestNetworkStack::Interface::attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) 00145 { 00146 00147 } 00148 00149 nsapi_connection_status_t EmacTestNetworkStack::Interface::get_connection_status() const 00150 { 00151 return NSAPI_STATUS_ERROR_UNSUPPORTED; 00152 } 00153 00154 char *EmacTestNetworkStack::Interface::get_mac_address(char *buf, nsapi_size_t buflen) 00155 { 00156 return NULL; 00157 } 00158 00159 char *EmacTestNetworkStack::Interface::get_ip_address(char *buf, nsapi_size_t buflen) 00160 { 00161 return NULL; 00162 } 00163 00164 char *EmacTestNetworkStack::Interface::get_netmask(char *buf, nsapi_size_t buflen) 00165 { 00166 return NULL; 00167 } 00168 00169 char *EmacTestNetworkStack::Interface::get_gateway(char *buf, nsapi_size_t buflen) 00170 { 00171 return NULL; 00172 } 00173 00174 nsapi_error_t EmacTestNetworkStack::Interface::bringup(bool dhcp, const char *ip, const char *netmask, const char *gw, const nsapi_ip_stack_t stack, bool blocking) 00175 { 00176 if (!emac_if_init(m_emac)) { 00177 TEST_ASSERT_MESSAGE(0, "emac initialization failed!"); 00178 } 00179 00180 return NSAPI_ERROR_OK ; 00181 } 00182 00183 nsapi_error_t EmacTestNetworkStack::Interface::bringdown() 00184 { 00185 return NSAPI_ERROR_OK ; 00186 } 00187 00188 EmacTestNetworkStack::Interface &EmacTestNetworkStack::Interface::get_instance() 00189 { 00190 static EmacTestNetworkStack::Interface test_interface; 00191 return test_interface; 00192 } 00193 00194 EmacTestNetworkStack &EmacTestNetworkStack::get_instance() 00195 { 00196 static EmacTestNetworkStack test_stack; 00197 return test_stack; 00198 } 00199 00200 #define TEST 0x33254234 00201 #if MBED_CONF_NSAPI_DEFAULT_STACK == TEST 00202 #undef TEST 00203 OnboardNetworkStack &OnboardNetworkStack::get_default_instance() 00204 { 00205 return EmacTestNetworkStack::get_instance(); 00206 } 00207 #endif 00208 00209 #endif
Generated on Tue Jul 12 2022 12:43:53 by
1.7.2