version_2.0

Dependents:   cc3000_ping_demo_try_2

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Revision:
45:50ab13d8f2dc
Parent:
44:960b73df5981
--- a/cc3000.h	Sun Oct 13 11:46:21 2013 +0200
+++ b/cc3000.h	Wed Nov 06 17:56:25 2013 +0100
@@ -127,6 +127,15 @@
     BOOTLOADER_PATCHES  = 2,
 };
 
+/** AP security
+ */
+enum Security {
+    NONE = 0,
+    WEP  = 1,
+    WPA  = 2,
+    WPA2 = 3
+};
+
 /** CC3000 Simple Link class which contains status of cc3000.
  */
 class cc3000_simple_link {
@@ -325,7 +334,7 @@
 class cc3000_event {
 public:
     /**
-     *  \brief
+     *  \brief Ctor
      *  \param simplelink Reference to simple link object.
      *  \param hci        Reference to hci object.
      *  \param spi        Reference to spi object.
@@ -334,7 +343,7 @@
      */
     cc3000_event(cc3000_simple_link &simplelink, cc3000_hci &hci, cc3000_spi &spi, cc3000 &cc3000);
     /**
-     *  \brief Ctor
+     *  \brief Dtor
      *  \param none
      *  \return none
      */
@@ -352,7 +361,7 @@
     *  \param  fromlen        from information length (in case of data received)
     *  \return                none
     */
-    uint8_t *hci_event_handler(void *ret_param, uint8_t *from, uint8_t *fromlen);
+    uint8_t* hci_event_handler(void *ret_param, uint8_t *from, uint8_t *fromlen);
     /**
     *  \brief  Handle unsolicited events.
     *  \param  event_hdr Event header
@@ -1072,7 +1081,7 @@
      *  \param simple_link Reference to the simple link object.
      *  \return none
      */
-     cc3000_spi(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, IRQn_Type irq_port, cc3000_event &event, cc3000_simple_link &simple_link);
+     cc3000_spi(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, cc3000_event &event, cc3000_simple_link &simple_link);
     /**
      *  \brief Dtor
      *  \param none
@@ -1166,10 +1175,9 @@
     DigitalOut          _wlan_en;
     DigitalOut          _wlan_cs;
     SPI                 _wlan_spi;
-    IRQn_Type           _irq_port;
-    pFunctionPointer_t  _function_pointer;
     cc3000_event        &_event;
     cc3000_simple_link  &_simple_link;
+    bool                _process_irq;
 };
 
 /** HCI layer
@@ -1531,9 +1539,9 @@
 public:
     /** status structure */
     typedef struct {
+        uint8_t socket;
         bool    dhcp;
         bool    connected;
-        uint8_t socket;
         bool    smart_config_complete;
         bool    stop_smart_config;
         bool    dhcp_configured;
@@ -1546,15 +1554,14 @@
      *  \param cc3000_en  Enable pin
      *  \param cc3000_cs  Chip select pin
      *  \param cc3000_spi SPI interface
-     *  \param irq_port   IRQ pin's port
      */
-    cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, IRQn_Type irq_port);
+    cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi);
     /**
      *  \brief Dtor.
      */
     ~cc3000();
     /**
-     *  \brief Initiate cc3000. It starts the wlan communication and deletes profiles.
+     *  \brief Initiate cc3000. It starts the wlan communication.
      *  \param patch Patch
      */
     void start(uint8_t patch);
@@ -1567,11 +1574,6 @@
      */
     void restart(uint8_t patch);
     /**
-     *  \brief Disconnect wlan device
-     *
-     */
-    bool disconnect(void);
-    /**
      *  \brief Callback which is called from the event class. This updates status of cc3000.
      *  \param event_type Type of the event
      *  \param data       Pointer to data
@@ -1689,18 +1691,55 @@
      *  \param none
      *  \return Pointer to cc3000 object
      */
-    static cc3000 *get_instance() {
+    static cc3000* get_instance() {
         return _inst;
     }
 #if (CC3000_ETH_COMPAT == 1)
     /**
+     *  \brief Ctor for EthernetInterface
+     *  \param cc3000_irq   IRQ pin
+     *  \param cc3000_en    Enable pin
+     *  \param cc3000_cs    Chip select pin
+     *  \param cc3000_spi   SPI interface
+     *  \param ssid         SSID
+     *  \param phrase       Password
+     *  \param sec          Security of the AP
+     *  \param smart_config Smart config selection
+     */
+    cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, const char *ssid, const char *phrase, Security sec, bool smart_config);
+    /**
+     *  \brief Disconnect wlan device.
+     *  \param none
+     *  \return 0 if successful, -1 otherwise.
+     */
+    int disconnect();
+    /**
+     *  \brief Initialize the interface with DHCP.
+     *  \param none
+     *  \return none
+     */
+    void init();
+    /**
+     *  \brief Initialize the interface with a static IP address.
+     *  \param ip      the IP address to use.
+     *  \param mask    the IP address mask
+     *  \param gateway the gateway to use
+     *  \return none
+     */
+    void init(const char *ip, const char *mask, const char *gateway);
+    /**
+     *  \brief Connect Bring the interface up.
+     *  \param timeout_ms timeout in ms
+     *  \return 0 if successful, -1 otherwise.
+     */
+    int connect(unsigned int timeout_ms = 20000);
+    /**
      *  \brief Get the MAC address of your Ethernet interface.
      *  \param none
      *  \return
      *      Pointer to a string containing the MAC address.
      */
     char* getMACAddress();
-
      /**
      *  \brief Get the IP address of your Ethernet interface.
      *  \param none
@@ -1708,7 +1747,6 @@
      *      Pointer to a string containing the IP address.
      */
     char* getIPAddress();
-
      /**
      *  \brief Get the Gateway address of your Ethernet interface
      *  \param none
@@ -1716,7 +1754,6 @@
      *      Pointer to a string containing the Gateway address
      */
     char* getGateway();
-
      /**
      *  \brief Get the Network mask of your Ethernet interface
      *  \param none
@@ -1728,21 +1765,27 @@
 public:
     cc3000_simple_link  _simple_link;
     cc3000_event        _event;
-#ifndef CC3000_UNENCRYPTED_SMART_CONFIG
-    cc3000_security     _security;
-#endif
     cc3000_socket       _socket;
     cc3000_spi          _spi;
     cc3000_hci          _hci;
     cc3000_nvmem        _nvmem;
     cc3000_netapp       _netapp;
     cc3000_wlan         _wlan;
+#ifndef CC3000_UNENCRYPTED_SMART_CONFIG
+    cc3000_security     _security;
+#endif
 protected:
     static cc3000       *_inst;
 private:
     tStatus                  _status;
     netapp_pingreport_args_t _ping_report;
     bool                     _closed_sockets[MAX_SOCKETS];
+#if (CC3000_ETH_COMPAT == 1)
+    uint8_t                  _phrase[30];
+    uint8_t                  _ssid[30];
+    Security                 _sec;
+    bool                     _smart_config;
+#endif
 };
 
 /**