Wiki source code of Filter unwanted LoRaWAN packets
Last modified by Kilight Cao on 2023/11/07 14:39
Hide last authors
author | version | line-number | content |
---|---|---|---|
11.2 | 1 | **~ Table of Contents:** | |
1.2 | 2 | ||
1.1 | 3 | {{toc/}} | |
4 | |||
9.1 | 5 | ||
6 | |||
7 | |||
8 | |||
35.2 | 9 | = 1. Introduction = | |
1.1 | 10 | ||
33.2 | 11 | ||
1.2 | 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: | |
1.1 | 13 | ||
1.2 | 14 | * Unconfirmed Data Up | |
35.4 | 15 | ||
1.2 | 16 | * Confirmed Data Up | |
1.1 | 17 | ||
35.2 | 18 | = 2. FWD Filter Mechanism = | |
33.2 | 19 | ||
13.1 | 20 | ||
41.4 | 21 | (% style="color:blue" %)**Support Devices:** | |
13.1 | 22 | ||
32.1 | 23 | * Firmware Version > ** dragino-lgw~-~-v5.4.1658824252** | |
35.4 | 24 | ||
30.1 | 25 | * LG308, DLOS8, LPS8, LIG16, LG308N, DLOS8N, LPS8N | |
13.1 | 26 | ||
41.4 | 27 | (% style="color:blue" %)**Filtering rules:** | |
13.1 | 28 | ||
35.4 | 29 | (% border="1" style="background-color:#f2f2f2; width:728px" %) | |
41.2 | 30 | |=(% colspan="2" style="width: 351px;background-color:#4F81BD;color:white" %)Fport Filter|=(% colspan="2" style="width: 374px;background-color:#4F81BD;color:white" %)DevAddr Filter | |
33.2 | 31 | |(% style="width:66px" %)**Level 0**|(% style="width:284px" %)Do nothing|(% style="width:68px" %)**Level 0**|(% style="width:306px" %)Do nothing | |
32 | |(% style="width:66px" %)**Level 1**|(% style="width:284px" %)Filter only the Fport in the list|(% style="width:68px" %)**Level 1**|(% style="width:306px" %)Filter only the DevAddr in the list | ||
33 | |(% style="width:66px" %)**Level 2**|(% style="width:284px" %)Filter Fport that are not in the database|(% style="width:68px" %)**Level 2**|(% style="width:306px" %)Filter DevAddr that are not in the database | ||
13.1 | 34 | ||
35 | ((( | ||
41.1 | 36 | [[image:image-20220726171434-6.png||_mstalt="432081" height="628" width="692"]] | |
13.1 | 37 | ||
24.1 | 38 | ||
41.4 | 39 | (% style="color:blue" %)**Check if the filter is running** | |
24.1 | 40 | ||
41.1 | 41 | [[image:image-20220726164533-3.png||_mstalt="431574" height="465" width="982"]] | |
24.1 | 42 | ||
43 | |||
35.2 | 44 | == 2.1 Filter By Fport == | |
24.1 | 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 | |||
26.1 | 52 | * By default, Fport Filter (% style="color:blue" %)**Level=0**(%%). which means do nothing | |
24.1 | 53 | ||
26.1 | 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. | |
24.1 | 55 | ||
26.1 | 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. | |
24.1 | 57 | ||
35.1 | 58 | 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**. | |
24.1 | 59 | ||
41.1 | 60 | [[image:image-20221129101012-1.png||_mstalt="425282"]] | |
35.1 | 61 | ||
35.2 | 62 | ||
35.1 | 63 | In this case, we set Fport Filter Level=1 and add the filter (server | fport | 0), when the gateway receives a Lorawan packet with Fport=0, it will be dropped. | |
64 | |||
41.1 | 65 | [[image:image-20220726165311-4.png||_mstalt="430287" height="718" width="798"]] | |
24.1 | 66 | ||
67 | |||
41.1 | 68 | [[image:image-20220726170532-5.png||_mstalt="431054"]] | |
24.1 | 69 | ||
70 | |||
35.2 | 71 | == 2.2 Filter By DevAddr == | |
33.2 | 72 | ||
24.1 | 73 | ||
33.1 | 74 | The Gateway DevAddr filter will check all the below LoRaWAN messages: Unconfirmed Data Up & Confirmed Data Up. | |
24.1 | 75 | ||
25.1 | 76 | ||
24.1 | 77 | (% style="color:red" %)**Important Notice:** | |
78 | |||
26.1 | 79 | * By default, DevAddr Filter (% style="color:blue" %)**Level=0**(%%). which means do nothing | |
24.1 | 80 | ||
26.1 | 81 | * 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. | |
24.1 | 82 | ||
26.1 | 83 | * 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. | |
24.1 | 84 | ||
41.1 | 85 | 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. | |
24.1 | 86 | ||
33.2 | 87 | ||
41.1 | 88 | [[image:image-20220726171555-7.png||_mstalt="433745" height="754" width="765"]] | |
24.1 | 89 | ||
90 | |||
41.1 | 91 | [[image:image-20220726171808-8.png||_mstalt="434434"]] | |
27.1 | 92 | ||
93 | |||
41.5 | 94 | (% style="color:red" %)**If user need to set the Secondary LoRaWAN Server Packet Filter, the configuration is similar to that above.** | |
27.1 | 95 | ||
38.1 | 96 | ||
41.6 | 97 | == 2.3 Filter By NwkID == | |
38.1 | 98 | ||
99 | |||
46.1 | 100 | Since firmware **dragino-lgw~-~-v5.4.1699325460**, the gateway supports NwkID filter. | |
41.1 | 101 | ||
102 | The Gateway NwkID filter will check all the below LoRaWAN messages: Unconfirmed Data Up & Confirmed Data Up. | ||
103 | |||
104 | |||
105 | (% style="color:red" %)**Important Notice:** | ||
106 | |||
107 | * By default, NwkID Filter (% style="color:blue" %)**Level=0**(%%). which means do nothing | ||
108 | |||
109 | * 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. | ||
110 | |||
111 | * 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. | ||
112 | |||
45.1 | 113 | 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. | |
41.1 | 114 | ||
115 | NwkID is calculated as follows: DevAddr counts shifted right by 25 bits | ||
116 | |||
45.1 | 117 | For example, Devaddr=01CC1907,NwkID= 01CC1907 >> 25 = 0 | |
41.1 | 118 | ||
45.1 | 119 | Devaddr=260B748A,NwkID= 260B748A >> 25 = 13 | |
41.1 | 120 | ||
121 | |||
45.1 | 122 | [[image:image-20231107105627-2.png||height="622" width="768"]] | |
123 | |||
124 | [[image:image-20231107105917-3.png||height="242" width="1011"]] | ||
125 | |||
126 | |||
41.5 | 127 | == 2.4 Add Filter rules via Linux Command. == | |
41.1 | 128 | ||
129 | |||
38.1 | 130 | (% class="box infomessage" %) | |
131 | ((( | ||
132 | $ sqlite3 /etc/lora/devskey "INSERT INTO filter (name, type, value ) VALUES ('$filter_name', '$filter_type', '$filter_value');" | ||
133 | |||
134 | |||
135 | |||
136 | name: server name. eg: server1/server2 | ||
137 | |||
138 | type: filter type. eg: fport/devaddr | ||
139 | |||
140 | value: 0,1,2,3/000000 | ||
141 | ))) | ||
142 | |||
143 | (% class="box" %) | ||
144 | ((( | ||
145 | eg: | ||
146 | |||
147 | sqlite3 /etc/lora/devskey "INSERT INTO filter (name, type, value ) VALUES ('server1', 'fport', '1');" | ||
148 | |||
149 | sqlite3 /etc/lora/devskey "INSERT INTO filter (name, type, value ) VALUES ('server1', 'devaddr', '00000000');" | ||
150 | |||
151 | sqlite3 /etc/lora/devskey "SELECT *from filter" | ||
152 | ))) | ||
153 | |||
41.6 | 154 | [[image:image-20230519104800-2.png||_mstalt="428714"]] | |
41.5 | 155 | ))) | |
38.1 | 156 | ||
157 | |||
35.2 | 158 | = 3. PKT_FWD Filter Mechanism = | |
27.1 | 159 | ||
160 | |||
41.4 | 161 | (% style="color:blue" %)**Support Devices:** | |
27.1 | 162 | ||
163 | * 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/]] | ||
35.4 | 164 | ||
27.1 | 165 | * LG308, DLOS8 | |
35.4 | 166 | ||
27.1 | 167 | * LPS8 | |
168 | |||
41.4 | 169 | (% style="color:blue" %)**Fport & DevAddr Filter** | |
35.4 | 170 | ||
41.1 | 171 | [[image:image-20220527150138-1.png||_mstalt="429598"]] | |
27.1 | 172 | ||
173 | |||
41.5 | 174 | (% style="color:blue" %)**Check if the filter is running** | |
27.1 | 175 | ||
41.1 | 176 | [[image:image-20220527150222-2.png||_mstalt="427921" height="379" width="1062"]] | |
27.1 | 177 | ||
178 | |||
35.2 | 179 | == 3.1 Filter By Fport == | |
27.1 | 180 | ||
181 | |||
182 | 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. | ||
183 | |||
184 | ((( | ||
185 | 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. | ||
186 | ))) | ||
187 | |||
41.1 | 188 | [[image:image-20220527150303-3.png||_mstalt="428285"]] | |
27.1 | 189 | ||
190 | |||
191 | 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. | ||
192 | |||
193 | |||
35.2 | 194 | == 3.2 Filter By DevAddr == | |
33.2 | 195 | ||
27.1 | 196 | ||
197 | 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. | ||
198 | |||
41.1 | 199 | [[image:image-20220527150404-4.png||_mstalt="429299"]] | |
27.1 | 200 | ||
201 | |||
202 | This screenshot shows packets is dropped if DevAddr mask doesn't match. | ||
203 | |||
204 |