spi_wifi_rw009.h 6.8 KB
Newer Older
wuyangyong's avatar
wuyangyong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * File      : spi_wifi_rw009.h
 * This file is part of RT-Thread RTOS
 * Copyright by Shanghai Real-Thread Electronic Technology Co.,Ltd
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Change Logs:
 * Date           Author       Notes
 * 2014-07-31     aozima       the first version
wuyangyong's avatar
wuyangyong 已提交
23
 * 2014-09-18     aozima       update command & response.
wuyangyong's avatar
wuyangyong 已提交
24 25 26 27 28 29 30 31
 */

#ifndef SPI_WIFI_H_INCLUDED
#define SPI_WIFI_H_INCLUDED

#include <stdint.h>

// little-endian
wuyangyong's avatar
wuyangyong 已提交
32
struct spi_cmd_request
wuyangyong's avatar
wuyangyong 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45
{
    uint32_t flag;
    uint32_t M2S_len; // master to slave data len.
    uint32_t magic1;
    uint32_t magic2;
};

#define CMD_MAGIC1          (0x67452301)
#define CMD_MAGIC2          (0xEFCDAB89)

#define CMD_FLAG_MRDY       (0x01)

// little-endian
wuyangyong's avatar
wuyangyong 已提交
46
struct spi_response
wuyangyong's avatar
wuyangyong 已提交
47 48 49 50 51 52 53 54 55 56 57 58
{
    uint32_t flag;
    uint32_t S2M_len; // slave to master data len.
    uint32_t magic1;
    uint32_t magic2;
};

#define RESP_FLAG_SRDY      (0x01)
#define RESP_MAGIC1         (0x98BADCFE)
#define RESP_MAGIC2         (0x10325476)

/* spi slave configure. */
wuyangyong's avatar
wuyangyong 已提交
59
#define SPI_MAX_DATA_LEN    1520
wuyangyong's avatar
wuyangyong 已提交
60
#define SPI_TX_POOL_SIZE    2
wuyangyong's avatar
wuyangyong 已提交
61
#define SPI_RX_POOL_SIZE    2
wuyangyong's avatar
wuyangyong 已提交
62 63 64 65 66 67

typedef enum
{
    data_type_eth_data = 0,
    data_type_cmd,
    data_type_resp,
wuyangyong's avatar
wuyangyong 已提交
68
    data_type_status,
wuyangyong's avatar
wuyangyong 已提交
69 70 71 72 73 74 75
}
app_data_type_typedef;

struct spi_data_packet
{
    uint32_t data_len;
    uint32_t data_type;
wuyangyong's avatar
wuyangyong 已提交
76
    char buffer[SPI_MAX_DATA_LEN];
wuyangyong's avatar
wuyangyong 已提交
77 78
};

wuyangyong's avatar
wuyangyong 已提交
79
/********************************* RW009 **************************************/
wuyangyong's avatar
wuyangyong 已提交
80

wuyangyong's avatar
wuyangyong 已提交
81 82 83 84
/* option */
#define RW009_CMD_TIMEOUT           (RT_TICK_PER_SECOND*3)
#define SSID_NAME_LENGTH_MAX        (32)
#define PASSWORD_LENGTH_MAX         (64)
wuyangyong's avatar
wuyangyong 已提交
85

86 87 88 89 90 91
typedef enum
{
    MODE_STATION=0,
    MODE_SOFTAP=1,
} wifi_mode_t;

wuyangyong's avatar
wuyangyong 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
typedef struct _rw009_ap_info
{
    char        ssid[SSID_NAME_LENGTH_MAX];
    uint8_t     bssid[8]; // 6byte + 2byte PAD.
    int         rssi;               /* Receive Signal Strength Indication in dBm. */
    uint32_t    max_data_rate;      /* Maximum data rate in kilobits/s */
    uint32_t    security;           /* Security type  */
    uint32_t    channel;            /* Radio channel that the AP beacon was received on   */
} rw009_ap_info;

typedef struct _rw009_cmd_init
{
    uint32_t mode;
} rw009_cmd_init;

typedef struct _rw009_resp_init
{
    uint8_t mac[8];     // 6byte + 2byte PAD.
    uint8_t sn[24];     // serial.
    char version[16];   // firmware version.
} rw009_resp_init;

typedef struct _rw009_cmd_easy_join
{
    char ssid[SSID_NAME_LENGTH_MAX];
    char passwd[PASSWORD_LENGTH_MAX];
} rw009_cmd_easy_join;

typedef struct _rw009_cmd_join
{
    uint8_t bssid[8]; // 6byte + 2byte PAD.
    char passwd[PASSWORD_LENGTH_MAX];
} rw009_cmd_join;
wuyangyong's avatar
wuyangyong 已提交
125

wuyangyong's avatar
wuyangyong 已提交
126 127 128 129 130
typedef struct _rw009_cmd_rssi
{
    uint8_t bssid[8]; // 6byte + 2byte PAD.
} rw009_cmd_rssi;

