<commit_before>/* WiFiInterface
 * Copyright (c) 2015 - 2016 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef WIFI_INTERFACE_H
#define WIFI_INTERFACE_H

#include <string.h>
#include "network-socket/NetworkInterface.h"

typedef struct wifi_ap {
    char ssid[33]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */
    uint8_t bssid[6];
    nsapi_security_t security;
    int8_t rssi;
    uint8_t channel;
} wifi_ap_t;

typedef void (*wifi_ap_scan_cb_t)(wifi_ap_t *ap, void *data);
typedef void (*wifi_connect_cb_t)(nsapi_error_t res, void *data);

/** WiFiInterface class
 *
 *  Common interface that is shared between WiFi devices
 */
class WiFiInterface: public NetworkInterface
{
public:
    /** Start the interface
     *
     *  Attempts to connect to a WiFi network.
     *
     *  @param ssid      Name of the network to connect to
     *  @param pass      Security passphrase to connect to the network
     *  @param security  Type of encryption for connection
     *  @param timeout   Timeout in milliseconds; 0 for no timeout
     *  @return          0 on success, or error code on failure
     */
    virtual nsapi_error_t connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE,
                                  unsigned timeout = 0) = 0;

    /** Start the interface
     *
     *  Attempts to connect to a WiFi network asynchronously, the call will return straight away. If the @a cb was NULL
     *  you'll need to query @a get_state until it's in NSAPI_IF_STATE_CONNECTED state, otherwise the @a cb will be
     *  called with connection results.
     *
     *  Note: @a ssid and @a pass must be kept until the connection is made, that is the callback has been called or the
     *        state changed to @a NSAPI_IF_STATE_CONNECTED as they are passed by value.
     *
     *  @param ssid      Name of the network to connect to
     *  @param pass      Security passphrase to connect to the network
     *  @param security  Type of encryption for connection
     *  @param cb        Function to be called when the connect finishes
     *  @param data      Arbitrary user data to pass to @a cb function
     */
    virtual void connect_async(const char *ssid, const char *pass,nsapi_security_t security = NSAPI_SECURITY_NONE,
                               wifi_connect_cb_t cb = NULL, void *data = NULL) = 0;

    /** Stop the interface
     *
     *  @return          0 on success, or error code on failure
     */
    virtual nsapi_error_t disconnect() = 0;

    /** Get the local MAC address
     *
     *  @return         Null-terminated representation of the local MAC address
     */
    virtual const char *get_mac_address() = 0;

    /** Get the current WiFi interface state
     *
     * @returns         Interface state enum
     */
    virtual nsapi_if_state_t get_state() = 0;

    /** Gets the current radio signal strength for active connection
     *
     * @return Connection strength in dBm (negative value), or 0 if measurement impossible
     */
    virtual int8_t get_rssi() = 0;

    /** Scan for available networks
     *
     * This function will block.
     *
     * @param  ap       Pointer to allocated array to store discovered AP
     * @param  count    Size of allocated @a res array, or 0 to only count available AP
     * @param  timeout  Timeout in milliseconds; 0 for no timeout
     * @return          Number of entries in @a, or if @a count was 0 number of available networks, negative on error
     *                  see @a nsapi_error
     */
    virtual int scan(wifi_ap_t *res, unsigned count, unsigned timeout = 0) = 0;

    /** Scan for available networks
     *
     * This function won't block, it'll return immediately and call provided callback for each discovered network with
     * AP data and user @a data. After the last discovered network @a cb will be called with NULL as @a ap, so it
     * will be always called at least once.
     *
     * @param  cb    Function to be called for every discovered network
     * @param  data  A user handle that will be passed to @a cb along with the AP data
     */
    virtual void scan_async(wifi_ap_scan_cb_t cb, void *data = NULL) = 0;
};

#endif
<commit_msg>WiFi: Extend WiFiInterface API and documentation<commit_after>/* WiFiInterface
 * Copyright (c) 2015 - 2016 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef WIFI_INTERFACE_H
#define WIFI_INTERFACE_H

#include <string.h>
#include "network-socket/NetworkInterface.h"

typedef struct wifi_ap {
    char ssid[33]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */
    uint8_t bssid[6];
    nsapi_security_t security;
    int8_t rssi;
    uint8_t channel;
} wifi_ap_t;

