hc
2023-02-13 e440ec23c5a540cdd3f7464e8779219be6fd3d95
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 * Copyright (c) 2015 South Silicon Valley Microelectronics Inc.
 * Copyright (c) 2015 iComm Corporation
 *
 * This program is free software: you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License 
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
 
#include <ssv6200.h>
#include "dev.h"
#include "sar.h"
#ifdef CONFIG_SSV_SUPPORT_ANDROID
#ifdef CONFIG_HAS_WAKELOCK
#include <linux/wakelock.h>
#endif
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#elif LINUX_VERSION_CODE > KERNEL_VERSION(3, 4, 0)
#include <linux/notifier.h>
#include <linux/fb.h>
#endif
struct ssv_softc *ssv_notify_sc = NULL;
EXPORT_SYMBOL(ssv_notify_sc);
#if defined(CONFIG_HAS_EARLYSUSPEND) || (LINUX_VERSION_CODE > KERNEL_VERSION(3, 4, 0))
#ifdef CONFIG_HAS_EARLYSUSPEND
void ssv6xxx_early_suspend(struct early_suspend *h)
#else
void ssv6xxx_early_suspend(void)
#endif
{
#ifdef CONFIG_HAS_EARLYSUSPEND
    struct ssv_softc *sc = container_of(h, struct ssv_softc, early_suspend);
#else
    struct ssv_softc *sc = ssv_notify_sc;
#endif
    sc->ps_status = PWRSV_PREPARE;
    if (sc->is_sar_enabled) {
        cancel_delayed_work(&sc->thermal_monitor_work);
        flush_workqueue(sc->thermal_wq);
    }
    printk(KERN_INFO "ssv6xxx_early_suspend\n");
    ssv6xxx_watchdog_controller(sc->sh ,(u8)SSV6XXX_HOST_CMD_WATCHDOG_STOP);
    sc->watchdog_flag = WD_SLEEP;
}
#define DEAUTH_DISASSOC_LEN (24 + 2 )
void ssv6xxx_send_deauth_toself(struct ssv_softc *sc,const u8 *bssid,const u8 *self_addr)
{
    struct sk_buff *deauth_skb ;
 u8 frame_buf[DEAUTH_DISASSOC_LEN];
    struct ieee80211_mgmt *mgmt = (void *)frame_buf;
 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH);
 mgmt->duration = 0;
 mgmt->seq_ctrl = 0;
 memcpy(mgmt->da, self_addr, ETH_ALEN);
 memcpy(mgmt->sa, bssid, ETH_ALEN);
 memcpy(mgmt->bssid, bssid, ETH_ALEN);
 mgmt->u.deauth.reason_code = cpu_to_le16(2);
 {
  deauth_skb = dev_alloc_skb(DEAUTH_DISASSOC_LEN);
  if (!deauth_skb)
   return;
  memcpy(skb_put(deauth_skb, DEAUTH_DISASSOC_LEN),
         mgmt, DEAUTH_DISASSOC_LEN);
        #if defined(USE_THREAD_RX) && !defined(IRQ_PROC_RX_DATA)
        local_bh_disable();
        ieee80211_rx(sc->hw, deauth_skb);
        local_bh_enable();
        #else
        ieee80211_rx_irqsafe(sc->hw, deauth_skb);
        #endif
     return;
 }
}
#ifdef CONFIG_HAS_EARLYSUSPEND
void ssv6xxx_late_resume(struct early_suspend *h)
#else
void ssv6xxx_late_resume(void)
#endif
{
#ifdef CONFIG_HAS_EARLYSUSPEND
 struct ssv_softc *sc = container_of(h, struct ssv_softc, early_suspend);
#else
 struct ssv_softc *sc = ssv_notify_sc;
#endif
   if (!sc)
       return;
    if(sc->ps_status == PWRSV_ENABLE)
    {
        if(sc->vif_info[0].vif)
        {
            if(sc->vif_info[0].vif->bss_conf.assoc)
            {
                printk("sc->vif_info[0].vif->bss_conf.assoc\n");
                if ((sc->vif_info[0].vif->type == NL80211_IFTYPE_STATION) || (sc->vif_info[0].vif->p2p))
                {
                    printk("sc->vif_info[0].vif->bss_conf.assoc ssv6xxx_send_deauth_toself\n");
                    ssv6xxx_send_deauth_toself(sc, sc->vif_info[0].vif->bss_conf.bssid, sc->vif_info[0].vif->addr);
                }
            }
        }
        if(sc->vif_info[1].vif)
        {
            if(sc->vif_info[1].vif->bss_conf.assoc)
            {
                printk("sc->vif_info[1].vif->bss_conf.assoc\n");
                if ((sc->vif_info[1].vif->type == NL80211_IFTYPE_STATION) || (sc->vif_info[1].vif->p2p))
                {
                    printk("sc->vif_info[1].vif->bss_conf.assoc ssv6xxx_send_deauth_toself\n");
                    ssv6xxx_send_deauth_toself(sc, sc->vif_info[1].vif->bss_conf.bssid, sc->vif_info[1].vif->addr);
                }
            }
        }
    }
    if(sc)
        ssv6xxx_disable_ps(sc);
    else
        printk(KERN_INFO "ssv6xxx_late_resume,sc=NULL\n");
    if (sc->is_sar_enabled) {
        queue_delayed_work(sc->thermal_wq, &sc->thermal_monitor_work, THERMAL_MONITOR_TIME);
    }
    ssv6xxx_watchdog_controller(sc->sh ,(u8)SSV6XXX_HOST_CMD_WATCHDOG_START);
    sc->watchdog_flag = WD_KICKED;
    printk(KERN_INFO "ssv6xxx_late_resume\n");
}
#ifndef CONFIG_HAS_EARLYSUSPEND
static int ssv_wlan_fb_event_notify(struct notifier_block *self,
                       unsigned long action, void *data)
{
        struct fb_event *event = data;
        int blank_mode = *((int *)event->data);
        if (action == FB_EARLY_EVENT_BLANK) {
                switch (blank_mode) {
                case FB_BLANK_UNBLANK:
                        break;
                default:
      ssv6xxx_early_suspend();
                        break;
                }
        }
   else if (action == FB_EVENT_BLANK) {
                switch (blank_mode) {
                case FB_BLANK_UNBLANK:
      ssv6xxx_late_resume();
                        break;
                default:
                        break;
                }
        }
        return NOTIFY_OK;
}
struct notifier_block ssv_wlan_fb_notifier = {
    .notifier_call = ssv_wlan_fb_event_notify,
};
#endif
#endif
void ssv_wakelock_init(struct ssv_softc *sc)
{
#ifdef CONFIG_HAS_WAKELOCK
    wake_lock_init(&sc->ssv_wake_lock_, WAKE_LOCK_SUSPEND, "ssv6051");
#endif
#ifndef CONFIG_HAS_EARLYSUSPEND
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0)
 fb_register_client(&ssv_wlan_fb_notifier);
#endif
#endif
}
void ssv_wakelock_destroy(struct ssv_softc *sc)
{
#ifdef CONFIG_HAS_WAKELOCK
    wake_lock_destroy(&sc->ssv_wake_lock_);
#endif
#ifndef CONFIG_HAS_EARLYSUSPEND
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0)
 fb_unregister_client(&ssv_wlan_fb_notifier);
#endif
#endif
}
void ssv_wake_lock(struct ssv_softc *sc)
{
#ifdef CONFIG_HAS_WAKELOCK
    wake_lock(&sc->ssv_wake_lock_);
#endif
}
void ssv_wake_timeout(struct ssv_softc *sc, int secs)
{
#ifdef CONFIG_HAS_WAKELOCK
    wake_lock_timeout(&sc->ssv_wake_lock_,secs*HZ);
#endif
}
void ssv_wake_unlock(struct ssv_softc *sc)
{
#ifdef CONFIG_HAS_WAKELOCK
    wake_unlock(&sc->ssv_wake_lock_);
#endif
}
#endif