131 132 133 134 135 136 137 138 139
typedef struct _rw009_cmd_softap
{
    char ssid[SSID_NAME_LENGTH_MAX];
    char passwd[PASSWORD_LENGTH_MAX];

    uint32_t    security;           /* Security type. */
    uint32_t    channel;            /* Radio channel that the AP beacon was received on   */
} rw009_cmd_softap;

wuyangyong's avatar
wuyangyong 已提交
140 141 142 143 144 145
typedef struct _rw009_resp_join
{
    rw009_ap_info ap_info;
} rw009_resp_join;

struct rw009_cmd
wuyangyong's avatar
wuyangyong 已提交
146 147
{
    uint32_t cmd;
wuyangyong's avatar
wuyangyong 已提交
148 149 150 151 152 153 154 155 156
    uint32_t len;

    /** command body */
    union
    {
        rw009_cmd_init init;
        rw009_cmd_easy_join easy_join;
        rw009_cmd_join join;
        rw009_cmd_rssi rssi;
157
        rw009_cmd_softap softap;
wuyangyong's avatar
wuyangyong 已提交
158
    } params;
wuyangyong's avatar
wuyangyong 已提交
159 160
};

wuyangyong's avatar
wuyangyong 已提交
161
struct rw009_resp
wuyangyong's avatar
wuyangyong 已提交
162 163
{
    uint32_t cmd;
wuyangyong's avatar
wuyangyong 已提交
164 165 166 167 168 169 170 171 172 173
    uint32_t len;

    int32_t result; // result for CMD.

    /** resp Body */
    union
    {
        rw009_resp_init init;
        rw009_ap_info ap_info;
    } resp;
wuyangyong's avatar
wuyangyong 已提交
174 175
};

wuyangyong's avatar
wuyangyong 已提交
176 177 178 179 180
#define RW009_CMD_INIT              128
#define RW009_CMD_SCAN              129
#define RW009_CMD_JOIN              130
#define RW009_CMD_EASY_JOIN         131
#define RW009_CMD_RSSI              132
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
#define RW009_CMD_SOFTAP            133

/** cond !ADDTHIS*/
#define SHARED_ENABLED  0x00008000
#define WPA_SECURITY    0x00200000
#define WPA2_SECURITY   0x00400000
#define WPS_ENABLED     0x10000000
#define WEP_ENABLED        0x0001
#define TKIP_ENABLED        0x0002
#define AES_ENABLED        0x0004
#define WSEC_SWFLAG        0x0008
/** endcond */
/**
 * Enumeration of Wi-Fi security modes
 */
typedef enum
{
    SECURITY_OPEN           = 0,                                                /**< Open security                           */
    SECURITY_WEP_PSK        = WEP_ENABLED,                                      /**< WEP Security with open authentication   */
    SECURITY_WEP_SHARED     = ( WEP_ENABLED | SHARED_ENABLED ),                 /**< WEP Security with shared authentication */
    SECURITY_WPA_TKIP_PSK   = ( WPA_SECURITY  | TKIP_ENABLED ),                 /**< WPA Security with TKIP                  */
    SECURITY_WPA_AES_PSK    = ( WPA_SECURITY  | AES_ENABLED ),                  /**< WPA Security with AES                   */
    SECURITY_WPA2_AES_PSK   = ( WPA2_SECURITY | AES_ENABLED ),                  /**< WPA2 Security with AES                  */
    SECURITY_WPA2_TKIP_PSK  = ( WPA2_SECURITY | TKIP_ENABLED ),                 /**< WPA2 Security with TKIP                 */
    SECURITY_WPA2_MIXED_PSK = ( WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED ),   /**< WPA2 Security with AES & TKIP           */

    SECURITY_WPS_OPEN       = WPS_ENABLED,                                      /**< WPS with open security                  */
    SECURITY_WPS_SECURE     = (WPS_ENABLED | AES_ENABLED),                      /**< WPS with AES security                   */

    SECURITY_UNKNOWN        = -1,                                               /**< May be returned by scan function if security is unknown. Do not pass this to the join function! */

    SECURITY_FORCE_32_BIT   = 0x7fffffff                                        /**< Exists only to force wiced_security_t type to 32 bits */
} security_t;
wuyangyong's avatar
wuyangyong 已提交
214 215 216 217 218 219

/* porting */
extern void spi_wifi_hw_init(void);
extern void spi_wifi_int_cmd(rt_bool_t cmd);
extern rt_bool_t spi_wifi_is_busy(void);

wuyangyong's avatar
wuyangyong 已提交
220
/* export API. */
221
extern rt_err_t rt_hw_wifi_init(const char *spi_device_name,wifi_mode_t mode);
wuyangyong's avatar
wuyangyong 已提交
222 223
extern int32_t rw009_rssi(void);
extern rt_err_t rw009_join(const char * SSID, const char * passwd);
224
extern rt_err_t rw009_softap(const char * SSID, const char * passwd,uint32_t security,uint32_t channel);
wuyangyong's avatar
wuyangyong 已提交
225 226

#endif // SPI_WIFI_H_INCLUDED