first commit
This commit is contained in:
30
external/cache/sources/wl/dhd/Android.mk
vendored
Normal file
30
external/cache/sources/wl/dhd/Android.mk
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
#OBJS_c := dhdu.c dhdu_linux.c bcmutils.c miniopt.c
|
||||
OBJS_c := dhdu.c dhdu_linux.c ucode_download.c
|
||||
#OBJS_c += ../shared/bcmutils.c ../shared/miniopt.c ../shared/wlu_pipe.c ../shared/wlu_pipe_linux.c ../shared/wlu_client_shared.c
|
||||
INCLUDES := $(LOCAL_PATH)/../include $(LOCAL_PATH)/../shared
|
||||
L_CFLAGS := -DBCMWPA2 -DWLCNT -DWLBTAMP -Wextra -DWLPFN -DWLPFN_AUTO_CONNECT -DLINUX -DRWLASD -DRWL_SOCKET -DRWL_DONGLE -DRWL_WIFI
|
||||
L_CFLAGS += -DSDTEST -DTARGETENV_android -Dlinux -DLINUX
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := dhd
|
||||
LOCAL_MODULE_TAGS := debug tests
|
||||
LOCAL_SHARED_LIBRARIES := libcutils
|
||||
LOCAL_STATIC_LIBRARIES := libshared
|
||||
LOCAL_CFLAGS = $(L_CFLAGS)
|
||||
LOCAL_SRC_FILES := $(OBJS_c)
|
||||
LOCAL_C_INCLUDES := $(INCLUDES)
|
||||
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := libdhd
|
||||
LOCAL_MODULE_TAGS := debug tests
|
||||
LOCAL_SHARED_LIBRARIES := libcutils
|
||||
LOCAL_STATIC_LIBRARIES := libshared
|
||||
LOCAL_CFLAGS = $(L_CFLAGS)
|
||||
LOCAL_CFLAGS += -DLIB
|
||||
LOCAL_SRC_FILES := $(OBJS_c)
|
||||
LOCAL_C_INCLUDES := $(INCLUDES)
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
41
external/cache/sources/wl/dhd/Makefile
vendored
Normal file
41
external/cache/sources/wl/dhd/Makefile
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
CC = $(CROSS_COMPILE)gcc
|
||||
|
||||
#IFLAGS := -I../include -I../wl -I../shared -g -Wall -static
|
||||
IFLAGS := -I../include -I../wl -I../shared -g -Wall
|
||||
DFLAGS := -DBCMWPA2 -DWLCNT -DWLBTAMP -Wextra -DWLPFN -DWLPFN_AUTO_CONNECT -DLINUX -DRWLASD -DRWL_SOCKET -DRWL_DONGLE -DRWL_WIFI
|
||||
#IFLAGS += -DIL_BIGENDIAN
|
||||
|
||||
obj-dhd = dhdu.o dhdu_linux.o ucode_download.o
|
||||
|
||||
DHD = dhd
|
||||
ALL = all
|
||||
LIBLINK := ../shared/libshared.a
|
||||
LIBDHD = libdhd.a
|
||||
|
||||
CFLAGS += $(IFLAGS) $(DFLAGS)
|
||||
ifeq ($(LIB),y)
|
||||
CFLAGS += -DLIB
|
||||
endif
|
||||
|
||||
all: $(ALL)
|
||||
|
||||
$(ALL):
|
||||
make clean
|
||||
make $(DHD)
|
||||
mv dhd dhd.back
|
||||
make clean
|
||||
make $(LIBDHD) LIB=y
|
||||
mv dhd.back dhd
|
||||
|
||||
$(DHD): $(obj-dhd)
|
||||
$(CC) -o $@ $(obj-dhd) $(LIBLINK)
|
||||
|
||||
$(LIBDHD): $(obj-dhd)
|
||||
ar rscv $(LIBDHD) $(obj-dhd) $(LIBLINK)
|
||||
# $(CC) $(obj-dhd) -shared -o $(LIBDHD) $(LIBLINK)
|
||||
|
||||
# for sequance
|
||||
# $(CC) -Wl,-elf2flt -o $@ $(obj-dhd)
|
||||
|
||||
clean:
|
||||
-rm -f $(DHD) *.o *.a *.so
|
||||
3103
external/cache/sources/wl/dhd/dhdu.c
vendored
Normal file
3103
external/cache/sources/wl/dhd/dhdu.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
51
external/cache/sources/wl/dhd/dhdu.h
vendored
Normal file
51
external/cache/sources/wl/dhd/dhdu.h
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Definitions for DHD command-line utility
|
||||
*
|
||||
* $Copyright Open Broadcom Corporation$
|
||||
*
|
||||
* $Id: dhdu.h 294362 2011-11-06 22:26:56Z $
|
||||
*/
|
||||
|
||||
#ifndef _dhdu_h_
|
||||
#define _dhdu_h_
|
||||
|
||||
#include "dhdu_cmd.h"
|
||||
|
||||
extern char *dhdu_av0;
|
||||
|
||||
/* parse common option */
|
||||
extern int dhd_option(char ***pargv, char **pifname, int *phelp);
|
||||
extern void dhd_cmd_init(void);
|
||||
|
||||
/* print usage */
|
||||
extern void dhd_cmd_usage(cmd_t *cmd);
|
||||
extern void dhd_usage(cmd_t *port_cmds);
|
||||
extern void dhd_cmds_usage(cmd_t *port_cmds);
|
||||
|
||||
/* print helpers */
|
||||
extern void dhd_printlasterror(void *dhd);
|
||||
extern void dhd_printint(int val);
|
||||
|
||||
/* check driver version */
|
||||
extern int dhd_check(void *dhd);
|
||||
|
||||
/* utility functions */
|
||||
struct ipv4_addr;
|
||||
int dhd_ether_atoe(const char *a, struct ether_addr *n);
|
||||
int dhd_atoip(const char *a, struct ipv4_addr *n);
|
||||
|
||||
#define USAGE_ERROR -1 /* Error code for Usage */
|
||||
#define IOCTL_ERROR -2 /* Error code for ioctl failure */
|
||||
#define COMMAND_ERROR -3 /* Error code for general command failure */
|
||||
|
||||
/* integer output format */
|
||||
#define INT_FMT_DEC 0 /* signed integer */
|
||||
#define INT_FMT_UINT 1 /* unsigned integer */
|
||||
#define INT_FMT_HEX 2 /* hexdecimal */
|
||||
|
||||
/* command line argument usage */
|
||||
#define CMD_ERR -1 /* Error for command */
|
||||
#define CMD_OPT 0 /* a command line option */
|
||||
#define CMD_DHD 1 /* the start of a dhd command */
|
||||
|
||||
#endif /* _dhdu_h_ */
|
||||
37
external/cache/sources/wl/dhd/dhdu_cmd.h
vendored
Normal file
37
external/cache/sources/wl/dhd/dhdu_cmd.h
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Command structure for dhd command line utility, copied from wl utility
|
||||
*
|
||||
* $Copyright Open Broadcom Corporation$
|
||||
*
|
||||
* $Id: dhdu_cmd.h 241182 2011-02-17 21:50:03Z $
|
||||
*/
|
||||
|
||||
#ifndef _dhdu_cmd_h_
|
||||
#define _dhdu_cmd_h_
|
||||
|
||||
typedef struct cmd cmd_t;
|
||||
typedef int (cmd_func_t)(void *dhd, cmd_t *cmd, char **argv);
|
||||
|
||||
/* generic command line argument handler */
|
||||
struct cmd {
|
||||
char *name;
|
||||
cmd_func_t *func;
|
||||
int get;
|
||||
int set;
|
||||
char *help;
|
||||
};
|
||||
|
||||
/* list of command line arguments */
|
||||
extern cmd_t dhd_cmds[];
|
||||
extern cmd_t dhd_varcmd;
|
||||
|
||||
/* Special set cmds to do download via dev node interface if present */
|
||||
#define DHD_DLDN_ST 0x400
|
||||
#define DHD_DLDN_WRITE (DHD_DLDN_ST + 1)
|
||||
#define DHD_DLDN_END (DHD_DLDN_ST + 2)
|
||||
|
||||
/* per-port ioctl handlers */
|
||||
extern int dhd_get(void *dhd, int cmd, void *buf, int len);
|
||||
extern int dhd_set(void *dhd, int cmd, void *buf, int len);
|
||||
|
||||
#endif /* _dhdu_cmd_h_ */
|
||||
40
external/cache/sources/wl/dhd/dhdu_common.h
vendored
Normal file
40
external/cache/sources/wl/dhd/dhdu_common.h
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Linux port of dhd command line utility, hacked from wl utility.
|
||||
*
|
||||
* Copyright (C) 2013, Broadcom Corporation
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
|
||||
* the contents of this file may not be disclosed to third parties, copied
|
||||
* or duplicated in any form, in whole or in part, without the prior
|
||||
* written permission of Broadcom Corporation.
|
||||
*
|
||||
* $Id: dhdu_common.h 281524 2011-09-02 17:09:25Z $
|
||||
*/
|
||||
|
||||
/* Common header file for dhdu_linux.c and dhdu_ndis.c */
|
||||
|
||||
#ifndef _dhdu_common_h
|
||||
#define _dhdu_common_h
|
||||
|
||||
/* DHD utility function declarations */
|
||||
extern int dhd_check(void *dhd);
|
||||
extern int dhd_atoip(const char *a, struct ipv4_addr *n);
|
||||
extern int dhd_option(char ***pargv, char **pifname, int *phelp);
|
||||
void dhd_usage(cmd_t *port_cmds);
|
||||
|
||||
/* Remote DHD declarations */
|
||||
int remote_type = NO_REMOTE;
|
||||
extern char *g_rwl_buf_mac;
|
||||
extern char* g_rwl_device_name_serial;
|
||||
unsigned short g_rwl_servport;
|
||||
char *g_rwl_servIP = NULL;
|
||||
unsigned short defined_debug = DEBUG_ERR | DEBUG_INFO;
|
||||
|
||||
|
||||
static int process_args(struct ifreq* ifr, char **argv);
|
||||
|
||||
#define dtoh32(i) i
|
||||
#define dtoh16(i) i
|
||||
|
||||
#endif /* _dhdu_common_h_ */
|
||||
619
external/cache/sources/wl/dhd/dhdu_linux.c
vendored
Normal file
619
external/cache/sources/wl/dhd/dhdu_linux.c
vendored
Normal file
@@ -0,0 +1,619 @@
|
||||
/*
|
||||
* Linux port of dhd command line utility, hacked from wl utility.
|
||||
*
|
||||
* $Copyright Open Broadcom Corporation$
|
||||
*
|
||||
* $Id: dhdu_linux.c 281524 2011-09-02 17:09:25Z $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/socket.h>
|
||||
#include <proto/ethernet.h>
|
||||
#include <proto/bcmip.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef TARGETENV_android
|
||||
#include <error.h>
|
||||
typedef u_int64_t u64;
|
||||
typedef u_int32_t u32;
|
||||
typedef u_int16_t u16;
|
||||
typedef u_int8_t u8;
|
||||
#endif /* TARGETENV_android */
|
||||
#include <linux/sockios.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/ethtool.h>
|
||||
|
||||
#include <typedefs.h>
|
||||
#include <signal.h>
|
||||
#include <dhdioctl.h>
|
||||
#include <wlioctl.h>
|
||||
#include <bcmcdc.h>
|
||||
#include <bcmutils.h>
|
||||
#include "dhdu.h"
|
||||
#include "wlu_remote.h"
|
||||
#include "wlu_client_shared.h"
|
||||
#include "wlu_pipe.h"
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <dhdioctl.h>
|
||||
#include "dhdu_common.h"
|
||||
|
||||
char *av0;
|
||||
static int rwl_os_type = LINUX_OS;
|
||||
/* Search the dhd_cmds table for a matching command name.
|
||||
* Return the matching command or NULL if no match found.
|
||||
*/
|
||||
static cmd_t *
|
||||
dhd_find_cmd(char* name)
|
||||
{
|
||||
cmd_t *cmd = NULL;
|
||||
/* search the dhd_cmds for a matching name */
|
||||
for (cmd = dhd_cmds; cmd->name && strcmp(cmd->name, name); cmd++);
|
||||
if (cmd->name == NULL)
|
||||
cmd = NULL;
|
||||
return cmd;
|
||||
}
|
||||
|
||||
static void
|
||||
syserr(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: ", dhdu_av0);
|
||||
perror(s);
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
/* This function is called by ioctl_setinformation_fe or ioctl_queryinformation_fe
|
||||
* for executing remote commands or local commands
|
||||
*/
|
||||
static int
|
||||
dhd_ioctl(void *dhd, int cmd, void *buf, int len, bool set)
|
||||
{
|
||||
struct ifreq *ifr = (struct ifreq *)dhd;
|
||||
dhd_ioctl_t ioc;
|
||||
int ret = 0;
|
||||
int s;
|
||||
/* By default try to execute wl commands */
|
||||
int driver_magic = WLC_IOCTL_MAGIC;
|
||||
int get_magic = WLC_GET_MAGIC;
|
||||
|
||||
/* For local dhd commands execute dhd. For wifi transport we still
|
||||
* execute wl commands.
|
||||
*/
|
||||
if (remote_type == NO_REMOTE && strncmp (buf, RWL_WIFI_ACTION_CMD,
|
||||
strlen(RWL_WIFI_ACTION_CMD)) && strncmp(buf, RWL_WIFI_GET_ACTION_CMD,
|
||||
strlen(RWL_WIFI_GET_ACTION_CMD))) {
|
||||
driver_magic = DHD_IOCTL_MAGIC;
|
||||
get_magic = DHD_GET_MAGIC;
|
||||
}
|
||||
|
||||
/* open socket to kernel */
|
||||
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
|
||||
syserr("socket");
|
||||
|
||||
/* do it */
|
||||
ioc.cmd = cmd;
|
||||
ioc.buf = buf;
|
||||
ioc.len = len;
|
||||
ioc.set = set;
|
||||
ioc.driver = driver_magic;
|
||||
ifr->ifr_data = (caddr_t) &ioc;
|
||||
|
||||
if ((ret = ioctl(s, SIOCDEVPRIVATE, ifr)) < 0) {
|
||||
if (cmd != get_magic) {
|
||||
ret = IOCTL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* cleanup */
|
||||
close(s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This function is called in wlu_pipe.c remote_wifi_ser_init() to execute
|
||||
* the initial set of wl commands for wifi transport (e.g slow_timer, fast_timer etc)
|
||||
*/
|
||||
int wl_ioctl(void *wl, int cmd, void *buf, int len, bool set)
|
||||
{
|
||||
return dhd_ioctl(wl, cmd, buf, len, set); /* Call actual wl_ioctl here: Shubhro */
|
||||
}
|
||||
|
||||
/* Search if dhd adapter or wl adapter is present
|
||||
* This is called by dhd_find to check if it supports wl or dhd
|
||||
* The reason for checking wl adapter is that we can still send remote dhd commands over
|
||||
* wifi transport.
|
||||
*/
|
||||
static int
|
||||
dhd_get_dev_type(char *name, void *buf, char *type)
|
||||
{
|
||||
int s;
|
||||
int ret;
|
||||
struct ifreq ifr;
|
||||
struct ethtool_drvinfo info;
|
||||
|
||||
/* open socket to kernel */
|
||||
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
|
||||
syserr("socket");
|
||||
|
||||
/* get device type */
|
||||
memset(&info, 0, sizeof(info));
|
||||
info.cmd = ETHTOOL_GDRVINFO;
|
||||
strcpy(info.driver, "?");
|
||||
strcat(info.driver, type);
|
||||
ifr.ifr_data = (caddr_t)&info;
|
||||
strncpy(ifr.ifr_name, name, IFNAMSIZ);
|
||||
if ((ret = ioctl(s, SIOCETHTOOL, &ifr)) < 0) {
|
||||
|
||||
/* print a good diagnostic if not superuser */
|
||||
if (errno == EPERM)
|
||||
syserr("dhd_get_dev_type");
|
||||
|
||||
*(char *)buf = '\0';
|
||||
}
|
||||
else
|
||||
strcpy(buf, info.driver);
|
||||
|
||||
close(s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* dhd_get/dhd_set is called by several functions in dhdu.c. This used to call dhd_ioctl
|
||||
* directly. However now we need to execute the dhd commands remotely.
|
||||
* So we make use of wl pipes to execute this.
|
||||
* wl_get or wl_set functions also check if it is a local command hence they in turn
|
||||
* call dhd_ioctl if required. Name wl_get/wl_set is retained because these functions are
|
||||
* also called by wlu_pipe.c wlu_client_shared.c
|
||||
*/
|
||||
int
|
||||
dhd_get(void *dhd, int cmd, void *buf, int len)
|
||||
{
|
||||
return wl_get(dhd, cmd, buf, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* To use /dev/node interface:
|
||||
* 1. mknod /dev/hnd0 c 248 0
|
||||
* 2. chmod 777 /dev/hnd0
|
||||
*/
|
||||
#define NODE "/dev/hnd0"
|
||||
|
||||
int
|
||||
dhd_set(void *dhd, int cmd, void *buf, int len)
|
||||
{
|
||||
static int dnode = -1;
|
||||
|
||||
switch (cmd) {
|
||||
case DHD_DLDN_ST:
|
||||
if (dnode == -1)
|
||||
dnode = open(NODE, O_RDWR);
|
||||
else
|
||||
fprintf(stderr, "devnode already opened!\n");
|
||||
|
||||
return dnode;
|
||||
break;
|
||||
case DHD_DLDN_WRITE:
|
||||
if (dnode > 0)
|
||||
return write(dnode, buf, len);
|
||||
break;
|
||||
case DHD_DLDN_END:
|
||||
if (dnode > 0)
|
||||
return close(dnode);
|
||||
break;
|
||||
default:
|
||||
return wl_set(dhd, cmd, buf, len);
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Verify the wl adapter found.
|
||||
* This is called by dhd_find to check if it supports wl
|
||||
* The reason for checking wl adapter is that we can still send remote dhd commands over
|
||||
* wifi transport. The function is copied from wlu.c.
|
||||
*/
|
||||
int
|
||||
wl_check(void *wl)
|
||||
{
|
||||
int ret;
|
||||
int val = 0;
|
||||
|
||||
if (!dhd_check (wl))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* If dhd_check() fails then go for a regular wl driver verification
|
||||
*/
|
||||
if ((ret = wl_get(wl, WLC_GET_MAGIC, &val, sizeof(int))) < 0)
|
||||
return ret;
|
||||
if (val != WLC_IOCTL_MAGIC)
|
||||
return BCME_ERROR;
|
||||
if ((ret = wl_get(wl, WLC_GET_VERSION, &val, sizeof(int))) < 0)
|
||||
return ret;
|
||||
if (val > WLC_IOCTL_VERSION) {
|
||||
fprintf(stderr, "Version mismatch, please upgrade\n");
|
||||
return BCME_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* Search and verify the request type of adapter (wl or dhd)
|
||||
* This is called by main before executing local dhd commands
|
||||
* or sending remote dhd commands over wifi transport
|
||||
*/
|
||||
void
|
||||
dhd_find(struct ifreq *ifr, char *type)
|
||||
{
|
||||
char proc_net_dev[] = "/proc/net/dev";
|
||||
FILE *fp;
|
||||
static char buf[400];
|
||||
char *c, *name;
|
||||
char dev_type[32];
|
||||
|
||||
ifr->ifr_name[0] = '\0';
|
||||
/* eat first two lines */
|
||||
if (!(fp = fopen(proc_net_dev, "r")) ||
|
||||
!fgets(buf, sizeof(buf), fp) ||
|
||||
!fgets(buf, sizeof(buf), fp))
|
||||
return;
|
||||
|
||||
while (fgets(buf, sizeof(buf), fp)) {
|
||||
c = buf;
|
||||
while (isspace(*c))
|
||||
c++;
|
||||
if (!(name = strsep(&c, ":")))
|
||||
continue;
|
||||
strncpy(ifr->ifr_name, name, IFNAMSIZ);
|
||||
if (dhd_get_dev_type(name, dev_type, type) >= 0 &&
|
||||
!strncmp(dev_type, type, strlen(dev_type) - 1))
|
||||
{
|
||||
if (!wl_check((void*)ifr))
|
||||
break;
|
||||
}
|
||||
ifr->ifr_name[0] = '\0';
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
/* This function is called by wl_get to execute either local dhd command
|
||||
* or send a dhd command over wl transport
|
||||
*/
|
||||
static int
|
||||
ioctl_queryinformation_fe(void *wl, int cmd, void* input_buf, int *input_len)
|
||||
{
|
||||
if (remote_type == NO_REMOTE) {
|
||||
return dhd_ioctl(wl, cmd, input_buf, *input_len, FALSE);
|
||||
} else {
|
||||
return rwl_queryinformation_fe(wl, cmd, input_buf,
|
||||
(unsigned long*)input_len, 0, RDHD_GET_IOCTL);
|
||||
}
|
||||
}
|
||||
|
||||
/* This function is called by wl_set to execute either local dhd command
|
||||
* or send a dhd command over wl transport
|
||||
*/
|
||||
static int
|
||||
ioctl_setinformation_fe(void *wl, int cmd, void* buf, int *len)
|
||||
{
|
||||
if (remote_type == NO_REMOTE) {
|
||||
return dhd_ioctl(wl, cmd, buf, *len, TRUE);
|
||||
} else {
|
||||
return rwl_setinformation_fe(wl, cmd, buf, (unsigned long*)len, 0, RDHD_SET_IOCTL);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* The function is replica of wl_get in wlu_linux.c. Optimize when we have some
|
||||
* common code between wlu_linux.c and dhdu_linux.c
|
||||
*/
|
||||
int
|
||||
wl_get(void *wl, int cmd, void *buf, int len)
|
||||
{
|
||||
int error = BCME_OK;
|
||||
/* For RWL: When interfacing to a Windows client, need t add in OID_BASE */
|
||||
if ((rwl_os_type == WIN32_OS) && (remote_type != NO_REMOTE)) {
|
||||
error = (int)ioctl_queryinformation_fe(wl, WL_OID_BASE + cmd, buf, &len);
|
||||
} else {
|
||||
error = (int)ioctl_queryinformation_fe(wl, cmd, buf, &len);
|
||||
}
|
||||
if (error == SERIAL_PORT_ERR)
|
||||
return SERIAL_PORT_ERR;
|
||||
|
||||
if (error != 0)
|
||||
return IOCTL_ERROR;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/* The function is replica of wl_set in wlu_linux.c. Optimize when we have some
|
||||
* common code between wlu_linux.c and dhdu_linux.c
|
||||
*/
|
||||
int
|
||||
wl_set(void *wl, int cmd, void *buf, int len)
|
||||
{
|
||||
int error = BCME_OK;
|
||||
|
||||
/* For RWL: When interfacing to a Windows client, need t add in OID_BASE */
|
||||
if ((rwl_os_type == WIN32_OS) && (remote_type != NO_REMOTE)) {
|
||||
error = (int)ioctl_setinformation_fe(wl, WL_OID_BASE + cmd, buf, &len);
|
||||
} else {
|
||||
error = (int)ioctl_setinformation_fe(wl, cmd, buf, &len);
|
||||
}
|
||||
|
||||
if (error == SERIAL_PORT_ERR)
|
||||
return SERIAL_PORT_ERR;
|
||||
|
||||
if (error != 0) {
|
||||
return IOCTL_ERROR;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
int
|
||||
wl_validatedev(void *dev_handle)
|
||||
{
|
||||
int retval = 1;
|
||||
struct ifreq *ifr = (struct ifreq *)dev_handle;
|
||||
/* validate the interface */
|
||||
if (!ifr->ifr_name || wl_check((void *)ifr)) {
|
||||
retval = 0;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Main client function
|
||||
* The code is mostly from wlu_linux.c. This function takes care of executing remote dhd commands
|
||||
* along with the local dhd commands now.
|
||||
*/
|
||||
int
|
||||
#if defined(LIB)
|
||||
dhd_main(int argc, char **argv)
|
||||
#else
|
||||
main(int argc, char **argv)
|
||||
#endif
|
||||
{
|
||||
struct ifreq ifr;
|
||||
char *ifname = NULL;
|
||||
int err = 0;
|
||||
int help = 0;
|
||||
int status = CMD_DHD;
|
||||
void* serialHandle = NULL;
|
||||
|
||||
UNUSED_PARAMETER(argc);
|
||||
|
||||
av0 = argv[0];
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
argv++;
|
||||
|
||||
if ((status = dhd_option(&argv, &ifname, &help)) == CMD_OPT) {
|
||||
if (ifname)
|
||||
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
|
||||
}
|
||||
/* Linux client looking for a Win32 server */
|
||||
if (*argv && strncmp (*argv, "--wince", strlen(*argv)) == 0) {
|
||||
rwl_os_type = WIN32_OS;
|
||||
argv++;
|
||||
}
|
||||
|
||||
/* RWL socket transport Usage: --socket ipaddr [port num] */
|
||||
if (*argv && strncmp (*argv, "--socket", strlen(*argv)) == 0) {
|
||||
argv++;
|
||||
|
||||
remote_type = REMOTE_SOCKET;
|
||||
|
||||
if (!(*argv)) {
|
||||
rwl_usage(remote_type);
|
||||
return err;
|
||||
}
|
||||
g_rwl_servIP = *argv;
|
||||
argv++;
|
||||
|
||||
g_rwl_servport = DEFAULT_SERVER_PORT;
|
||||
if ((*argv) && isdigit(**argv)) {
|
||||
g_rwl_servport = atoi(*argv);
|
||||
argv++;
|
||||
}
|
||||
}
|
||||
|
||||
/* RWL from system serial port on client to uart dongle port on server */
|
||||
/* Usage: --dongle /dev/ttyS0 */
|
||||
if (*argv && strncmp (*argv, "--dongle", strlen(*argv)) == 0) {
|
||||
argv++;
|
||||
remote_type = REMOTE_DONGLE;
|
||||
|
||||
if (!(*argv)) {
|
||||
rwl_usage(remote_type);
|
||||
return err;
|
||||
}
|
||||
g_rwl_device_name_serial = *argv;
|
||||
argv++;
|
||||
if ((serialHandle = rwl_open_pipe(remote_type, "\0", 0, 0)) == NULL) {
|
||||
DPRINT_ERR(ERR, "serial device open error\r\n");
|
||||
return BCME_ERROR;
|
||||
}
|
||||
ifr = (*(struct ifreq *)serialHandle);
|
||||
}
|
||||
|
||||
/* RWL over wifi. Usage: --wifi mac_address */
|
||||
if (*argv && strncmp (*argv, "--wifi", strlen(*argv)) == 0) {
|
||||
argv++;
|
||||
remote_type = NO_REMOTE;
|
||||
if (!ifr.ifr_name[0])
|
||||
{
|
||||
dhd_find(&ifr, "wl");
|
||||
}
|
||||
/* validate the interface */
|
||||
if (!ifr.ifr_name[0] || wl_check((void*)&ifr)) {
|
||||
fprintf(stderr, "%s: wl driver adapter not found\n", av0);
|
||||
exit(1);
|
||||
}
|
||||
remote_type = REMOTE_WIFI;
|
||||
|
||||
if (argc < 4) {
|
||||
rwl_usage(remote_type);
|
||||
return err;
|
||||
}
|
||||
/* copy server mac address to local buffer for later use by findserver cmd */
|
||||
if (!dhd_ether_atoe(*argv, (struct ether_addr *)g_rwl_buf_mac)) {
|
||||
fprintf(stderr,
|
||||
"could not parse as an ethernet MAC address\n");
|
||||
return FAIL;
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
|
||||
/* Process for local dhd */
|
||||
if (remote_type == NO_REMOTE) {
|
||||
err = process_args(&ifr, argv);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (*argv) {
|
||||
err = process_args(&ifr, argv);
|
||||
if ((err == SERIAL_PORT_ERR) && (remote_type == REMOTE_DONGLE)) {
|
||||
DPRINT_ERR(ERR, "\n Retry again\n");
|
||||
err = process_args((struct ifreq*)&ifr, argv);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
rwl_usage(remote_type);
|
||||
|
||||
if (remote_type == REMOTE_DONGLE)
|
||||
rwl_close_pipe(remote_type, (void*)&ifr);
|
||||
|
||||
return err;
|
||||
}
|
||||
/*
|
||||
* Function called for 'local' execution and for 'remote' non-interactive session
|
||||
* (shell cmd, wl cmd) .The code is mostly from wlu_linux.c. This code can be
|
||||
* common to wlu_linux.c and dhdu_linux.c
|
||||
*/
|
||||
static int
|
||||
process_args(struct ifreq* ifr, char **argv)
|
||||
{
|
||||
char *ifname = NULL;
|
||||
int help = 0;
|
||||
int status = 0;
|
||||
int err = BCME_OK;
|
||||
cmd_t *cmd = NULL;
|
||||
while (*argv) {
|
||||
if ((strcmp (*argv, "sh") == 0) && (remote_type != NO_REMOTE)) {
|
||||
argv++; /* Get the shell command */
|
||||
if (*argv) {
|
||||
/* Register handler in case of shell command only */
|
||||
signal(SIGINT, ctrlc_handler);
|
||||
err = rwl_shell_cmd_proc((void*)ifr, argv, SHELL_CMD);
|
||||
} else {
|
||||
DPRINT_ERR(ERR,
|
||||
"Enter the shell command (e.g ls(Linux) or dir(Win CE) \n");
|
||||
err = BCME_ERROR;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((status = dhd_option(&argv, &ifname, &help)) == CMD_OPT) {
|
||||
if (help)
|
||||
break;
|
||||
if (ifname)
|
||||
strncpy(ifr->ifr_name, ifname, IFNAMSIZ);
|
||||
continue;
|
||||
}
|
||||
/* parse error */
|
||||
else if (status == CMD_ERR)
|
||||
break;
|
||||
|
||||
if (remote_type == NO_REMOTE) {
|
||||
/* use default interface */
|
||||
if (!ifr->ifr_name[0])
|
||||
dhd_find(ifr, "dhd");
|
||||
/* validate the interface */
|
||||
if (!ifr->ifr_name[0] || dhd_check((void *)ifr)) {
|
||||
if (strcmp("dldn", *argv) != 0) {
|
||||
fprintf(stderr, "%s: dhd driver adapter not found\n", av0);
|
||||
exit(BCME_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* search for command */
|
||||
cmd = dhd_find_cmd(*argv);
|
||||
/* if not found, use default set_var and get_var commands */
|
||||
if (!cmd) {
|
||||
cmd = &dhd_varcmd;
|
||||
}
|
||||
|
||||
/* do command */
|
||||
err = (*cmd->func)((void *) ifr, cmd, argv);
|
||||
break;
|
||||
} /* while loop end */
|
||||
|
||||
/* provide for help on a particular command */
|
||||
if (help && *argv) {
|
||||
cmd = dhd_find_cmd(*argv);
|
||||
if (cmd) {
|
||||
dhd_cmd_usage(cmd);
|
||||
} else {
|
||||
DPRINT_ERR(ERR, "%s: Unrecognized command \"%s\", type -h for help\n",
|
||||
av0, *argv);
|
||||
}
|
||||
} else if (!cmd)
|
||||
dhd_usage(NULL);
|
||||
else if (err == USAGE_ERROR)
|
||||
dhd_cmd_usage(cmd);
|
||||
else if (err == IOCTL_ERROR)
|
||||
dhd_printlasterror((void *) ifr);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int
|
||||
rwl_shell_createproc(void *wl)
|
||||
{
|
||||
UNUSED_PARAMETER(wl);
|
||||
return fork();
|
||||
}
|
||||
|
||||
void
|
||||
rwl_shell_killproc(int pid)
|
||||
{
|
||||
kill(pid, SIGKILL);
|
||||
}
|
||||
|
||||
#ifdef RWL_SOCKET
|
||||
/* to validate hostname/ip given by the client */
|
||||
int validate_server_address()
|
||||
{
|
||||
struct hostent *he;
|
||||
struct ipv4_addr temp;
|
||||
if (!dhd_atoip(g_rwl_servIP, &temp)) {
|
||||
/* Wrong IP address format check for hostname */
|
||||
if ((he = gethostbyname(g_rwl_servIP)) != NULL) {
|
||||
if (!dhd_atoip(*he->h_addr_list, &temp)) {
|
||||
g_rwl_servIP =
|
||||
inet_ntoa(*(struct in_addr *)*he->h_addr_list);
|
||||
if (g_rwl_servIP == NULL) {
|
||||
DPRINT_ERR(ERR, "Error at inet_ntoa \n");
|
||||
return FAIL;
|
||||
}
|
||||
} else {
|
||||
DPRINT_ERR(ERR, "Error in IP address \n");
|
||||
return FAIL;
|
||||
}
|
||||
} else {
|
||||
DPRINT_ERR(ERR, "Enter correct IP address/hostname format\n");
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
#endif /* RWL_SOCKET */
|
||||
251
external/cache/sources/wl/dhd/ucode_download.c
vendored
Normal file
251
external/cache/sources/wl/dhd/ucode_download.c
vendored
Normal file
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
* Ucode download related utility functions
|
||||
*
|
||||
* $Copyright Open Broadcom Corporation$
|
||||
*
|
||||
* $Id: ucode_download.c 297277 2011-11-18 14:10:09Z $
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <trxhdr.h>
|
||||
#include <bcmendian.h>
|
||||
#include <wlu_common.h>
|
||||
|
||||
#define DEVPRESENT_DELAY 10000 /* in microsecs */
|
||||
#define DEVPRESENT_RETRIES 100
|
||||
|
||||
extern int wl_validatedev(void *dev_handle);
|
||||
|
||||
int
|
||||
dload_generic_data(void *wl, uint16 dload_type, unsigned char *dload_buf, int len)
|
||||
{
|
||||
struct wl_dload_data *dload_ptr = (struct wl_dload_data *)dload_buf;
|
||||
int err = 0;
|
||||
int actual_data_offset;
|
||||
char *buf;
|
||||
|
||||
actual_data_offset = OFFSETOF(struct wl_dload_data, data);
|
||||
dload_ptr->flag = (DLOAD_HANDLER_VER << DLOAD_FLAG_VER_SHIFT);
|
||||
dload_ptr->flag |= DL_CRC_NOT_INUSE;
|
||||
dload_ptr->dload_type = dload_type;
|
||||
dload_ptr->len = htod32(len - actual_data_offset);
|
||||
dload_ptr->crc = 0;
|
||||
|
||||
len = len + 8 - (len%8);
|
||||
|
||||
buf = malloc(WLC_IOCTL_MEDLEN);
|
||||
if (buf) {
|
||||
bzero(buf, WLC_IOCTL_MEDLEN);
|
||||
err = wlu_iovar_setbuf(wl, "generic_dload", dload_buf, len, buf,
|
||||
WLC_IOCTL_MEDLEN);
|
||||
}
|
||||
free(buf);
|
||||
return err;
|
||||
}
|
||||
|
||||
int
|
||||
dload_ucode_part(void *wl, uint8 ucode_type, uint32 datalen, unsigned char *org_buf)
|
||||
{
|
||||
int num_chunks, chunk_len, cumulative_len = 0;
|
||||
int size2alloc, ucode_chunk_len = 0;
|
||||
unsigned char *new_buf;
|
||||
struct wl_ucode_info *ucode_ptr;
|
||||
int err = 0, ucode_offset, chunk_offset;
|
||||
|
||||
ucode_offset = OFFSETOF(wl_dload_data_t, data);
|
||||
chunk_offset = OFFSETOF(wl_ucode_info_t, data_chunk);
|
||||
|
||||
err = wlu_iovar_getint(wl, "ucdload_chunk_len",
|
||||
&ucode_chunk_len);
|
||||
if (err) {
|
||||
printf("err in getting ucode chunk len, exiting\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
num_chunks = datalen/ucode_chunk_len;
|
||||
if (datalen % ucode_chunk_len != 0)
|
||||
num_chunks++;
|
||||
size2alloc = ucode_offset + chunk_offset + ucode_chunk_len;
|
||||
|
||||
/* single chunk buffer */
|
||||
new_buf = (unsigned char *)malloc(size2alloc);
|
||||
memset(new_buf, 0, size2alloc);
|
||||
ucode_ptr = (struct wl_ucode_info *)((uint8 *)new_buf+ucode_offset);
|
||||
ucode_ptr->ucode_type = ucode_type;
|
||||
ucode_ptr->num_chunks = num_chunks;
|
||||
do {
|
||||
if (datalen >= ucode_chunk_len)
|
||||
chunk_len = ucode_chunk_len;
|
||||
else
|
||||
chunk_len = datalen;
|
||||
memset(new_buf+ucode_offset+chunk_offset, 0, size2alloc-ucode_offset-chunk_offset);
|
||||
ucode_ptr->chunk_len = htod32(chunk_len);
|
||||
ucode_ptr->chunk_num++;
|
||||
memcpy(&ucode_ptr->data_chunk[0], org_buf + cumulative_len, chunk_len);
|
||||
cumulative_len += chunk_len;
|
||||
err = dload_generic_data(wl, DL_TYPE_UCODE, new_buf, size2alloc);
|
||||
if (err) {
|
||||
printf("error while writing %s to the memory\n",
|
||||
(ucode_type == UCODE_FW)? "ucode" : "initvals");
|
||||
break;
|
||||
}
|
||||
datalen = datalen - chunk_len;
|
||||
} while (datalen > 0);
|
||||
free(new_buf);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int
|
||||
check_ucode_file(unsigned char *headers)
|
||||
{
|
||||
struct trx_header *trx;
|
||||
int actual_data_len = -1;
|
||||
|
||||
/* Extract trx header */
|
||||
trx = (struct trx_header *)headers;
|
||||
if (trx->magic != TRX_MAGIC) {
|
||||
printf("Error: trx bad hdr\n");
|
||||
goto err;
|
||||
}
|
||||
actual_data_len = ROUNDUP(trx->offsets[0], 4) + ROUNDUP(trx->offsets[1], 4);
|
||||
err:
|
||||
return actual_data_len;
|
||||
}
|
||||
|
||||
int
|
||||
proc_ucode_download(char* fw_filename, void *dev_handle)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
int ret = 0, loopcnt = 0;
|
||||
struct trx_header main_trx_hdr, *ucode_trx_hdr;
|
||||
uint32 maintrx_hdr_len, tmp_len;
|
||||
uint32 fw_size, second_offset, ucode_trx_offset;
|
||||
long ucode_pos;
|
||||
unsigned long ucode_info_len = 0, status;
|
||||
unsigned char *ucodetrx_buf, *initvals_ptr;
|
||||
int ucode_len, initvals_len;
|
||||
int ucdload_status = 0;
|
||||
int is_devpresent;
|
||||
|
||||
/* read the file and push blocks down to memory */
|
||||
if ((fp = fopen(fw_filename, "rb")) == NULL) {
|
||||
fprintf(stderr, "%s: unable to open %s: %s\n",
|
||||
__FUNCTION__, fw_filename, strerror(errno));
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
maintrx_hdr_len = sizeof(struct trx_header);
|
||||
tmp_len = fread(&main_trx_hdr, sizeof(uint8), maintrx_hdr_len, fp);
|
||||
|
||||
if (tmp_len == maintrx_hdr_len) {
|
||||
if (main_trx_hdr.magic == TRX_MAGIC) {
|
||||
fw_size = main_trx_hdr.offsets[0];
|
||||
second_offset = main_trx_hdr.offsets[2];
|
||||
|
||||
if (second_offset == maintrx_hdr_len) {
|
||||
second_offset = 0;
|
||||
}
|
||||
ucode_trx_offset = maintrx_hdr_len +
|
||||
ROUNDUP(fw_size, 4) + ROUNDUP(second_offset, 4);
|
||||
ucode_pos = fseek(fp, ucode_trx_offset, SEEK_SET);
|
||||
BCM_REFERENCE(ucode_pos);
|
||||
|
||||
if ((ucode_trx_hdr = malloc(sizeof(struct trx_header)))
|
||||
== NULL) {
|
||||
printf("Unable to allocate %d bytes!\n", maintrx_hdr_len);
|
||||
ret = -ENOMEM;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Read ONLY the firmware-file-header into the new_buffer */
|
||||
status = fread(ucode_trx_hdr, sizeof(uint8),
|
||||
maintrx_hdr_len, fp);
|
||||
if (status < sizeof(struct trx_header)) {
|
||||
printf("Short read in hdr read for %s!\n", fw_filename);
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ucode_info_len = check_ucode_file(
|
||||
(unsigned char *)ucode_trx_hdr)) <= 0) {
|
||||
printf("not a valid ucode.trx\n");
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ucodetrx_buf = (unsigned char *)malloc(ucode_info_len *
|
||||
sizeof(char));
|
||||
tmp_len = fread(ucodetrx_buf, sizeof(uint8),
|
||||
ucode_info_len, fp);
|
||||
if (ucode_info_len > 0) {
|
||||
ucode_len = ucode_trx_hdr->offsets[0];
|
||||
initvals_ptr = ucodetrx_buf +
|
||||
ROUNDUP(ucode_trx_hdr->offsets[0], 4);
|
||||
initvals_len = ucode_trx_hdr->offsets[1];
|
||||
}
|
||||
free(ucode_trx_hdr);
|
||||
|
||||
init_cmd_batchingmode();
|
||||
do {
|
||||
is_devpresent = wl_validatedev(dev_handle);
|
||||
loopcnt++;
|
||||
/* in USB after dongle fw starts running wl interface
|
||||
might not appear in the list of interfaces immediately, hence try
|
||||
after some delay of 10ms
|
||||
*/
|
||||
if (!is_devpresent)
|
||||
usleep(DEVPRESENT_DELAY);
|
||||
else {
|
||||
/* below iovar to verify if the for foundout
|
||||
interface has already ucode been downloaded
|
||||
*/
|
||||
ret = wlu_iovar_getint(dev_handle, "ucdload_status",
|
||||
&ucdload_status);
|
||||
if (ret) {
|
||||
printf("err in ucdload_status, exiting\n");
|
||||
goto exit;
|
||||
}
|
||||
if (ucdload_status) {
|
||||
/* Number of 'wl' interfaces to skip
|
||||
in the next round of going thru wl_find
|
||||
*/
|
||||
printf("ucode is already downloaded\n");
|
||||
}
|
||||
}
|
||||
/* usb seems to take some time to come up, hence the
|
||||
loop value of 100
|
||||
*/
|
||||
} while (loopcnt < DEVPRESENT_RETRIES && !is_devpresent);
|
||||
|
||||
if (loopcnt < DEVPRESENT_RETRIES) {
|
||||
/* download the ucode fw */
|
||||
ret = dload_ucode_part(dev_handle, UCODE_FW, ucode_len,
|
||||
ucodetrx_buf);
|
||||
if (ret) {
|
||||
printf("error while downloading ucode, exiting\n");
|
||||
goto exit;
|
||||
}
|
||||
/* download the initvals to the dongle */
|
||||
ret = dload_ucode_part(dev_handle, INIT_VALS,
|
||||
initvals_len, initvals_ptr);
|
||||
|
||||
if (ret) {
|
||||
printf("error while downloading initvals, exiting\n");
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("wl device is not present\n");
|
||||
}
|
||||
free(ucodetrx_buf);
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
9
external/cache/sources/wl/dhd/ucode_download.h
vendored
Normal file
9
external/cache/sources/wl/dhd/ucode_download.h
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Ucode download related utility functions
|
||||
*
|
||||
* $Copyright Open Broadcom Corporation$
|
||||
*
|
||||
* $Id: ucode_download.h 241182 2011-02-17 21:50:03Z $
|
||||
*/
|
||||
extern int
|
||||
proc_ucode_download(char* fw_filename, void *dev_handle);
|
||||
Reference in New Issue
Block a user