wifi: run wpa_main in pthread

This commit is contained in:
Christian Helmuth 2019-12-18 15:01:09 +01:00
parent 73d089da36
commit 8699f5592f
4 changed files with 69 additions and 21 deletions

View File

@ -111,7 +111,6 @@ struct Main
_wifi_frontend = &*_frontend;
_wpa.construct(env, _wpa_startup_lock);
_wpa->start();
/*
* Forcefully disable 11n but for convenience the attribute is used the

View File

@ -1,9 +1,9 @@
REQUIRES = x86
TARGET = wifi_drv
SRC_CC = main.cc
SRC_CC = main.cc wpa.cc
LIBS = base wifi iwl_firmware
LIBS += wpa_supplicant
LIBS += wpa_supplicant libc
# needed for firmware.h
INC_DIR += $(REP_DIR)/src/lib/wifi/include

View File

@ -0,0 +1,57 @@
/*
* \brief Wpa_supplicant thread of the wifi driver
* \author Josef Soentgen
* \author Christian Helmuth
* \date 2019-12-18
*/
/*
* Copyright (C) 2019 Genode Labs GmbH
*
* This file is distributed under the terms of the GNU General Public License
* version 2.
*/
/* Genode includes */
#include <base/env.h>
#include <base/lock.h>
#include <base/sleep.h>
/* libc includes */
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include "wpa.h"
/* entry function */
extern "C" int wpa_main(void);
void * Wpa_thread::_entry_trampoline(void *arg)
{
Wpa_thread *t = (Wpa_thread *)arg;
t->_entry();
return nullptr;
}
void Wpa_thread::_entry()
{
/* wait until the wifi driver is up and running */
_lock.lock();
_exit = wpa_main();
Genode::sleep_forever();
}
Wpa_thread::Wpa_thread(Genode::Env &env, Genode::Lock &lock)
: _lock(lock), _exit(-1)
{
pthread_t tid = 0;
if (pthread_create(&tid, 0, _entry_trampoline, this) != 0) {
printf("Error: pthread_create() failed\n");
exit(-1);
}
}

View File

@ -14,34 +14,26 @@
#ifndef _WIFI__WPA_H_
#define _WIFI__WPA_H_
/* Genode includes */
#include <base/sleep.h>
/* entry function */
extern "C" int wpa_main(void);
namespace Genode {
struct Env;
struct Lock;
}
class Wpa_thread : public Genode::Thread
class Wpa_thread
{
private:
Genode::Lock &_lock;
int _exit;
static void * _entry_trampoline(void *arg);
void _entry();
public:
Wpa_thread(Genode::Env &env, Genode::Lock &lock)
:
Thread(env, "wpa_supplicant", 8*1024*sizeof(long)),
_lock(lock), _exit(-1)
{ }
void entry()
{
/* wait until the wifi driver is up and running */
_lock.lock();
_exit = wpa_main();
Genode::sleep_forever();
}
Wpa_thread(Genode::Env &env, Genode::Lock &lock);
};
#endif /* _WIFI__WPA_H_ */