Wiki source code of Filter unwanted LoRaWAN packets
Last modified by Kilight Cao on 2025/03/03 16:11
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | **~ Table of Contents:** | ||
2 | |||
3 | {{toc/}} | ||
4 | |||
5 | |||
6 | |||
7 | |||
8 | |||
9 | = 1. Introduction = | ||
10 | |||
11 | |||
12 | This feature is to filter the unwanted LoRaWAN packets. Purpose is to save the upstream traffic especially for a 4G cellular connection. If configured, gateway will process filter for below two types of message: | ||
13 | |||
14 | * Unconfirmed Data Up | ||
15 | |||
16 | * Confirmed Data Up | ||
17 | |||
18 | = (% data-sider-select-id="a6563476-6957-435c-a8e6-64925b496a09" %)2. LoRaWAN Filter Mechanism(%%) = | ||
19 | |||
20 | |||
21 | (% style="color:blue" %)**Support Devices:** | ||
22 | |||
23 | * All existing models of Gateways | ||
24 | |||
25 | (% style="color:blue" %)**Support Server Type:** | ||
26 | |||
27 | * LoRaWAN Semtech UDP & Basic Station | ||
28 | |||
29 | (% style="color:blue" %)**Filtering rules:** | ||
30 | |||
31 | (% border="1" style="background-color:#f2f2f2; width:1327.22px" %) | ||
32 | |=(% colspan="2" data-sider-select-id="2963d404-f9df-47a3-9421-ad8343c28190" style="width: 326px; background-color: rgb(79, 129, 189); color: white;" %)Fport Filters|=(% colspan="2" data-sider-select-id="b75fb8fe-614b-43de-866c-7df1f0e1351c" style="width: 320px; background-color: rgb(79, 129, 189); color: white;" %)DevAddr Filter|=(% colspan="2" data-sider-select-id="b75fb8fe-614b-43de-866c-7df1f0e1351c" rowspan="1" style="width: 345px; background-color: rgb(79, 129, 189); color: white;" %)(% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)NwkID Filter|=(% colspan="2" data-sider-select-id="b75fb8fe-614b-43de-866c-7df1f0e1351c" rowspan="1" style="width: 336px; background-color: rgb(79, 129, 189); color: white;" %)Dev EUI Filter | ||
33 | |(% data-sider-select-id="48ec1aac-dbc7-42b1-b4cf-5efa6cebeb7b" style="width:71px" %)**Level 0**|(% style="width:203px" %)Do nothing|(% data-sider-select-id="93e39a51-390d-40f8-b384-3e2013f30f59" style="width:75px" %)**Level 0**|(% data-sider-select-id="7a32435a-480f-4394-8307-c01a996c309e" style="width:245px" %)Do nothing|(% data-sider-select-id="bbac18ba-6ebe-4919-a75e-006067aa9702" style="width:78px" %)(% data-sider-select-id="a5a992a8-2aba-48cb-b876-6441732df6a5" %)**Level 0**|(% style="width:266px" %)Do nothing|(% data-sider-select-id="bbac18ba-6ebe-4919-a75e-006067aa9702" style="width:83px" %)(% data-sider-select-id="a5a992a8-2aba-48cb-b876-6441732df6a5" %)**Level 0**|(% style="width:256px" %)Do nothing | ||
34 | |(% style="width:71px" %)**Level 1**|(% style="width:203px" %)Filter only the Fport in the list|(% style="width:75px" %)**Level 1**|(% data-sider-select-id="97e7e7ae-2f87-4c08-9730-569c9628f9a7" style="width:245px" %)Filter only the DevAddr in the list|(% data-sider-select-id="5a23d47e-2f84-4f36-a62b-d3b2bd094087" style="width:78px" %)(% data-sider-select-id="8dfd7850-dada-4703-bf77-3dc67e3d3e13" %)**Level 1**|(% data-sider-select-id="87522df9-2acc-4194-9b27-61085236248e" style="width:266px" %)Filter only the NwkID in the list|(% data-sider-select-id="87522df9-2acc-4194-9b27-61085236248e" style="width:83px" %)**Level 1**|(% data-sider-select-id="87522df9-2acc-4194-9b27-61085236248e" style="width:256px" %)Filter only the Dev EUI in the list | ||
35 | |(% style="width:71px" %)**Level 2**|(% style="width:203px" %)Filter Fport that are not in the database|(% style="width:75px" %)**Level 2**|(% data-sider-select-id="58fb49e7-bec6-4701-8dd9-8c4a3a3138fa" style="width:245px" %)Filter DevAddr that are not in the database|(% data-sider-select-id="41c0816f-cc2a-45ce-a04c-5499e54b8347" style="width:78px" %)(% data-sider-select-id="1d8fbf98-cc3e-430c-824c-fe435a1b7330" %)**Level 2**|(% data-sider-select-id="323e6d5b-9fd3-4ec8-a767-ac5339de7160" style="width:266px" %)Filter NWkID that are not in the database|(% data-sider-select-id="41c0816f-cc2a-45ce-a04c-5499e54b8347" style="width:83px" %)(% data-sider-select-id="1d8fbf98-cc3e-430c-824c-fe435a1b7330" %)**Level 2**|(% data-sider-select-id="323e6d5b-9fd3-4ec8-a767-ac5339de7160" style="width:256px" %)Filter Dev EUI that are not in the database | ||
36 | |||
37 | ((( | ||
38 | |||
39 | |||
40 | (% style="color:blue" %)**LoRaWAN Semtech UDP Page:** | ||
41 | |||
42 | [[image:image-20250303153917-1.png||height="764" width="1195"]] | ||
43 | |||
44 | |||
45 | (% style="color:blue" %)**Basic Station Page:** | ||
46 | |||
47 | [[image:image-20250303160903-6.png]] | ||
48 | |||
49 | |||
50 | (% style="color:blue" %)**Check if the filter is running** | ||
51 | |||
52 | [[image:image-20250303154226-2.png||height="878" width="1068"]] | ||
53 | |||
54 | |||
55 | == 2.1 Filter By Fport == | ||
56 | |||
57 | |||
58 | The Gateway FPort filter will check all the below LoRaWAN messages: Unconfirmed Data Up & Confirmed Data Up. | ||
59 | |||
60 | |||
61 | (% style="color:red" %)**Important Notice:** | ||
62 | |||
63 | * By default, Fport Filter (% style="color:blue" %)**Level=0**(%%). which means do nothing | ||
64 | |||
65 | * Fport Filter configured to (% style="color:blue" %)**Level=1**(%%). If the Fport in the list matches the Fport received by the gateway, it will be dropped. | ||
66 | |||
67 | * Fport Filter configured to (% style="color:blue" %)**Level=2**(%%). If the Fport in the list does not match the Fport received by the gateway, it will be dropped. | ||
68 | |||
69 | (% data-sider-select-id="a52abdcb-0f07-49a7-a84d-dbbdfc7912d8" %) | ||
70 | If you want to **forward only a certain Fport**, use level=2 and add the desired fport in the Filter value textbox. **Add Filter Value 0 to forward Join requests**. | ||
71 | |||
72 | [[image:image-20240517094721-4.png]] | ||
73 | |||
74 | |||
75 | == 2.2 Filter By DevAddr == | ||
76 | |||
77 | |||
78 | The Gateway DevAddr filter will check all the below LoRaWAN messages: Unconfirmed Data Up & Confirmed Data Up. | ||
79 | |||
80 | |||
81 | (% style="color:red" %)**Important Notice:** | ||
82 | |||
83 | * By default, DevAddr Filter (% style="color:blue" %)**Level=0**(%%). which means do nothing | ||
84 | |||
85 | * DevAddr Filter configured to (% style="color:blue" %)**Level=1**(%%). If the DevAddr in the list matches the DevAddr received by the gateway, it will be dropped. | ||
86 | |||
87 | * DevAddr Filter configured to (% style="color:blue" %)**Level=2**(%%). If the DevAddr in the list does not match the DevAddr received by the gateway, it will be dropped. | ||
88 | |||
89 | (% data-sider-select-id="1c5a3ce7-94da-41b2-b4f5-a83321d225e4" %) | ||
90 | In this case, we set DevAddr Filter Level=1 and add the filter (server | DevAddr | 12664787 ), when the gateway receives a Lorawan packet with DevAddr=12664787, it will be dropped. | ||
91 | |||
92 | [[image:image-20240517095315-5.png||height="373" width="1085"]] | ||
93 | |||
94 | |||
95 | == (% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)2.3 Filter By NwkID(%%) == | ||
96 | |||
97 | |||
98 | The Gateway NwkID filter will check all the below LoRaWAN messages: Unconfirmed Data Up & Confirmed Data Up. | ||
99 | |||
100 | (% style="color:red" %)**Important Notice:** | ||
101 | |||
102 | * By default, NwkID Filter (% style="color:blue" %)**Level=0**(%%). which means do nothing | ||
103 | |||
104 | * NwkID Filter configured to (% style="color:blue" %)**Level=1**(%%). If the NwkID in the list matches the NwkID received by the gateway, it will be dropped. | ||
105 | |||
106 | * NwkID Filter configured to (% style="color:blue" %)**Level=2**(%%). If the NwkID in the list does not match the NwkID received by the gateway, it will be dropped. | ||
107 | |||
108 | In this case, we set NwkID Filter Level=2 and add the filter (server | NwkID | 13 ), when the gateway receives a packet that is not NwkID=00000013, it will be dropped. | ||
109 | |||
110 | NwkID is calculated as follows: DevAddr counts shifted right by 25 bits | ||
111 | |||
112 | For example, Devaddr=01CC1907,NwkID= 01CC1907 >> 25 = 0 | ||
113 | |||
114 | Devaddr=260B748A,NwkID= 260B748A >> 25 = 13 | ||
115 | |||
116 | [[image:image-20240517095458-6.png]] | ||
117 | |||
118 | |||
119 | (% data-sider-select-id="77834038-9f62-4c79-9e9e-8761b751e708" style="color:red" %)**If user need to set the Secondary LoRaWAN Server Packet Filter, the configuration is similar to that above.** | ||
120 | |||
121 | |||
122 | == (% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)2.4 Filter By Dev EUI(%%) == | ||
123 | |||
124 | |||
125 | The Gateway (% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)Dev EUI(%%) filter will check all the below LoRaWAN messages: Unconfirmed Data Up & Confirmed Data Up. | ||
126 | |||
127 | (% style="color:red" %)**Important Notice:** | ||
128 | |||
129 | * By default, (% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)Dev EUI(%%) Filter (% style="color:blue" %)**Level=0**(%%). which means do nothing | ||
130 | |||
131 | * (% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)Dev EUI(%%) Filter configured to (% style="color:blue" %)**Level=1**(%%). If the (% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)Dev EUI(%%) in the list matches the (% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)Dev EUI(%%) received by the gateway, it will be dropped. | ||
132 | |||
133 | * (% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)Dev EUI(%%) Filter configured to (% style="color:blue" %)**Level=2**(%%). If the (% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)Dev EUI(%%) in the list does not match the (% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)Dev EUI(%%) received by the gateway, it will be dropped. | ||
134 | |||
135 | In this case, we set (% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)Dev EUI(%%) Filter Level=1 and add the filter (server | deveui | 11FF1111FF112255 ), when the gateway receives the join request packet with deveui=11FF1111FF112255, it will be dropped. | ||
136 | |||
137 | [[image:image-20250303155342-4.png]] | ||
138 | |||
139 | |||
140 | == (% data-sider-select-id="94c45e8c-41a9-45df-bd1c-0253901140bb" %)2.5 Add Filter rules via Linux Command.(%%) == | ||
141 | |||
142 | |||
143 | (% class="box infomessage" %) | ||
144 | ((( | ||
145 | $ sqlite3 /etc/lora/devskey "INSERT INTO filter (name, type, value ) VALUES ('$filter_name', '$filter_type', '$filter_value');" | ||
146 | |||
147 | |||
148 | |||
149 | name: server name. eg: server1/server2 | ||
150 | |||
151 | type: filter type. eg: fport/devaddr | ||
152 | |||
153 | value: 0,1,2,3/000000 | ||
154 | ))) | ||
155 | |||
156 | (% class="box" %) | ||
157 | ((( | ||
158 | eg: | ||
159 | |||
160 | sqlite3 /etc/lora/devskey "INSERT INTO filter (name, type, value ) VALUES ('server1', 'fport', '1');" | ||
161 | |||
162 | sqlite3 /etc/lora/devskey "INSERT INTO filter (name, type, value ) VALUES ('server1', 'devaddr', '00000000');" | ||
163 | |||
164 | sqlite3 /etc/lora/devskey "SELECT *from filter" | ||
165 | ))) | ||
166 | |||
167 | [[image:image-20230519104800-2.png||_mstalt="428714"]] | ||
168 | ))) | ||
169 | |||
170 | |||
171 | ((( | ||
172 | |||
173 | |||
174 | = 3. PKT_FWD Filter Mechanism = | ||
175 | |||
176 | |||
177 | (% style="color:blue" %)**Support Devices:** | ||
178 | |||
179 | * Firmware Version >** lgw~-~-build-v5.4.1602379434-20201011-0926** [[Firmware Download>>url:http://www.dragino.com/downloads/index.php?dir=LoRa_Gateway/LPS8/Firmware/Release/]] | ||
180 | |||
181 | * LG308, DLOS8 | ||
182 | |||
183 | * LPS8 | ||
184 | |||
185 | (% style="color:blue" %)**Fport & DevAddr Filter** | ||
186 | |||
187 | [[image:image-20220527150138-1.png||_mstalt="429598"]] | ||
188 | |||
189 | |||
190 | (% style="color:blue" %)**Check if the filter is running** | ||
191 | |||
192 | [[image:image-20220527150222-2.png||_mstalt="427921" height="379" width="1062"]] | ||
193 | |||
194 | |||
195 | == 3.1 Filter By Fport == | ||
196 | |||
197 | |||
198 | The Gateway FPort filter will check all the below LoRaWAN message: Unconfirmed Data Up & Confirmed Data Up. If the packet's FPort doesn't match the FPort setting, it will be dropped. | ||
199 | |||
200 | ((( | ||
201 | By default , this value is 0 means can upstream all packets with any FPort. We can set to other FPort so specify only one FPort works. | ||
202 | ))) | ||
203 | |||
204 | [[image:image-20220527150303-3.png||_mstalt="428285"]] | ||
205 | |||
206 | |||
207 | In case we set the FPort filter to 45, and the End Node send a packet with Fport other than 45, it will be dropped. | ||
208 | |||
209 | |||
210 | == 3.2 Filter By DevAddr == | ||
211 | |||
212 | |||
213 | Gateway will use a DevAddr mask to check if the Unconfirmed Data Up & Confirmed Data Up packets match the mask . If not, gateway will drop it. | ||
214 | |||
215 | [[image:image-20220527150404-4.png||_mstalt="429299"]] | ||
216 | |||
217 | |||
218 | This screenshot shows packets is dropped if DevAddr mask doesn't match. | ||
219 | |||
220 | |||
221 | ))) |