Onenet

Dependents:   K64F_eCompass_OneNET_JW

Committer:
robert_jw
Date:
Mon Jun 20 01:40:20 2016 +0000
Revision:
0:b2805b6888dc
ADS

Who changed what in which revision?

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