fdsf

Dependents:   sisk_proj_stat MQTT Hello_FXOS8700Q WireFSHandControl ... more

Committer:
grzemich
Date:
Wed Dec 07 23:47:50 2016 +0000
Revision:
0:d7bd7384a37c
dgd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
grzemich 0:d7bd7384a37c 1 /**
grzemich 0:d7bd7384a37c 2 * @file
grzemich 0:d7bd7384a37c 3 * Network Interface Sequential API module
grzemich 0:d7bd7384a37c 4 *
grzemich 0:d7bd7384a37c 5 */
grzemich 0:d7bd7384a37c 6
grzemich 0:d7bd7384a37c 7 /*
grzemich 0:d7bd7384a37c 8 * Redistribution and use in source and binary forms, with or without modification,
grzemich 0:d7bd7384a37c 9 * are permitted provided that the following conditions are met:
grzemich 0:d7bd7384a37c 10 *
grzemich 0:d7bd7384a37c 11 * 1. Redistributions of source code must retain the above copyright notice,
grzemich 0:d7bd7384a37c 12 * this list of conditions and the following disclaimer.
grzemich 0:d7bd7384a37c 13 * 2. Redistributions in binary form must reproduce the above copyright notice,
grzemich 0:d7bd7384a37c 14 * this list of conditions and the following disclaimer in the documentation
grzemich 0:d7bd7384a37c 15 * and/or other materials provided with the distribution.
grzemich 0:d7bd7384a37c 16 * 3. The name of the author may not be used to endorse or promote products
grzemich 0:d7bd7384a37c 17 * derived from this software without specific prior written permission.
grzemich 0:d7bd7384a37c 18 *
grzemich 0:d7bd7384a37c 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
grzemich 0:d7bd7384a37c 20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
grzemich 0:d7bd7384a37c 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
grzemich 0:d7bd7384a37c 22 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
grzemich 0:d7bd7384a37c 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
grzemich 0:d7bd7384a37c 24 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
grzemich 0:d7bd7384a37c 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
grzemich 0:d7bd7384a37c 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
grzemich 0:d7bd7384a37c 27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
grzemich 0:d7bd7384a37c 28 * OF SUCH DAMAGE.
grzemich 0:d7bd7384a37c 29 *
grzemich 0:d7bd7384a37c 30 * This file is part of the lwIP TCP/IP stack.
grzemich 0:d7bd7384a37c 31 *
grzemich 0:d7bd7384a37c 32 */
grzemich 0:d7bd7384a37c 33
grzemich 0:d7bd7384a37c 34 #include "lwip/opt.h"
grzemich 0:d7bd7384a37c 35
grzemich 0:d7bd7384a37c 36 #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */
grzemich 0:d7bd7384a37c 37
grzemich 0:d7bd7384a37c 38 #include "lwip/netifapi.h"
grzemich 0:d7bd7384a37c 39 #include "lwip/tcpip.h"
grzemich 0:d7bd7384a37c 40
grzemich 0:d7bd7384a37c 41 /**
grzemich 0:d7bd7384a37c 42 * Call netif_add() inside the tcpip_thread context.
grzemich 0:d7bd7384a37c 43 */
grzemich 0:d7bd7384a37c 44 void
grzemich 0:d7bd7384a37c 45 do_netifapi_netif_add(struct netifapi_msg_msg *msg)
grzemich 0:d7bd7384a37c 46 {
grzemich 0:d7bd7384a37c 47 if (!netif_add( msg->netif,
grzemich 0:d7bd7384a37c 48 msg->msg.add.ipaddr,
grzemich 0:d7bd7384a37c 49 msg->msg.add.netmask,
grzemich 0:d7bd7384a37c 50 msg->msg.add.gw,
grzemich 0:d7bd7384a37c 51 msg->msg.add.state,
grzemich 0:d7bd7384a37c 52 msg->msg.add.init,
grzemich 0:d7bd7384a37c 53 msg->msg.add.input)) {
grzemich 0:d7bd7384a37c 54 msg->err = ERR_IF;
grzemich 0:d7bd7384a37c 55 } else {
grzemich 0:d7bd7384a37c 56 msg->err = ERR_OK;
grzemich 0:d7bd7384a37c 57 }
grzemich 0:d7bd7384a37c 58 TCPIP_NETIFAPI_ACK(msg);
grzemich 0:d7bd7384a37c 59 }
grzemich 0:d7bd7384a37c 60
grzemich 0:d7bd7384a37c 61 /**
grzemich 0:d7bd7384a37c 62 * Call netif_set_addr() inside the tcpip_thread context.
grzemich 0:d7bd7384a37c 63 */
grzemich 0:d7bd7384a37c 64 void
grzemich 0:d7bd7384a37c 65 do_netifapi_netif_set_addr(struct netifapi_msg_msg *msg)
grzemich 0:d7bd7384a37c 66 {
grzemich 0:d7bd7384a37c 67 netif_set_addr( msg->netif,
grzemich 0:d7bd7384a37c 68 msg->msg.add.ipaddr,
grzemich 0:d7bd7384a37c 69 msg->msg.add.netmask,
grzemich 0:d7bd7384a37c 70 msg->msg.add.gw);
grzemich 0:d7bd7384a37c 71 msg->err = ERR_OK;
grzemich 0:d7bd7384a37c 72 TCPIP_NETIFAPI_ACK(msg);
grzemich 0:d7bd7384a37c 73 }
grzemich 0:d7bd7384a37c 74
grzemich 0:d7bd7384a37c 75 /**
grzemich 0:d7bd7384a37c 76 * Call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) inside the
grzemich 0:d7bd7384a37c 77 * tcpip_thread context.
grzemich 0:d7bd7384a37c 78 */
grzemich 0:d7bd7384a37c 79 void
grzemich 0:d7bd7384a37c 80 do_netifapi_netif_common(struct netifapi_msg_msg *msg)
grzemich 0:d7bd7384a37c 81 {
grzemich 0:d7bd7384a37c 82 if (msg->msg.common.errtfunc != NULL) {
grzemich 0:d7bd7384a37c 83 msg->err = msg->msg.common.errtfunc(msg->netif);
grzemich 0:d7bd7384a37c 84 } else {
grzemich 0:d7bd7384a37c 85 msg->err = ERR_OK;
grzemich 0:d7bd7384a37c 86 msg->msg.common.voidfunc(msg->netif);
grzemich 0:d7bd7384a37c 87 }
grzemich 0:d7bd7384a37c 88 TCPIP_NETIFAPI_ACK(msg);
grzemich 0:d7bd7384a37c 89 }
grzemich 0:d7bd7384a37c 90
grzemich 0:d7bd7384a37c 91 /**
grzemich 0:d7bd7384a37c 92 * Call netif_add() in a thread-safe way by running that function inside the
grzemich 0:d7bd7384a37c 93 * tcpip_thread context.
grzemich 0:d7bd7384a37c 94 *
grzemich 0:d7bd7384a37c 95 * @note for params @see netif_add()
grzemich 0:d7bd7384a37c 96 */
grzemich 0:d7bd7384a37c 97 err_t
grzemich 0:d7bd7384a37c 98 netifapi_netif_add(struct netif *netif,
grzemich 0:d7bd7384a37c 99 ip_addr_t *ipaddr,
grzemich 0:d7bd7384a37c 100 ip_addr_t *netmask,
grzemich 0:d7bd7384a37c 101 ip_addr_t *gw,
grzemich 0:d7bd7384a37c 102 void *state,
grzemich 0:d7bd7384a37c 103 netif_init_fn init,
grzemich 0:d7bd7384a37c 104 netif_input_fn input)
grzemich 0:d7bd7384a37c 105 {
grzemich 0:d7bd7384a37c 106 struct netifapi_msg msg;
grzemich 0:d7bd7384a37c 107 msg.function = do_netifapi_netif_add;
grzemich 0:d7bd7384a37c 108 msg.msg.netif = netif;
grzemich 0:d7bd7384a37c 109 msg.msg.msg.add.ipaddr = ipaddr;
grzemich 0:d7bd7384a37c 110 msg.msg.msg.add.netmask = netmask;
grzemich 0:d7bd7384a37c 111 msg.msg.msg.add.gw = gw;
grzemich 0:d7bd7384a37c 112 msg.msg.msg.add.state = state;
grzemich 0:d7bd7384a37c 113 msg.msg.msg.add.init = init;
grzemich 0:d7bd7384a37c 114 msg.msg.msg.add.input = input;
grzemich 0:d7bd7384a37c 115 TCPIP_NETIFAPI(&msg);
grzemich 0:d7bd7384a37c 116 return msg.msg.err;
grzemich 0:d7bd7384a37c 117 }
grzemich 0:d7bd7384a37c 118
grzemich 0:d7bd7384a37c 119 /**
grzemich 0:d7bd7384a37c 120 * Call netif_set_addr() in a thread-safe way by running that function inside the
grzemich 0:d7bd7384a37c 121 * tcpip_thread context.
grzemich 0:d7bd7384a37c 122 *
grzemich 0:d7bd7384a37c 123 * @note for params @see netif_set_addr()
grzemich 0:d7bd7384a37c 124 */
grzemich 0:d7bd7384a37c 125 err_t
grzemich 0:d7bd7384a37c 126 netifapi_netif_set_addr(struct netif *netif,
grzemich 0:d7bd7384a37c 127 ip_addr_t *ipaddr,
grzemich 0:d7bd7384a37c 128 ip_addr_t *netmask,
grzemich 0:d7bd7384a37c 129 ip_addr_t *gw)
grzemich 0:d7bd7384a37c 130 {
grzemich 0:d7bd7384a37c 131 struct netifapi_msg msg;
grzemich 0:d7bd7384a37c 132 msg.function = do_netifapi_netif_set_addr;
grzemich 0:d7bd7384a37c 133 msg.msg.netif = netif;
grzemich 0:d7bd7384a37c 134 msg.msg.msg.add.ipaddr = ipaddr;
grzemich 0:d7bd7384a37c 135 msg.msg.msg.add.netmask = netmask;
grzemich 0:d7bd7384a37c 136 msg.msg.msg.add.gw = gw;
grzemich 0:d7bd7384a37c 137 TCPIP_NETIFAPI(&msg);
grzemich 0:d7bd7384a37c 138 return msg.msg.err;
grzemich 0:d7bd7384a37c 139 }
grzemich 0:d7bd7384a37c 140
grzemich 0:d7bd7384a37c 141 /**
grzemich 0:d7bd7384a37c 142 * call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) in a thread-safe
grzemich 0:d7bd7384a37c 143 * way by running that function inside the tcpip_thread context.
grzemich 0:d7bd7384a37c 144 *
grzemich 0:d7bd7384a37c 145 * @note use only for functions where there is only "netif" parameter.
grzemich 0:d7bd7384a37c 146 */
grzemich 0:d7bd7384a37c 147 err_t
grzemich 0:d7bd7384a37c 148 netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc,
grzemich 0:d7bd7384a37c 149 netifapi_errt_fn errtfunc)
grzemich 0:d7bd7384a37c 150 {
grzemich 0:d7bd7384a37c 151 struct netifapi_msg msg;
grzemich 0:d7bd7384a37c 152 msg.function = do_netifapi_netif_common;
grzemich 0:d7bd7384a37c 153 msg.msg.netif = netif;
grzemich 0:d7bd7384a37c 154 msg.msg.msg.common.voidfunc = voidfunc;
grzemich 0:d7bd7384a37c 155 msg.msg.msg.common.errtfunc = errtfunc;
grzemich 0:d7bd7384a37c 156 TCPIP_NETIFAPI(&msg);
grzemich 0:d7bd7384a37c 157 return msg.msg.err;
grzemich 0:d7bd7384a37c 158 }
grzemich 0:d7bd7384a37c 159
grzemich 0:d7bd7384a37c 160 #endif /* LWIP_NETIF_API */