takashi kadono / Mbed OS Nucleo446_SSD1331

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Wed Oct 10 00:33:53 2018 +0000
Revision:
0:8fdf9a60065b
how to make mbed librry

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kadonotakashi 0:8fdf9a60065b 1 /* mbed OS IP stack API
kadonotakashi 0:8fdf9a60065b 2 * Copyright (c) 2015-2017 ARM Limited
kadonotakashi 0:8fdf9a60065b 3 *
kadonotakashi 0:8fdf9a60065b 4 * Licensed under the Apache License, Version 2.0 (the "License");
kadonotakashi 0:8fdf9a60065b 5 * you may not use this file except in compliance with the License.
kadonotakashi 0:8fdf9a60065b 6 * You may obtain a copy of the License at
kadonotakashi 0:8fdf9a60065b 7 *
kadonotakashi 0:8fdf9a60065b 8 * http://www.apache.org/licenses/LICENSE-2.0
kadonotakashi 0:8fdf9a60065b 9 *
kadonotakashi 0:8fdf9a60065b 10 * Unless required by applicable law or agreed to in writing, software
kadonotakashi 0:8fdf9a60065b 11 * distributed under the License is distributed on an "AS IS" BASIS,
kadonotakashi 0:8fdf9a60065b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kadonotakashi 0:8fdf9a60065b 13 * See the License for the specific language governing permissions and
kadonotakashi 0:8fdf9a60065b 14 * limitations under the License.
kadonotakashi 0:8fdf9a60065b 15 */
kadonotakashi 0:8fdf9a60065b 16
kadonotakashi 0:8fdf9a60065b 17 #ifndef MBED_IPSTACK_H
kadonotakashi 0:8fdf9a60065b 18 #define MBED_IPSTACK_H
kadonotakashi 0:8fdf9a60065b 19
kadonotakashi 0:8fdf9a60065b 20 #include "nsapi.h"
kadonotakashi 0:8fdf9a60065b 21
kadonotakashi 0:8fdf9a60065b 22 #include "NetworkStack.h"
kadonotakashi 0:8fdf9a60065b 23 #include "EMAC.h"
kadonotakashi 0:8fdf9a60065b 24
kadonotakashi 0:8fdf9a60065b 25 /**
kadonotakashi 0:8fdf9a60065b 26 * mbed OS API for onboard IP stack abstraction
kadonotakashi 0:8fdf9a60065b 27 *
kadonotakashi 0:8fdf9a60065b 28 * This interface should be used by targets to initialize IP stack, create, bring up and bring down network interfaces.
kadonotakashi 0:8fdf9a60065b 29 *
kadonotakashi 0:8fdf9a60065b 30 * An onboard network stack has the potential ability to register interfaces
kadonotakashi 0:8fdf9a60065b 31 * such as through EMAC, and has its own interface identifiers.
kadonotakashi 0:8fdf9a60065b 32 */
kadonotakashi 0:8fdf9a60065b 33 class OnboardNetworkStack : public NetworkStack {
kadonotakashi 0:8fdf9a60065b 34 public:
kadonotakashi 0:8fdf9a60065b 35 /** Return the default on-board network stack
kadonotakashi 0:8fdf9a60065b 36 *
kadonotakashi 0:8fdf9a60065b 37 * Returns the default on-board network stack, as configured by
kadonotakashi 0:8fdf9a60065b 38 * JSON option nsapi.default-stack.
kadonotakashi 0:8fdf9a60065b 39 */
kadonotakashi 0:8fdf9a60065b 40 static OnboardNetworkStack &get_default_instance();
kadonotakashi 0:8fdf9a60065b 41
kadonotakashi 0:8fdf9a60065b 42 /** Representation of a stack's view of an interface.
kadonotakashi 0:8fdf9a60065b 43 *
kadonotakashi 0:8fdf9a60065b 44 * Provides facilities required by a driver to implement the application
kadonotakashi 0:8fdf9a60065b 45 * NetworkInterface API.
kadonotakashi 0:8fdf9a60065b 46 */
kadonotakashi 0:8fdf9a60065b 47 class Interface {
kadonotakashi 0:8fdf9a60065b 48 public:
kadonotakashi 0:8fdf9a60065b 49 virtual ~Interface() {}
kadonotakashi 0:8fdf9a60065b 50
kadonotakashi 0:8fdf9a60065b 51 /** Connect the interface to the network
kadonotakashi 0:8fdf9a60065b 52 *
kadonotakashi 0:8fdf9a60065b 53 * Sets up a connection on specified network interface, using DHCP or provided network details. If the @a dhcp is set to
kadonotakashi 0:8fdf9a60065b 54 * true all the remaining parameters are ignored.
kadonotakashi 0:8fdf9a60065b 55 *
kadonotakashi 0:8fdf9a60065b 56 * @param dhcp true if the network details should be acquired using DHCP
kadonotakashi 0:8fdf9a60065b 57 * @param ip IP address to be used for the interface as "W:X:Y:Z" or NULL
kadonotakashi 0:8fdf9a60065b 58 * @param netmask Net mask to be used for the interface as "W:X:Y:Z" or NULL
kadonotakashi 0:8fdf9a60065b 59 * @param gw Gateway address to be used for the interface as "W:X:Y:Z" or NULL
kadonotakashi 0:8fdf9a60065b 60 * @param stack Allow manual selection of IPv4 and/or IPv6.
kadonotakashi 0:8fdf9a60065b 61 * @param blocking Specify whether bringup blocks for connection completion.
kadonotakashi 0:8fdf9a60065b 62 * @return NSAPI_ERROR_OK on success, or error code
kadonotakashi 0:8fdf9a60065b 63 */
kadonotakashi 0:8fdf9a60065b 64 virtual nsapi_error_t bringup(bool dhcp, const char *ip,
kadonotakashi 0:8fdf9a60065b 65 const char *netmask, const char *gw,
kadonotakashi 0:8fdf9a60065b 66 nsapi_ip_stack_t stack = DEFAULT_STACK,
kadonotakashi 0:8fdf9a60065b 67 bool blocking = true) = 0;
kadonotakashi 0:8fdf9a60065b 68
kadonotakashi 0:8fdf9a60065b 69 /** Disconnect interface from the network
kadonotakashi 0:8fdf9a60065b 70 *
kadonotakashi 0:8fdf9a60065b 71 * After this call the network interface is inactive, to use it again user needs to call @n bringup again.
kadonotakashi 0:8fdf9a60065b 72 *
kadonotakashi 0:8fdf9a60065b 73 * @return NSAPI_ERROR_OK on success, or error code
kadonotakashi 0:8fdf9a60065b 74 */
kadonotakashi 0:8fdf9a60065b 75 virtual nsapi_error_t bringdown() = 0;
kadonotakashi 0:8fdf9a60065b 76
kadonotakashi 0:8fdf9a60065b 77 /** Register callback for status reporting
kadonotakashi 0:8fdf9a60065b 78 *
kadonotakashi 0:8fdf9a60065b 79 * The specified status callback function will be called on status changes
kadonotakashi 0:8fdf9a60065b 80 * on the network. The parameters on the callback are the event type and
kadonotakashi 0:8fdf9a60065b 81 * event-type dependent reason parameter.
kadonotakashi 0:8fdf9a60065b 82 *
kadonotakashi 0:8fdf9a60065b 83 * @param status_cb The callback for status changes
kadonotakashi 0:8fdf9a60065b 84 */
kadonotakashi 0:8fdf9a60065b 85 virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) = 0;
kadonotakashi 0:8fdf9a60065b 86
kadonotakashi 0:8fdf9a60065b 87 /** Get the connection status
kadonotakashi 0:8fdf9a60065b 88 *
kadonotakashi 0:8fdf9a60065b 89 * @return The connection status according to ConnectionStatusType
kadonotakashi 0:8fdf9a60065b 90 */
kadonotakashi 0:8fdf9a60065b 91 virtual nsapi_connection_status_t get_connection_status() const = 0;
kadonotakashi 0:8fdf9a60065b 92
kadonotakashi 0:8fdf9a60065b 93 /** Return MAC address of the network interface
kadonotakashi 0:8fdf9a60065b 94 *
kadonotakashi 0:8fdf9a60065b 95 * @return MAC address as "V:W:X:Y:Z"
kadonotakashi 0:8fdf9a60065b 96 */
kadonotakashi 0:8fdf9a60065b 97 virtual char *get_mac_address(char *buf, nsapi_size_t buflen) = 0;
kadonotakashi 0:8fdf9a60065b 98
kadonotakashi 0:8fdf9a60065b 99 /** Copies IP address of the network interface to user supplied buffer
kadonotakashi 0:8fdf9a60065b 100 *
kadonotakashi 0:8fdf9a60065b 101 * @param buf buffer to which IP address will be copied as "W:X:Y:Z"
kadonotakashi 0:8fdf9a60065b 102 * @param buflen size of supplied buffer
kadonotakashi 0:8fdf9a60065b 103 * @return Pointer to a buffer, or NULL if the buffer is too small
kadonotakashi 0:8fdf9a60065b 104 */
kadonotakashi 0:8fdf9a60065b 105 virtual char *get_ip_address(char *buf, nsapi_size_t buflen) = 0;
kadonotakashi 0:8fdf9a60065b 106
kadonotakashi 0:8fdf9a60065b 107 /** Copies netmask of the network interface to user supplied buffer
kadonotakashi 0:8fdf9a60065b 108 *
kadonotakashi 0:8fdf9a60065b 109 * @param buf buffer to which netmask will be copied as "W:X:Y:Z"
kadonotakashi 0:8fdf9a60065b 110 * @param buflen size of supplied buffer
kadonotakashi 0:8fdf9a60065b 111 * @return Pointer to a buffer, or NULL if the buffer is too small
kadonotakashi 0:8fdf9a60065b 112 */
kadonotakashi 0:8fdf9a60065b 113 virtual char *get_netmask(char *buf, nsapi_size_t buflen) = 0;
kadonotakashi 0:8fdf9a60065b 114
kadonotakashi 0:8fdf9a60065b 115 /** Copies gateway address of the network interface to user supplied buffer
kadonotakashi 0:8fdf9a60065b 116 *
kadonotakashi 0:8fdf9a60065b 117 * @param buf buffer to which gateway address will be copied as "W:X:Y:Z"
kadonotakashi 0:8fdf9a60065b 118 * @param buflen size of supplied buffer
kadonotakashi 0:8fdf9a60065b 119 * @return Pointer to a buffer, or NULL if the buffer is too small
kadonotakashi 0:8fdf9a60065b 120 */
kadonotakashi 0:8fdf9a60065b 121 virtual char *get_gateway(char *buf, nsapi_size_t buflen) = 0;
kadonotakashi 0:8fdf9a60065b 122 };
kadonotakashi 0:8fdf9a60065b 123
kadonotakashi 0:8fdf9a60065b 124 /** Register a network interface with the IP stack
kadonotakashi 0:8fdf9a60065b 125 *
kadonotakashi 0:8fdf9a60065b 126 * Connects EMAC layer with the IP stack and initializes all the required infrastructure.
kadonotakashi 0:8fdf9a60065b 127 * This function should be called only once for each available interface. EMAC memory
kadonotakashi 0:8fdf9a60065b 128 * manager is available to EMAC after this function call.
kadonotakashi 0:8fdf9a60065b 129 *
kadonotakashi 0:8fdf9a60065b 130 * @param emac EMAC HAL implementation for this network interface
kadonotakashi 0:8fdf9a60065b 131 * @param default_if true if the interface should be treated as the default one
kadonotakashi 0:8fdf9a60065b 132 * @param[out] interface_out pointer to stack interface object controlling the EMAC
kadonotakashi 0:8fdf9a60065b 133 * @return NSAPI_ERROR_OK on success, or error code
kadonotakashi 0:8fdf9a60065b 134 */
kadonotakashi 0:8fdf9a60065b 135 virtual nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, Interface **interface_out) = 0;
kadonotakashi 0:8fdf9a60065b 136 };
kadonotakashi 0:8fdf9a60065b 137
kadonotakashi 0:8fdf9a60065b 138 #endif /* MBED_IPSTACK_H */