typedef void (*wifi_ap_scan_cb_t)(wifi_ap_t *ap, void *data);
typedef void (*wifi_connect_cb_t)(nsapi_error_t res, wifi_ap_t *ap, void *data);

/** WiFiInterface class
 *
 *  Common interface that is shared between WiFi devices
 */
class WiFiInterface: public NetworkInterface
{
public:
    /** Start the interface
     *
     *  Attempts to connect to a WiFi network.
     *
     *  @param ssid      Name of the network to connect to
     *  @param pass      Security passphrase to connect to the network
     *  @param security  Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
     *  @param channel   Channel on which the connection is to be made, or 0 for any (Default: 0)
     *  @param timeout   Timeout in milliseconds; 0 for no timeout (Default: 0)
     *  @return          0 on success, or error code on failure
     */
    virtual nsapi_error_t connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE,
                                  uint8_t channel = 0, unsigned timeout = 0) = 0;

    /** Start the interface
     *
     *  Attempts to connect to a WiFi network asynchronously, the call will return straight away. If the @a cb was NULL
     *  you'll need to query @a get_state until it's in NSAPI_IF_STATE_CONNECTED state, otherwise the @a cb will be
     *  called with connection results, connected AP details and user data.
     *
     *  Note: @a ssid and @a pass must be kept until the connection is made, that is the callback has been called or the
     *        state changed to @a NSAPI_IF_STATE_CONNECTED as they are passed by value.
     *
     *  @param ssid      Name of the network to connect to
     *  @param pass      Security passphrase to connect to the network
     *  @param channel   Channel on which the connection is to be made, or 0 for any (Default: 0)
     *  @param security  Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
     *  @param cb        Function to be called when the connect finishes (Default: NULL)
     *  @param data      Arbitrary user data to pass to @a cb function (Default: NULL)
     *  @param timeout   Timeout in milliseconds; 0 for no timeout (Default: 0)
     */
    virtual void connect_async(const char *ssid, const char *pass,nsapi_security_t security = NSAPI_SECURITY_NONE,
                               uint8_t channel = 0, wifi_connect_cb_t cb = NULL, void *data = NULL,
                               unsigned timeout = 0) = 0;

    /** Stop the interface
     *
     *  @return          0 on success, or error code on failure
     */
    virtual nsapi_error_t disconnect() = 0;

    /** Get the local MAC address
     *
     *  @return         Null-terminated representation of the local MAC address in "00:11:22:33:44:55" form
     */
    virtual const char *get_mac_address() = 0;

    /** Get the current WiFi interface state
     *
     * @returns         Interface state enum
     */
    virtual nsapi_if_state_t get_state() = 0;

    /** Gets the current radio signal strength for active connection
     *
     * @return Connection strength in dBm (negative value), or 0 if measurement impossible
     */
    virtual int8_t get_rssi() = 0;

    /** Scan for available networks
     *
     * This function will block.
     *
     * @param  ap       Pointer to allocated array to store discovered AP
     * @param  count    Size of allocated @a res array, or 0 to only count available AP
     * @param  timeout  Timeout in milliseconds; 0 for no timeout (Default: 0)
     * @return          Number of entries in @a, or if @a count was 0 number of available networks, negative on error
     *                  see @a nsapi_error
     */
    virtual int scan(wifi_ap_t *res, unsigned count, unsigned timeout = 0) = 0;

    /** Scan for available networks
     *
     * This function won't block, it'll return immediately and call provided callback for each discovered network with
     * AP data and user @a data. After the last discovered network @a cb will be called with NULL as @a ap, so it
     * will be always called at least once.
     *
     * @param  cb    Function to be called for every discovered network
     * @param  data  User handle that will be passed to @a cb along with the AP data (Default: NULL)
     * @param  timeout  Timeout in milliseconds; 0 for no timeout (Default: 0)
     */
    virtual void scan_async(wifi_ap_scan_cb_t cb, void *data = NULL, unsigned timeout = 0) = 0;
};

#endif

{'fraction_non_alphanumeric': 0.06735650136665365, 'fraction_numerical': 0.011518937914877, 'mean_word_length': 2.6433143669985775, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2129234', 'n_tokens_mistral': 2978, 'n_tokens_neox': 2814, 'n_words': 1277}