1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#include "wlan_includes.h"
DEFINE_SPINLOCK(rssi_buf_lock);
void wlan_add_new_aver_rssi(wlan_private * priv, u8 * bssid, u8 rssi)
{
t_aver_bssid_rssi * list = (t_aver_bssid_rssi *)kmalloc(sizeof(t_aver_bssid_rssi), GFP_KERNEL);
if(!list)
return;
list->dirty = 0;
memset(list->rssi, 0, sizeof(list->rssi));
if(((s8)rssi) > 0)
rssi -= 0x100;
else if(((s8)rssi) > -20)
rssi = ((s8)rssi) - 20;
list->rssi[0] = rssi;
list->index = 1;
list->count = 1;
memcpy(list->bssid, bssid, 6);
spin_lock(&rssi_buf_lock);
list_add_tail(&list->list, &priv->AverRssiQ);
spin_unlock(&rssi_buf_lock);
}
t_aver_bssid_rssi* wlan_find_bssid_in_aver_rssi(wlan_private * priv, u8 * bssid)
{
t_aver_bssid_rssi * rssi_list = NULL;
spin_lock(&rssi_buf_lock);
if(list_empty(&priv->AverRssiQ)){
spin_unlock(&rssi_buf_lock);
return NULL;
}
list_for_each_entry(rssi_list, &priv->AverRssiQ, list){
if(memcmp(bssid, rssi_list->bssid, 6) == 0){
spin_unlock(&rssi_buf_lock);
return rssi_list;
}
}
spin_unlock(&rssi_buf_lock);
return NULL;
}
void wlan_set_aver_rssi(t_aver_bssid_rssi* aver_rssi, u8 rssi)
{
u8 index = 0;
u8 *ch = 0;
ch = aver_rssi->bssid;
if(((s8)rssi) > 0)
rssi -= 0x100;
else if(((s8)rssi) > -20)
rssi = ((s8)rssi) - 20;
index = aver_rssi->index;
aver_rssi->rssi[index] = rssi;
index = (index + 1)%MAX_RSSI_RECORD;
aver_rssi->index = index;
if(aver_rssi->count < MAX_RSSI_RECORD)
aver_rssi->count ++;
if(aver_rssi->dirty > 0)
aver_rssi->dirty --;
}
void wlan_update_aver_rssi(wlan_private * priv, u8 * bssid, u8 rssi)
{
t_aver_bssid_rssi* aver_rssi = NULL;
aver_rssi = wlan_find_bssid_in_aver_rssi(priv, bssid);
if(aver_rssi)
wlan_set_aver_rssi(aver_rssi, rssi);
else
wlan_add_new_aver_rssi(priv, bssid, rssi);
}
s8 wlan_cal_aver_rssi(t_aver_bssid_rssi* aver_rssi)
{
s32 rssi = 0;
u8 i = 0, count = 0;
count = aver_rssi->count;
for(i = 0; i < count; i ++){
rssi += (s8)aver_rssi->rssi[i];
}
//-15 was hardware diff
return ((s8)(rssi/count)) - 15;
}
s8 wlan_get_aver_rssi(wlan_private * priv, u8 * bssid)
{
t_aver_bssid_rssi * rssi_list = NULL;
rssi_list = wlan_find_bssid_in_aver_rssi(priv, bssid);
if(rssi_list)
return wlan_cal_aver_rssi(rssi_list);
else{
return INVALID_RSSI;
}
}
void wlan_set_rssi_dirty(wlan_private * priv)
{
t_aver_bssid_rssi * rssi_list = NULL, *next = NULL;
spin_lock(&rssi_buf_lock);
if(list_empty(&priv->AverRssiQ)){
spin_unlock(&rssi_buf_lock);
return;
}
list_for_each_entry_safe(rssi_list, next, &priv->AverRssiQ, list){
rssi_list->dirty ++;
if(rssi_list->dirty >= MAX_RSSI_RECORD){
if(memcmp(rssi_list->bssid, priv->curbssparams.bssid, 6) != 0){
list_del(&rssi_list->list);
kfree(rssi_list);
}
}
}
spin_unlock(&rssi_buf_lock);
}
void wlan_free_aver_rssi(wlan_private * priv)
{
t_aver_bssid_rssi * rssi_list = NULL, *next = NULL;
spin_lock(&rssi_buf_lock);
if(list_empty(&priv->AverRssiQ)){
spin_unlock(&rssi_buf_lock);
return;
}
list_for_each_entry_safe(rssi_list, next, &priv->AverRssiQ, list){
list_del(&rssi_list->list);
kfree(rssi_list);
}
spin_unlock(&rssi_buf_lock);
}
|