mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-29 05:38:21 +00:00
wlan: netdev operations
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
#include <kernel/wlan.h>
|
||||
#include <u80211/u80211.h>
|
||||
#include <kernel/net.h>
|
||||
#include <kernel/eth.h>
|
||||
#include <logging.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define WLAN_MTU 1500
|
||||
|
||||
typedef struct {
|
||||
netdev_t netdev;
|
||||
void *driver_handle;
|
||||
@@ -13,6 +16,8 @@ typedef struct {
|
||||
int id;
|
||||
} wlan_device_t;
|
||||
|
||||
// TODO: change how netdesc_t is handled in kernel overall (?)
|
||||
// TODO: map u80211 errors to errnos
|
||||
// TODO: in u80211, change the device ops to take a (void *) handle
|
||||
// TODO: general netdev cleanup:
|
||||
// - use struct ops instead of having function pointers in netdev struct
|
||||
@@ -77,16 +82,42 @@ static u80211_device_ops_t ops = {
|
||||
.del_key = del_key
|
||||
};
|
||||
|
||||
static int wlan_alloc_desc(netdev_t *netdev, size_t requestedsize, netdesc_t *desc) {
|
||||
|
||||
static int wlan_alloc_desc(netdev_t *netdev, size_t requested_size, netdesc_t *desc) {
|
||||
wlan_device_t *wlan = (wlan_device_t *)netdev;
|
||||
|
||||
if (requested_size > WLAN_MTU)
|
||||
return E2BIG;
|
||||
|
||||
u80211_tx_buffer_descriptor_t u80211_desc;
|
||||
int status = u80211_allocate_tx_buffer(wlan->u80211_device, &u80211_desc);
|
||||
if (status != U80211_STATUS_SUCCESS)
|
||||
return EINVAL;
|
||||
|
||||
desc->address = u80211_desc.data;
|
||||
desc->curroffset = u80211_desc.current_offset;
|
||||
desc->size = u80211_desc.size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wlan_free_desc(netdev_t *netdev, netdesc_t *desc) {
|
||||
|
||||
// TODO: u80211 free descriptor call
|
||||
}
|
||||
|
||||
static int wlan_send_packet(netdev_t *_internal, netdesc_t desc, mac_t targetmac, int proto) {
|
||||
static int wlan_send_packet(netdev_t *netdev, netdesc_t desc, mac_t target, int proto) {
|
||||
wlan_device_t *wlan = (wlan_device_t *)netdev;
|
||||
|
||||
ethframe_t *ethframe = desc.address;
|
||||
ethframe->type = cpu_to_be_w(proto);
|
||||
memcpy(ðframe->source, &wlan->netdev.mac, sizeof(mac_t));
|
||||
memcpy(ðframe->destination, &target, sizeof(mac_t));
|
||||
|
||||
u80211_tx_buffer_descriptor_t descriptor = {
|
||||
.data = desc.address,
|
||||
.current_offset = desc.curroffset,
|
||||
.size = desc.size
|
||||
};
|
||||
|
||||
return u80211_transmit_buffer(wlan->u80211_device, &descriptor) == U80211_STATUS_SUCCESS ? 0 : EINVAL;
|
||||
}
|
||||
|
||||
int wlan_register(void *handle, const u80211_drv_device_metadata_t *drv_metadata, const u80211_drv_device_ops_t *drv_ops, u80211_drv_network_device_handle_t *network_device) {
|
||||
@@ -97,7 +128,7 @@ int wlan_register(void *handle, const u80211_drv_device_metadata_t *drv_metadata
|
||||
wlan->driver_handle = handle;
|
||||
wlan->ops = drv_ops;
|
||||
|
||||
wlan->netdev.mtu = 1500;
|
||||
wlan->netdev.mtu = WLAN_MTU;
|
||||
wlan->netdev.sendpacket = wlan_send_packet;
|
||||
wlan->netdev.allocdesc = wlan_alloc_desc;
|
||||
wlan->netdev.freedesc = wlan_free_desc;
|
||||
|
||||
Reference in New Issue
Block a user