Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Applications Sample Camera
提交
d9ac078d
A
Applications Sample Camera
项目概览
OpenHarmony
/
Applications Sample Camera
9 个月 前同步成功
通知
5
Star
25
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
Applications Sample Camera
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
d9ac078d
编写于
2月 26, 2022
作者:
O
openharmony_ci
提交者:
Gitee
2月 26, 2022
浏览文件
操作
浏览文件
下载
差异文件
!80 修复搜索Wifi蓝屏问题
Merge pull request !80 from 郝烁/master
上级
edab5b31
e31da587
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
62 addition
and
20 deletion
+62
-20
setting/setting/src/main/cpp/wpa_work.c
setting/setting/src/main/cpp/wpa_work.c
+61
-19
setting/setting/src/main/cpp/wpa_work.h
setting/setting/src/main/cpp/wpa_work.h
+1
-1
未找到文件。
setting/setting/src/main/cpp/wpa_work.c
浏览文件 @
d9ac078d
...
@@ -38,13 +38,13 @@
...
@@ -38,13 +38,13 @@
static
struct
wpa_ctrl
*
g_monitorConn
=
NULL
;
static
struct
wpa_ctrl
*
g_monitorConn
=
NULL
;
static
pthread_t
g_threadId
=
0
;
static
pthread_t
g_threadId
=
0
;
pthread_mutex_t
g_mutex
;
pthread_mutex_t
g_mutex
;
pthread_mutex_t
g_monitorConnMutex
;
static
char
g_mySsidD
[
40
][
40
]
=
{
0
};
static
char
g_mySsidD
[
40
][
40
]
=
{
0
};
static
int
g_ssidCount
=
0
;
static
int
g_ssidCount
=
0
;
static
char
g_useSsidD
[
40
][
40
]
=
{
0
};
static
char
g_useSsidD
[
40
][
40
]
=
{
0
};
static
int
g_useSsidCount
=
0
;
static
int
g_useSsidCount
=
0
;
static
struct
wpa_ctrl
*
g_ctrlConn
=
NULL
;
static
pthread_t
g_wpaThreadId
=
0
;
static
pthread_t
g_wpaThreadId
=
0
;
static
pthread_t
g_scanThreadId
=
0
;
static
pthread_t
g_scanThreadId
=
0
;
static
int
g_scanAvailable
=
0
;
static
int
g_scanAvailable
=
0
;
...
@@ -69,24 +69,28 @@ static int StrMatch(const char *a, const char *b)
...
@@ -69,24 +69,28 @@ static int StrMatch(const char *a, const char *b)
static
int
SendCtrlCommand
(
const
char
*
cmd
,
char
*
reply
,
size_t
*
replyLen
)
static
int
SendCtrlCommand
(
const
char
*
cmd
,
char
*
reply
,
size_t
*
replyLen
)
{
{
static
struct
wpa_ctrl
*
ctrlConn
=
NULL
;
int
i
=
0
;
int
i
=
0
;
int
reTime
=
5
;
int
reTime
=
5
;
while
(
i
++
<
reTime
)
{
// check wpa init success
while
(
i
++
<
reTime
)
{
// check wpa init success
g_
ctrlConn
=
wpa_ctrl_open
(
WPA_IFACE_NAME
);
ctrlConn
=
wpa_ctrl_open
(
WPA_IFACE_NAME
);
if
(
g_ctrlConn
>
0
)
{
if
(
ctrlConn
!=
NULL
)
{
break
;
break
;
}
}
sleep
(
1
);
sleep
(
1
);
}
}
if
(
g_
ctrlConn
==
NULL
)
{
if
(
ctrlConn
==
NULL
)
{
printf
(
"%s:%d [ERROR] control connect handle is null
\n
"
,
__FUNCTION__
,
__LINE__
);
printf
(
"%s:%d [ERROR] control connect handle is null
\n
"
,
__FUNCTION__
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
size_t
len
=
*
replyLen
-
1
;
size_t
len
=
*
replyLen
-
1
;
wpa_ctrl_request
(
g_
ctrlConn
,
cmd
,
strlen
(
cmd
),
reply
,
&
len
,
0
);
wpa_ctrl_request
(
ctrlConn
,
cmd
,
strlen
(
cmd
),
reply
,
&
len
,
0
);
DumpString
(
reply
,
len
,
"SendCtrlCommand raw return"
);
DumpString
(
reply
,
len
,
"SendCtrlCommand raw return"
);
wpa_ctrl_close
(
g_ctrlConn
);
if
(
ctrlConn
!=
NULL
)
{
g_ctrlConn
=
NULL
;
wpa_ctrl_close
(
ctrlConn
);
ctrlConn
=
NULL
;
}
if
(
len
!=
0
&&
!
StrMatch
(
reply
,
WPA_CTRL_REQUEST_FAIL
))
{
if
(
len
!=
0
&&
!
StrMatch
(
reply
,
WPA_CTRL_REQUEST_FAIL
))
{
*
replyLen
=
len
;
*
replyLen
=
len
;
return
0
;
return
0
;
...
@@ -197,11 +201,13 @@ void ExitWpaScan(void)
...
@@ -197,11 +201,13 @@ void ExitWpaScan(void)
void
ExitWpa
(
void
)
void
ExitWpa
(
void
)
{
{
int
ret
;
int
ret
;
pthread_mutex_lock
(
&
g_monitorConnMutex
);
if
(
g_monitorConn
!=
NULL
)
{
if
(
g_monitorConn
!=
NULL
)
{
wpa_ctrl_close
(
g_monitorConn
);
wpa_ctrl_close
(
g_monitorConn
);
printf
(
"[INFO]wpa_ctrl_close(g_monitorConn).
\n
"
);
printf
(
"[INFO]wpa_ctrl_close(g_monitorConn).
\n
"
);
g_monitorConn
=
NULL
;
g_monitorConn
=
NULL
;
}
}
pthread_mutex_unlock
(
&
g_monitorConnMutex
);
char
result
[
100
]
=
{
0
};
char
result
[
100
]
=
{
0
};
size_t
len
=
sizeof
(
result
);
size_t
len
=
sizeof
(
result
);
printf
(
"[INFO]ExitWpa TERMINATE begin.
\n
"
);
printf
(
"[INFO]ExitWpa TERMINATE begin.
\n
"
);
...
@@ -220,6 +226,10 @@ void ExitWpa(void)
...
@@ -220,6 +226,10 @@ void ExitWpa(void)
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
printf
(
"[ERROR]pthread_mutex_destroy ret -> %d
\n
"
,
ret
);
printf
(
"[ERROR]pthread_mutex_destroy ret -> %d
\n
"
,
ret
);
}
}
ret
=
pthread_mutex_destroy
(
&
g_monitorConnMutex
);
if
(
ret
!=
0
)
{
printf
(
"[ERROR]pthread_mutex_destroy ret -> %d
\n
"
,
ret
);
}
}
}
int
GetAndResetScanStat
(
void
)
int
GetAndResetScanStat
(
void
)
...
@@ -317,18 +327,27 @@ static void WifiEventHandler(char *rawEvent, int len)
...
@@ -317,18 +327,27 @@ static void WifiEventHandler(char *rawEvent, int len)
static
void
CliRecvPending
(
void
)
static
void
CliRecvPending
(
void
)
{
{
while
(
wpa_ctrl_pending
(
g_monitorConn
))
{
int
pendingResult
=
-
1
;
pthread_mutex_lock
(
&
g_monitorConnMutex
);
if
(
g_monitorConn
!=
NULL
)
{
pendingResult
=
wpa_ctrl_pending
(
g_monitorConn
);
}
while
(
pendingResult
>
0
)
{
char
buf
[
4096
];
char
buf
[
4096
];
size_t
len
=
sizeof
(
buf
)
-
1
;
size_t
len
=
sizeof
(
buf
)
-
1
;
if
(
wpa_ctrl_recv
(
g_monitorConn
,
buf
,
&
len
)
==
0
)
{
if
(
g_monitorConn
!=
NULL
)
{
buf
[
len
]
=
'\0'
;
if
(
wpa_ctrl_recv
(
g_monitorConn
,
buf
,
&
len
)
==
0
)
{
SAMPLE_INFO
(
"event received %s"
,
buf
);
buf
[
len
]
=
'\0'
;
WifiEventHandler
(
buf
,
len
);
SAMPLE_INFO
(
"event received %s"
,
buf
);
}
else
{
WifiEventHandler
(
buf
,
len
);
SAMPLE_INFO
(
"could not read pending message."
);
}
else
{
break
;
SAMPLE_INFO
(
"could not read pending message."
);
break
;
}
pendingResult
=
wpa_ctrl_pending
(
g_monitorConn
);
}
}
}
}
pthread_mutex_lock
(
&
g_monitorConnMutex
);
}
}
static
void
*
MonitorTask
(
void
*
args
)
static
void
*
MonitorTask
(
void
*
args
)
...
@@ -337,7 +356,15 @@ static void* MonitorTask(void *args)
...
@@ -337,7 +356,15 @@ static void* MonitorTask(void *args)
int
fd
,
ret
;
int
fd
,
ret
;
fd_set
rfd
;
fd_set
rfd
;
while
(
1
)
{
while
(
1
)
{
fd
=
wpa_ctrl_get_fd
(
g_monitorConn
);
fd
=
-
1
;
pthread_mutex_lock
(
&
g_monitorConnMutex
);
if
(
g_monitorConn
!=
NULL
)
{
fd
=
wpa_ctrl_get_fd
(
g_monitorConn
);
}
else
{
pthread_mutex_unlock
(
&
g_monitorConnMutex
);
break
;
}
pthread_mutex_unlock
(
&
g_monitorConnMutex
);
FD_ZERO
(
&
rfd
);
FD_ZERO
(
&
rfd
);
FD_SET
(
fd
,
&
rfd
);
FD_SET
(
fd
,
&
rfd
);
ret
=
select
(
fd
+
1
,
&
rfd
,
NULL
,
NULL
,
NULL
);
ret
=
select
(
fd
+
1
,
&
rfd
,
NULL
,
NULL
,
NULL
);
...
@@ -408,7 +435,7 @@ int InitControlInterface()
...
@@ -408,7 +435,7 @@ int InitControlInterface()
int
reTime
=
5
;
int
reTime
=
5
;
while
(
i
++
<
reTime
)
{
// create control interface for event monitor
while
(
i
++
<
reTime
)
{
// create control interface for event monitor
g_monitorConn
=
wpa_ctrl_open
(
WPA_IFACE_NAME
);
g_monitorConn
=
wpa_ctrl_open
(
WPA_IFACE_NAME
);
if
(
g_
ctrlConn
>
0
)
{
if
(
g_
monitorConn
!=
NULL
)
{
break
;
break
;
}
}
sleep
(
1
);
sleep
(
1
);
...
@@ -417,7 +444,13 @@ int InitControlInterface()
...
@@ -417,7 +444,13 @@ int InitControlInterface()
SAMPLE_ERROR
(
"open wpa control interface failed."
);
SAMPLE_ERROR
(
"open wpa control interface failed."
);
return
-
1
;
return
-
1
;
}
}
ret
=
wpa_ctrl_attach
(
g_monitorConn
);
ret
=
-
1
;
pthread_mutex_lock
(
&
g_monitorConnMutex
);
if
(
g_monitorConn
!=
NULL
)
{
ret
=
wpa_ctrl_attach
(
g_monitorConn
);
}
pthread_mutex_unlock
(
&
g_monitorConnMutex
);
printf
(
"[INFO]wpa_ctrl_attach return %d.
\n
"
,
ret
);
printf
(
"[INFO]wpa_ctrl_attach return %d.
\n
"
,
ret
);
if
(
ret
==
0
)
{
// start monitor
if
(
ret
==
0
)
{
// start monitor
ret
=
pthread_create
(
&
g_wpaThreadId
,
NULL
,
MonitorTask
,
NULL
);
// create thread for read event
ret
=
pthread_create
(
&
g_wpaThreadId
,
NULL
,
MonitorTask
,
NULL
);
// create thread for read event
...
@@ -435,7 +468,7 @@ void* WpaScanThread(void *args)
...
@@ -435,7 +468,7 @@ void* WpaScanThread(void *args)
int
mySleep
=
2
;
int
mySleep
=
2
;
int
ret
=
0
;
int
ret
=
0
;
sleep
(
mySleep
);
sleep
(
mySleep
);
if
(
g_
ctrl
Conn
==
NULL
)
{
if
(
g_
monitor
Conn
==
NULL
)
{
ret
=
InitControlInterface
();
ret
=
InitControlInterface
();
printf
(
"%s:%d [INFO] InitControlInterface return %d.
\n
"
,
__FUNCTION__
,
__LINE__
,
ret
);
printf
(
"%s:%d [INFO] InitControlInterface return %d.
\n
"
,
__FUNCTION__
,
__LINE__
,
ret
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
...
@@ -495,6 +528,15 @@ void WpaClientStart(void)
...
@@ -495,6 +528,15 @@ void WpaClientStart(void)
printf
(
"[ERROR]pthread_mutex_init error %s
\n
"
,
strerror
(
ret
));
printf
(
"[ERROR]pthread_mutex_init error %s
\n
"
,
strerror
(
ret
));
return
;
return
;
}
}
pthread_mutexattr_t
attr
;
pthread_mutexattr_init
(
&
attr
);
pthread_mutexattr_settype
(
&
attr
,
PTHREAD_MUTEX_RECURSIVE
);
ret
=
pthread_mutex_init
(
&
g_monitorConnMutex
,
&
attr
);
if
(
ret
!=
0
)
{
printf
(
"[ERROR]pthread_mutex_init error %s
\n
"
,
strerror
(
ret
));
return
;
}
runStatus
=
1
;
runStatus
=
1
;
}
}
}
}
setting/setting/src/main/cpp/wpa_work.h
浏览文件 @
d9ac078d
...
@@ -41,7 +41,7 @@ extern "C" {
...
@@ -41,7 +41,7 @@ extern "C" {
void
ResetSSIDBuff
(
void
);
void
ResetSSIDBuff
(
void
);
int
GetIdNum
(
void
);
int
GetIdNum
(
void
);
int
GetAndResetScanStat
(
void
);
int
GetAndResetScanStat
(
void
);
char
*
GetSsid
(
int
ssidNum
);
char
*
GetSsid
(
const
int
ssidNum
);
void
WpaScanReconnect
(
const
char
*
gSsid
,
const
char
*
gPassWord
,
const
int
hiddenSwitch
);
void
WpaScanReconnect
(
const
char
*
gSsid
,
const
char
*
gPassWord
,
const
int
hiddenSwitch
);
void
WpaClientStart
(
void
);
void
WpaClientStart
(
void
);
void
LockWifiData
(
void
);
void
LockWifiData
(
void
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录