Wiki source code of Filter unwanted LoRaWAN packets
Last modified by Kilight Cao on 2024/05/17 10:07
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. FWD Filter Mechanism(%%) = | ||
19 | |||
20 | |||
21 | (% style="color:blue" %)**Support Devices:** | ||
22 | |||
23 | * Firmware Version > (% data-sider-select-id="96ad6b3a-7145-4307-84cb-f96bf2963143" %)** **(% data-sider-select-id="4543141b-3f38-468e-b55c-42b857536714" %)**dragino-lgw~-~-v5.4.1699325460** | ||
24 | |||
25 | * LG308, DLOS8, LPS8, LIG16, LG308N, DLOS8N, LPS8N | ||
26 | |||
27 | (% style="color:blue" %)**Filtering rules:** | ||
28 | |||
29 | (% border="1" style="background-color:#f2f2f2; width:1063px" %) | ||
30 | |=(% 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: 328px; 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: 403px; background-color: rgb(79, 129, 189); color: white;" %)(% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)NwkID Filter | ||
31 | |(% data-sider-select-id="48ec1aac-dbc7-42b1-b4cf-5efa6cebeb7b" style="width:66px" %)**Level 0**|(% style="width:259px" %)Do nothing|(% data-sider-select-id="93e39a51-390d-40f8-b384-3e2013f30f59" style="width:67px" %)**Level 0**|(% data-sider-select-id="7a32435a-480f-4394-8307-c01a996c309e" style="width:261px" %)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:326px" %)Do nothing | ||
32 | |(% style="width:66px" %)**Level 1**|(% style="width:259px" %)Filter only the Fport in the list|(% style="width:67px" %)**Level 1**|(% data-sider-select-id="97e7e7ae-2f87-4c08-9730-569c9628f9a7" style="width:261px" %)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:326px" %)Filter only the NwkID in the list | ||
33 | |(% style="width:66px" %)**Level 2**|(% style="width:259px" %)Filter Fport that are not in the database|(% style="width:67px" %)**Level 2**|(% data-sider-select-id="58fb49e7-bec6-4701-8dd9-8c4a3a3138fa" style="width:261px" %)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:326px" %)Filter NWkID that are not in the database | ||
34 | |||
35 | ((( | ||
36 | [[image:image-20240517094256-2.png||height="785" width="976"]] | ||
37 | |||
38 | |||
39 | (% style="color:blue" %)**Check if the filter is running** | ||
40 | |||
41 | [[image:image-20240517094552-3.png||height="568" width="974"]] | ||
42 | |||
43 | |||
44 | == 2.1 Filter By Fport == | ||
45 | |||
46 | |||
47 | The Gateway FPort filter will check all the below LoRaWAN messages: Unconfirmed Data Up & Confirmed Data Up. | ||
48 | |||
49 | |||
50 | (% style="color:red" %)**Important Notice:** | ||
51 | |||
52 | * By default, Fport Filter (% style="color:blue" %)**Level=0**(%%). which means do nothing | ||
53 | |||
54 | * 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. | ||
55 | |||
56 | * 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. | ||
57 | |||
58 | (% data-sider-select-id="a52abdcb-0f07-49a7-a84d-dbbdfc7912d8" %) | ||
59 | 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**. | ||
60 | |||
61 | [[image:image-20240517094721-4.png]] | ||
62 | |||
63 | |||
64 | |||
65 | == 2.2 Filter By DevAddr == | ||
66 | |||
67 | |||
68 | The Gateway DevAddr filter will check all the below LoRaWAN messages: Unconfirmed Data Up & Confirmed Data Up. | ||
69 | |||
70 | |||
71 | (% style="color:red" %)**Important Notice:** | ||
72 | |||
73 | * By default, DevAddr Filter (% style="color:blue" %)**Level=0**(%%). which means do nothing | ||
74 | |||
75 | * 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. | ||
76 | |||
77 | * 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. | ||
78 | |||
79 | (% data-sider-select-id="1c5a3ce7-94da-41b2-b4f5-a83321d225e4" %) | ||
80 | 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. | ||
81 | |||
82 | [[image:image-20240517095315-5.png||height="373" width="1085"]] | ||
83 | |||
84 | |||
85 | |||
86 | |||
87 | == (% data-sider-select-id="66b78721-94c2-42f2-9700-2d53738af37c" %)2.3 Filter By NwkID(%%) == | ||
88 | |||
89 | |||
90 | The Gateway NwkID filter will check all the below LoRaWAN messages: Unconfirmed Data Up & Confirmed Data Up. | ||
91 | |||
92 | |||
93 | (% style="color:red" %)**Important Notice:** | ||
94 | |||
95 | * By default, NwkID Filter (% style="color:blue" %)**Level=0**(%%). which means do nothing | ||
96 | |||
97 | * 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. | ||
98 | |||
99 | * 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. | ||
100 | |||
101 | In this case, we set NwkID Filter Level=0 and add the filter (server | NwkID | 13 ), when the gateway receives a packet that is not NwkID=00000013, it will be dropped. | ||
102 | |||
103 | NwkID is calculated as follows: DevAddr counts shifted right by 25 bits | ||
104 | |||
105 | For example, Devaddr=01CC1907,NwkID= 01CC1907 >> 25 = 0 | ||
106 | |||
107 | Devaddr=260B748A,NwkID= 260B748A >> 25 = 13 | ||
108 | |||
109 | [[image:image-20240517095458-6.png]] | ||
110 | |||
111 | |||
112 | |||
113 | |||
114 | (% 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.** | ||
115 | |||
116 | == (% data-sider-select-id="94c45e8c-41a9-45df-bd1c-0253901140bb" %)2.4 Add Filter rules via Linux Command.(%%) == | ||
117 | |||
118 | |||
119 | (% class="box infomessage" %) | ||
120 | ((( | ||
121 | $ sqlite3 /etc/lora/devskey "INSERT INTO filter (name, type, value ) VALUES ('$filter_name', '$filter_type', '$filter_value');" | ||
122 | |||
123 | |||
124 | |||
125 | name: server name. eg: server1/server2 | ||
126 | |||
127 | type: filter type. eg: fport/devaddr | ||
128 | |||
129 | value: 0,1,2,3/000000 | ||
130 | ))) | ||
131 | |||
132 | (% class="box" %) | ||
133 | ((( | ||
134 | eg: | ||
135 | |||
136 | sqlite3 /etc/lora/devskey "INSERT INTO filter (name, type, value ) VALUES ('server1', 'fport', '1');" | ||
137 | |||
138 | sqlite3 /etc/lora/devskey "INSERT INTO filter (name, type, value ) VALUES ('server1', 'devaddr', '00000000');" | ||
139 | |||
140 | sqlite3 /etc/lora/devskey "SELECT *from filter" | ||
141 | ))) | ||
142 | |||
143 | [[image:image-20230519104800-2.png||_mstalt="428714"]] | ||
144 | ))) | ||
145 | |||
146 | |||
147 | (% data-sider-select-id="e156bc15-52eb-407c-ac7d-e4f5dc536721" %) | ||
148 | == (% data-sider-select-id="94c45e8c-41a9-45df-bd1c-0253901140bb" %)2.5 (%%)Check results == | ||
149 | |||
150 | |||
151 | (% data-sider-select-id="eb82d072-f936-4456-812b-2d4072ad5fe7" %) | ||
152 | After the configuration is complete, you can enable Logread Debug level on System~-~->General, return to LoRaWAN~-~->Semtech UDP, and click "Save&Apply". | ||
153 | |||
154 | [[image:image-20240517100303-7.png||height="784" width="1120"]] | ||
155 | |||
156 | |||
157 | = 3. PKT_FWD Filter Mechanism = | ||
158 | |||
159 | |||
160 | (% style="color:blue" %)**Support Devices:** | ||
161 | |||
162 | * 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/]] | ||
163 | |||
164 | * LG308, DLOS8 | ||
165 | |||
166 | * LPS8 | ||
167 | |||
168 | (% style="color:blue" %)**Fport & DevAddr Filter** | ||
169 | |||
170 | [[image:image-20220527150138-1.png||_mstalt="429598"]] | ||
171 | |||
172 | |||
173 | (% style="color:blue" %)**Check if the filter is running** | ||
174 | |||
175 | [[image:image-20220527150222-2.png||_mstalt="427921" height="379" width="1062"]] | ||
176 | |||
177 | |||
178 | == 3.1 Filter By Fport == | ||
179 | |||
180 | |||
181 | 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. | ||
182 | |||
183 | ((( | ||
184 | 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. | ||
185 | ))) | ||
186 | |||
187 | [[image:image-20220527150303-3.png||_mstalt="428285"]] | ||
188 | |||
189 | |||
190 | 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. | ||
191 | |||
192 | |||
193 | == 3.2 Filter By DevAddr == | ||
194 | |||
195 | |||
196 | 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. | ||
197 | |||
198 | [[image:image-20220527150404-4.png||_mstalt="429299"]] | ||
199 | |||
200 | |||
201 | This screenshot shows packets is dropped if DevAddr mask doesn't match. | ||
202 | |||
203 |