1 /*
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 * Description: implementation for l3_msg_event
15 * Author: none
16 * Create: 2020
17 */
18
19 #include "lwip/opt.h"
20 #include "lwip/sys.h"
21 #if !NO_SYS /* don't build if not configured for use in lwipopts.h */
22
23 #if LWIP_L3_EVENT_MSG
24
25 #include "lwip/l3event.h"
26 #include "lwip/tcpip.h"
27
28 /* global variables, used for storing the callback function from upper app */
29 static app_callback_fn g_l3_evt_cbs[L3_EVENT_MSG_MAX];
30
31 /*
32 * Invoke l3 msg event callback
33 * @param type which l3 event msg type
34 * @param msg data that are carried in the msg
35 */
36 void
l3_invoke_msg_callback(enum l3_event_msg_type evt_type,void * msg)37 l3_invoke_msg_callback(enum l3_event_msg_type evt_type, void *msg)
38 {
39 #if LWIP_L3_EVENT_MSG_EXIST
40 switch (evt_type) {
41 #if LWIP_ROUTE_CHANGE_MSG
42 case L3_EVENT_MSG_ROUTE_CHANGE:
43 case L3_EVENT_MSG_ROUTE_ADD:
44 case L3_EVENT_MSG_ROUTE_UPDATE:
45 case L3_EVENT_MSG_ROUTE_DEL:
46 #endif
47 #if LWIP_NAT64_CHANGE_MSG
48 case L3_EVENT_MSG_NAT64_ADD:
49 case L3_EVENT_MSG_NAT64_DEL:
50 case L3_EVENT_MSG_NAT64_UPDATE:
51 #endif
52 #if LWIP_RPL_JOIN_SUCC_MSG
53 case L3_EVENT_MSG_RPL_JOIN_SUCC:
54 #endif
55 #if LWIP_RPL_PARENT_CLEAR_MSG
56 case L3_EVENT_MSG_PARENT_CLEAR:
57 #endif
58 #if LWIP_RPL_BEACON_PRI_RESET
59 case L3_EVENT_MSG_BEACON_PRI_RESET:
60 #endif
61 #if LWIP_RPL_GET_IPV4_ADDR_FAIL
62 case L3_EVENT_MSG_GET_IPV4_ADDR_FAIL:
63 #endif
64 #if LWIP_RPL_MSTA_GET_IPV4_ADDR_FAIL
65 case L3_EVENT_MSG_MSTA_GET_IPV4_ADDR_FAIL:
66 #endif
67 #if LWIP_RPL_MG_FULL
68 case L3_EVENT_MSG_MG_FULL:
69 #endif
70 #if LWIP_RPL_RT_FULL
71 case L3_EVENT_MSG_RT_FULL:
72 #endif
73 #if LWIP_RPL_GET_MNID_FAIL
74 case L3_EVENT_MSG_GET_MNID_FAIL:
75 #endif
76 if (g_l3_evt_cbs[evt_type] != NULL) {
77 g_l3_evt_cbs[evt_type](evt_type, msg);
78 } else {
79 LWIP_DEBUGF(L3_EVENT_MSG_DEBUG, ("l3_ext_parent_clear_callback: callback function didn't be registered\n"));
80 }
81 break;
82 default:
83 LWIP_DEBUGF(L3_EVENT_MSG_DEBUG, ("l3_event_thread: invalid message: %d\n", evt_type));
84 LWIP_ASSERT("invalid message", 0);
85 break;
86 }
87 #else
88 (void)evt_type;
89 (void)msg;
90 #endif
91 }
92
93 /*
94 * l3 event msg callback
95 * @param type which l3 event msg type
96 * @param app_callback the register callback function
97 */
l3_event_msg_callback_reg(enum l3_event_msg_type evt_type,app_callback_fn app_callback)98 void l3_event_msg_callback_reg(enum l3_event_msg_type evt_type, app_callback_fn app_callback)
99 {
100 #if LWIP_L3_EVENT_MSG_EXIST
101 switch (evt_type) {
102 #if LWIP_ROUTE_CHANGE_MSG
103 case L3_EVENT_MSG_ROUTE_CHANGE:
104 case L3_EVENT_MSG_ROUTE_ADD:
105 case L3_EVENT_MSG_ROUTE_UPDATE:
106 case L3_EVENT_MSG_ROUTE_DEL:
107 #endif
108 #if LWIP_NAT64_CHANGE_MSG
109 case L3_EVENT_MSG_NAT64_ADD:
110 case L3_EVENT_MSG_NAT64_DEL:
111 case L3_EVENT_MSG_NAT64_UPDATE:
112 #endif
113 #if LWIP_RPL_JOIN_SUCC_MSG
114 case L3_EVENT_MSG_RPL_JOIN_SUCC:
115 #endif
116 #if LWIP_RPL_PARENT_CLEAR_MSG
117 case L3_EVENT_MSG_PARENT_CLEAR:
118 #endif
119 #if LWIP_RPL_BEACON_PRI_RESET
120 case L3_EVENT_MSG_BEACON_PRI_RESET:
121 #endif
122 #if LWIP_RPL_GET_IPV4_ADDR_FAIL
123 case L3_EVENT_MSG_GET_IPV4_ADDR_FAIL:
124 #endif
125 #if LWIP_RPL_MSTA_GET_IPV4_ADDR_FAIL
126 case L3_EVENT_MSG_MSTA_GET_IPV4_ADDR_FAIL:
127 #endif
128 #if LWIP_RPL_MG_FULL
129 case L3_EVENT_MSG_MG_FULL:
130 #endif
131 #if LWIP_RPL_RT_FULL
132 case L3_EVENT_MSG_RT_FULL:
133 #endif
134 #if LWIP_RPL_GET_MNID_FAIL
135 case L3_EVENT_MSG_GET_MNID_FAIL:
136 #endif
137 LOCK_TCPIP_CORE();
138 g_l3_evt_cbs[evt_type] = app_callback;
139 UNLOCK_TCPIP_CORE();
140 LWIP_DEBUGF(L3_EVENT_MSG_DEBUG, ("l3_event_msg_callback: register the MSG callback function\n"));
141 break;
142 default:
143 LWIP_DEBUGF(L3_EVENT_MSG_DEBUG, ("l3_event_msg_callback: invalid message: %d\n", evt_type));
144 LWIP_ASSERT("l3_event_msg_callback: invalid message", 0);
145 break;
146 }
147 #else
148 (void)evt_type;
149 (void)app_callback;
150 #endif
151 }
152
153 #endif /* LWIP_L3_EVENT_MSG */
154 #endif /* !NO_SYS */
155