init (first ubus try)
This commit is contained in:
commit
0decaae1eb
|
@ -0,0 +1,11 @@
|
||||||
|
# _______ ________ __
|
||||||
|
# | |.-----.-----.-----.| | | |.----.| |_
|
||||||
|
# | - || _ | -__| || | | || _|| _|
|
||||||
|
# |_______|| __|_____|__|__||________||__| |____|
|
||||||
|
# |__| W I R E L E S S F R E E D O M
|
||||||
|
#
|
||||||
|
# People listed here are managing the OpenWrt telephony
|
||||||
|
feed. Use
|
||||||
|
# alphabetical order when updating the list.
|
||||||
|
|
||||||
|
Martin/Geno <geno+dev@fireorbit.de>
|
|
@ -0,0 +1,28 @@
|
||||||
|
# Wifi control deamon packages feed
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
This is an OpenWrt package feed containing community
|
||||||
|
maintained wifictld packages.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
To use these packages, add the following line to the
|
||||||
|
feeds.conf
|
||||||
|
in the OpenWrt buildroot:
|
||||||
|
|
||||||
|
```
|
||||||
|
src-git wifictld git@dev.sum7.eu:wifictld/wifictld.git
|
||||||
|
```
|
||||||
|
|
||||||
|
This feed should be included and enabled by default in the
|
||||||
|
OpenWrt buildroot. To install all its package definitions,
|
||||||
|
run:
|
||||||
|
|
||||||
|
```
|
||||||
|
./scripts/feeds update wifictld
|
||||||
|
./scripts/feeds install -a -p wifictld
|
||||||
|
```
|
||||||
|
|
||||||
|
The wifictld packages should now appear in menuconfig.
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
PKG_NAME:=wifictld
|
||||||
|
PKG_VERSION:=1.0
|
||||||
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
|
PKG_MAINTAINER:=Martin/Geno <geno+dev@fireorbit.de>
|
||||||
|
PKG_LICENSE:=APGL
|
||||||
|
|
||||||
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|
||||||
|
define Package/wifictld/Default
|
||||||
|
SECTION:=net
|
||||||
|
CATEGORY:=Network
|
||||||
|
TITLE:=wireless control daemon
|
||||||
|
URL:=https://dev.sum7.eu/wifictld/wifictld
|
||||||
|
DEPENDS:=+libubus +libubox
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/wifictld
|
||||||
|
$(call Package/wifictld/Default)
|
||||||
|
TITLE+= (full)
|
||||||
|
VARIANT:=full
|
||||||
|
TARGET_CFLAGS += -DDEBUG
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/wifictld-mini
|
||||||
|
$(call Package/wifictld/Default)
|
||||||
|
TITLE+= (local)
|
||||||
|
VARIANT:=mini
|
||||||
|
TARGET_CFLAGS += -DMINI
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/wifictld/description
|
||||||
|
$(call Package/wifictld-mini/Default)
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/wifictld-mini/description
|
||||||
|
This package is a wifi control daemon
|
||||||
|
which use ubus to communicate with hostapd
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Build/Prepare
|
||||||
|
mkdir -p $(PKG_BUILD_DIR)
|
||||||
|
cp ./src/* $(PKG_BUILD_DIR)
|
||||||
|
$(Build/Patch)
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Build/Compile
|
||||||
|
$(MAKE) -C $(PKG_BUILD_DIR) CC="$(TARGET_CC)" CFLAGS="$(TARGET_CFLAGS)"
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/wifictld/install
|
||||||
|
$(INSTALL_DIR) $(1)/usr/sbin/
|
||||||
|
$(INSTALL_BIN) $(PKG_BUILD_DIR)/wifictld $(1)/usr/sbin/
|
||||||
|
endef
|
||||||
|
|
||||||
|
Package/wifictld-mini/install = $(Package/hostapd/install)
|
||||||
|
|
||||||
|
|
||||||
|
$(eval $(call BuildPackage,wifictld))
|
||||||
|
$(eval $(call BuildPackage,wifictld-mini))
|
|
@ -0,0 +1,23 @@
|
||||||
|
|
||||||
|
all: wifictld
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
CFLAGS = -Wall
|
||||||
|
LDFLAGS = -lubox -lubus
|
||||||
|
|
||||||
|
DEPS = $(wildcard *.h)
|
||||||
|
|
||||||
|
SRC = $(wildcard *.c)
|
||||||
|
|
||||||
|
OBJ = $(patsubst %.c, %.o, $(SRC))
|
||||||
|
|
||||||
|
%.o: %.c $(DEPS)
|
||||||
|
$(CC) -c -o $@ $< $(CFLAGS)
|
||||||
|
|
||||||
|
wifictld: $(OBJ)
|
||||||
|
$(CC) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f wifictld *.o
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef __WIFICTLD_LOG_H
|
||||||
|
#define __WIFICTLD_LOG_H
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define DEBUG_COMPILE 1
|
||||||
|
#else
|
||||||
|
#define DEBUG_COMPILE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define debug_print(fmt) \
|
||||||
|
do { if (DEBUG_COMPILE) fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
||||||
|
__LINE__, __func__); } while (0)
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,105 @@
|
||||||
|
#ifndef IEEE802_11_DEFS_H
|
||||||
|
#define IEEE802_11_DEFS_H
|
||||||
|
|
||||||
|
//TODO showd use hostapd/../src/common/ieee802_11_defs.h
|
||||||
|
|
||||||
|
/* Status codes (IEEE Std 802.11-2016, 9.4.1.9, Table 9-46) */
|
||||||
|
#define WLAN_STATUS_SUCCESS 0
|
||||||
|
#define WLAN_STATUS_UNSPECIFIED_FAILURE 1
|
||||||
|
#define WLAN_STATUS_TDLS_WAKEUP_ALTERNATE 2
|
||||||
|
#define WLAN_STATUS_TDLS_WAKEUP_REJECT 3
|
||||||
|
#define WLAN_STATUS_SECURITY_DISABLED 5
|
||||||
|
#define WLAN_STATUS_UNACCEPTABLE_LIFETIME 6
|
||||||
|
#define WLAN_STATUS_NOT_IN_SAME_BSS 7
|
||||||
|
#define WLAN_STATUS_CAPS_UNSUPPORTED 10
|
||||||
|
#define WLAN_STATUS_REASSOC_NO_ASSOC 11
|
||||||
|
#define WLAN_STATUS_ASSOC_DENIED_UNSPEC 12
|
||||||
|
#define WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG 13
|
||||||
|
#define WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION 14
|
||||||
|
#define WLAN_STATUS_CHALLENGE_FAIL 15
|
||||||
|
#define WLAN_STATUS_AUTH_TIMEOUT 16
|
||||||
|
#define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
|
||||||
|
#define WLAN_STATUS_ASSOC_DENIED_RATES 18
|
||||||
|
#define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
|
||||||
|
#define WLAN_STATUS_SPEC_MGMT_REQUIRED 22
|
||||||
|
#define WLAN_STATUS_PWR_CAPABILITY_NOT_VALID 23
|
||||||
|
#define WLAN_STATUS_SUPPORTED_CHANNEL_NOT_VALID 24
|
||||||
|
#define WLAN_STATUS_ASSOC_DENIED_NO_SHORT_SLOT_TIME 25
|
||||||
|
#define WLAN_STATUS_ASSOC_DENIED_NO_HT 27
|
||||||
|
#define WLAN_STATUS_R0KH_UNREACHABLE 28
|
||||||
|
#define WLAN_STATUS_ASSOC_DENIED_NO_PCO 29
|
||||||
|
#define WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY 30
|
||||||
|
#define WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION 31
|
||||||
|
#define WLAN_STATUS_UNSPECIFIED_QOS_FAILURE 32
|
||||||
|
#define WLAN_STATUS_DENIED_INSUFFICIENT_BANDWIDTH 33
|
||||||
|
#define WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS 34
|
||||||
|
#define WLAN_STATUS_DENIED_QOS_NOT_SUPPORTED 35
|
||||||
|
#define WLAN_STATUS_REQUEST_DECLINED 37
|
||||||
|
#define WLAN_STATUS_INVALID_PARAMETERS 38
|
||||||
|
#define WLAN_STATUS_REJECTED_WITH_SUGGESTED_CHANGES 39
|
||||||
|
#define WLAN_STATUS_INVALID_IE 40
|
||||||
|
#define WLAN_STATUS_GROUP_CIPHER_NOT_VALID 41
|
||||||
|
#define WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID 42
|
||||||
|
#define WLAN_STATUS_AKMP_NOT_VALID 43
|
||||||
|
#define WLAN_STATUS_UNSUPPORTED_RSN_IE_VERSION 44
|
||||||
|
#define WLAN_STATUS_INVALID_RSN_IE_CAPAB 45
|
||||||
|
#define WLAN_STATUS_CIPHER_REJECTED_PER_POLICY 46
|
||||||
|
#define WLAN_STATUS_TS_NOT_CREATED 47
|
||||||
|
#define WLAN_STATUS_DIRECT_LINK_NOT_ALLOWED 48
|
||||||
|
#define WLAN_STATUS_DEST_STA_NOT_PRESENT 49
|
||||||
|
#define WLAN_STATUS_DEST_STA_NOT_QOS_STA 50
|
||||||
|
#define WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE 51
|
||||||
|
#define WLAN_STATUS_INVALID_FT_ACTION_FRAME_COUNT 52
|
||||||
|
#define WLAN_STATUS_INVALID_PMKID 53
|
||||||
|
#define WLAN_STATUS_INVALID_MDIE 54
|
||||||
|
#define WLAN_STATUS_INVALID_FTIE 55
|
||||||
|
#define WLAN_STATUS_REQUESTED_TCLAS_NOT_SUPPORTED 56
|
||||||
|
#define WLAN_STATUS_INSUFFICIENT_TCLAS_PROCESSING_RESOURCES 57
|
||||||
|
#define WLAN_STATUS_TRY_ANOTHER_BSS 58
|
||||||
|
#define WLAN_STATUS_GAS_ADV_PROTO_NOT_SUPPORTED 59
|
||||||
|
#define WLAN_STATUS_NO_OUTSTANDING_GAS_REQ 60
|
||||||
|
#define WLAN_STATUS_GAS_RESP_NOT_RECEIVED 61
|
||||||
|
#define WLAN_STATUS_STA_TIMED_OUT_WAITING_FOR_GAS_RESP 62
|
||||||
|
#define WLAN_STATUS_GAS_RESP_LARGER_THAN_LIMIT 63
|
||||||
|
#define WLAN_STATUS_REQ_REFUSED_HOME 64
|
||||||
|
#define WLAN_STATUS_ADV_SRV_UNREACHABLE 65
|
||||||
|
#define WLAN_STATUS_REQ_REFUSED_SSPN 67
|
||||||
|
#define WLAN_STATUS_REQ_REFUSED_UNAUTH_ACCESS 68
|
||||||
|
#define WLAN_STATUS_INVALID_RSNIE 72
|
||||||
|
#define WLAN_STATUS_U_APSD_COEX_NOT_SUPPORTED 73
|
||||||
|
#define WLAN_STATUS_U_APSD_COEX_MODE_NOT_SUPPORTED 74
|
||||||
|
#define WLAN_STATUS_BAD_INTERVAL_WITH_U_APSD_COEX 75
|
||||||
|
#define WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ 76
|
||||||
|
#define WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED 77
|
||||||
|
#define WLAN_STATUS_CANNOT_FIND_ALT_TBTT 78
|
||||||
|
#define WLAN_STATUS_TRANSMISSION_FAILURE 79
|
||||||
|
#define WLAN_STATUS_REQ_TCLAS_NOT_SUPPORTED 80
|
||||||
|
#define WLAN_STATUS_TCLAS_RESOURCES_EXCHAUSTED 81
|
||||||
|
#define WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION 82
|
||||||
|
#define WLAN_STATUS_REJECT_WITH_SCHEDULE 83
|
||||||
|
#define WLAN_STATUS_REJECT_NO_WAKEUP_SPECIFIED 84
|
||||||
|
#define WLAN_STATUS_SUCCESS_POWER_SAVE_MODE 85
|
||||||
|
#define WLAN_STATUS_PENDING_ADMITTING_FST_SESSION 86
|
||||||
|
#define WLAN_STATUS_PERFORMING_FST_NOW 87
|
||||||
|
#define WLAN_STATUS_PENDING_GAP_IN_BA_WINDOW 88
|
||||||
|
#define WLAN_STATUS_REJECT_U_PID_SETTING 89
|
||||||
|
#define WLAN_STATUS_REFUSED_EXTERNAL_REASON 92
|
||||||
|
#define WLAN_STATUS_REFUSED_AP_OUT_OF_MEMORY 93
|
||||||
|
#define WLAN_STATUS_REJECTED_EMERGENCY_SERVICE_NOT_SUPPORTED 94
|
||||||
|
#define WLAN_STATUS_QUERY_RESP_OUTSTANDING 95
|
||||||
|
#define WLAN_STATUS_REJECT_DSE_BAND 96
|
||||||
|
#define WLAN_STATUS_TCLAS_PROCESSING_TERMINATED 97
|
||||||
|
#define WLAN_STATUS_TS_SCHEDULE_CONFLICT 98
|
||||||
|
#define WLAN_STATUS_DENIED_WITH_SUGGESTED_BAND_AND_CHANNEL 99
|
||||||
|
#define WLAN_STATUS_MCCAOP_RESERVATION_CONFLICT 100
|
||||||
|
#define WLAN_STATUS_MAF_LIMIT_EXCEEDED 101
|
||||||
|
#define WLAN_STATUS_MCCA_TRACK_LIMIT_EXCEEDED 102
|
||||||
|
#define WLAN_STATUS_DENIED_DUE_TO_SPECTRUM_MANAGEMENT 103
|
||||||
|
#define WLAN_STATUS_ASSOC_DENIED_NO_VHT 104
|
||||||
|
#define WLAN_STATUS_ENABLEMENT_DENIED 105
|
||||||
|
#define WLAN_STATUS_RESTRICTION_FROM_AUTHORIZED_GDB 106
|
||||||
|
#define WLAN_STATUS_AUTHORIZATION_DEENABLED 107
|
||||||
|
#define WLAN_STATUS_FILS_AUTHENTICATION_FAILURE 112
|
||||||
|
#define WLAN_STATUS_UNKNOWN_AUTHENTICATION_SERVER 113
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,120 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <libubox/blobmsg.h>
|
||||||
|
#include <libubox/ulog.h>
|
||||||
|
#include <libubus.h>
|
||||||
|
#include "temp_defs.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
static struct blob_buf b;
|
||||||
|
struct ubus_context *ctx_main;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int receive_request(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg)
|
||||||
|
{
|
||||||
|
const char *attr_name, *addr;
|
||||||
|
uint16_t freq, ssi_signal = -1;
|
||||||
|
struct blob_attr *pos;
|
||||||
|
int rem = blobmsg_data_len(msg);
|
||||||
|
|
||||||
|
// read msg
|
||||||
|
blobmsg_for_each_attr(pos, msg, rem) {
|
||||||
|
attr_name = blobmsg_name(pos);
|
||||||
|
|
||||||
|
if (!strcmp(attr_name, "address")){
|
||||||
|
addr = blobmsg_get_string(pos);
|
||||||
|
} else if(!strcmp(attr_name, "signal")){
|
||||||
|
ssi_signal = blobmsg_get_u32(pos);
|
||||||
|
} else if(!strcmp(attr_name, "freq")){
|
||||||
|
freq = blobmsg_get_u32(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
blob_buf_init(&b, 0);
|
||||||
|
blob_put_u32(&b, 0, WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA);
|
||||||
|
ubus_send_reply(ctx, req, b.head);
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!strcmp(method, "probe")) {
|
||||||
|
ULOG_NOTE("probe\n");
|
||||||
|
return WLAN_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
if (!strcmp(method, "auth")) {
|
||||||
|
if (freq <= 5000) {
|
||||||
|
ULOG_WARN("auth [drop]-> %s\n", addr);
|
||||||
|
return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
|
||||||
|
}
|
||||||
|
ULOG_WARN("auth [accept]-> %s\n", addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// learn by freq and address
|
||||||
|
|
||||||
|
ULOG_INFO("%s\n", method);
|
||||||
|
return WLAN_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct ubus_subscriber sub = {
|
||||||
|
.cb = receive_request,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void wifictld_ubus_interfaces(struct ubus_context *ctx, struct ubus_object_data *obj, void *priv)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
const char *str = "notify_response";
|
||||||
|
|
||||||
|
if (obj->path == NULL || !strstr(obj->path, "hostapd.")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//switch to notify
|
||||||
|
blob_buf_init(&b, 0);
|
||||||
|
blobmsg_add_u32(&b, str, 1);
|
||||||
|
ret = ubus_invoke(ctx, obj->id, str, b.head, NULL, NULL, 100);
|
||||||
|
if (ret) {
|
||||||
|
ULOG_ERR("Error while register response for event '%s': %s\n", obj->path, ubus_strerror(ret));
|
||||||
|
}
|
||||||
|
|
||||||
|
//subscribe
|
||||||
|
ret = ubus_subscribe(ctx, &sub, obj->id);
|
||||||
|
if (ret) {
|
||||||
|
ULOG_ERR("Error while register subscribe for event '%s': %s\n", obj->path, ubus_strerror(ret));
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("sub %s: %d:%d\n", obj->path, obj->id, obj->type_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
int wifictld_ubus_init()
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
ctx_main = ubus_connect(NULL);
|
||||||
|
if (!ctx_main) {
|
||||||
|
ULOG_ERR("Failed to connect to ubus");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ubus_register_subscriber(ctx_main, &sub);
|
||||||
|
if (ret) {
|
||||||
|
ULOG_ERR("Error while registering subscriber: %s", ubus_strerror(ret));
|
||||||
|
ubus_free(ctx_main);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
ubus_lookup(ctx_main, NULL, wifictld_ubus_interfaces, NULL);
|
||||||
|
|
||||||
|
ubus_add_uloop(ctx_main);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wifictld_ubus_close()
|
||||||
|
{
|
||||||
|
ubus_free(ctx_main);
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef __WIFICTLD_UBUS_EVENT_H
|
||||||
|
#define __WIFICTLD_UBUS_EVENT_H
|
||||||
|
|
||||||
|
#include <libubus.h>
|
||||||
|
|
||||||
|
int wifictld_ubus_init();
|
||||||
|
void wifictld_ubus_close();
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,31 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <libubox/ulog.h>
|
||||||
|
#include <libubus.h>
|
||||||
|
#include "ubus_events.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
#ifdef MINI
|
||||||
|
ULOG_NOTE("start wifictld (mini)\n");
|
||||||
|
#else
|
||||||
|
ULOG_NOTE("start wifictld (full)\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uloop_init();
|
||||||
|
|
||||||
|
//bind to loop
|
||||||
|
ret = wifictld_ubus_init();
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
uloop_run();
|
||||||
|
uloop_done();
|
||||||
|
|
||||||
|
|
||||||
|
wifictld_ubus_close();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue