Shop OBEX P1 Docs P2 Docs Learn Events
TI's CC3000 WIFI driver (2015 update) — Parallax Forums

TI's CC3000 WIFI driver (2015 update)

Finally got around implementing all the functions CC3000 can do.
It was a pain as it uses HCI type structure where bytes,words & long are mixed on odd boundary.

By default it uses the pins on the breakout board I sold for the Propeller Quickstart board a year back, but any cc3000 breakout board should work.

4 sockets at the same time.
Rolling buffers, you parse data at your leisure as SPI driver handles IRQ in the background.
Parse what you looking for (or to end of Rxbuffer) if parser find something else during it will fill in that data too.

Recommend you do the store-SSID-profile inside cc3000 so it will auto-connect to it when you power it up.
http://processors.wiki.ti.com/index.php/CC3000_Protocol
code snippet:
{{

PUB wlan_connect(wlan_security, bssid, ssid, passphrase)
    hci_len := 0
    hci_long(28)                                        'not documented yet
    hci_long(strsize(ssid))
    hci_long(wlan_security)
    hci_long(strsize(ssid)+16)
    hci_long(strsize(passphrase))
    hci_word(0)                                         'probably upper filler word for bssid     
    if bssid == 0
      hci_word(0)
      hci_long(0)
    else
      hci_byte(delimiter(bssid,0,":"))                  'bbsid (Big-endian)
      hci_byte(delimiter(bssid,1,":"))                  'a router macid filtering
      hci_byte(delimiter(bssid,2,":"))                  'use dec, not hex values
      hci_byte(delimiter(bssid,3,":"))
      hci_byte(delimiter(bssid,4,":"))
      hci_byte(delimiter(bssid,5,":"))
    hci_copy(strsize(ssid),ssid)                        'fill in ascii ssid name
    case wlan_security                                  'if wep, wpa & wpa2 
      1..3 : hci_copy(strsize(passphrase),passphrase)   'key index 1 (wep 5 ascii chars = 40bit key)    
    hci_cmnd($0001)                                     'HCI_TYPE_CMND
    
PUB add_profile(wlan_security, bssid, priority, ssid, passphrase)
    hci_len := 0
    hci_long(wlan_security)                             '0=open, 1=wep, 2=wpa, 3=wpa2
    case wlan_security 
      0   : hci_long(20)                                'not documented yet
      1   : hci_long(32)                                'hci lenght probably
      2,3 : hci_long(40)   
    hci_long(strsize(ssid))
    hci_word (0)                                        'probably upper filler word for bssid
    if bssid == 0
      hci_word(0)
      hci_long(0)
    else
      hci_byte(delimiter(bssid,0,":"))                  'bbsid (Big-endian)
      hci_byte(delimiter(bssid,1,":"))                  'a router macid filtering
      hci_byte(delimiter(bssid,2,":"))                  'use dec, not hex values
      hci_byte(delimiter(bssid,3,":"))
      hci_byte(delimiter(bssid,4,":"))
      hci_byte(delimiter(bssid,5,":"))
    hci_long(priority)                                  '0=low to 7=highest priority
    if wlan_security == 0                               'open
      hci_copy(strsize(ssid),ssid)                      'for open, just fill in ascii ssid name
    if wlan_security == 1                               'wep
      hci_long(strsize(ssid)+12)
      hci_long(32)                                      'Key length 
      hci_long(0)                                       'Key index
      hci_copy(strsize(ssid),ssid)                      'fill in ascii ssid name   
      hci_copy(strsize(passphrase),passphrase)          'key index 1 (5 ascii chars = 40bit key)
      hci_copy(strsize(passphrase),passphrase)          'key index 2 (same key repeated 4 times)       
      hci_copy(strsize(passphrase),passphrase)          'key index 3 
      hci_copy(strsize(passphrase),passphrase)          'key index 4
    if wlan_security == 2 or  wlan_security == 3        'wpa and wpa2
      hci_long(24)                                      'PairwiseCipher
      hci_long(30)                                      'GroupCipher
      hci_long(2)                                       'Key management
      hci_long(strsize(ssid)+8)
      hci_long(strsize(passphrase))
      hci_copy(strsize(ssid),ssid)                      'fill in ascii ssid name
      hci_copy(strsize(passphrase),passphrase)          'fill in ascii password                                                                     
    hci_cmnd($0005)                                     'HCI_TYPE_CMND

PUB set_scanparam(interval)
    hci_len := 0                                        'all parameters, except the interval[ms] are saved into the CC3000 NVMEM/EEPROM
    hci_long(36)                                        'not documented
    hci_long(interval)                                  'minumum 1000[ms], 0=disable scan
    hci_long(20)                                        'MinDwellTime [ms]
    hci_long(100)                                       'MaxDwellTime [ms]
    hci_long(2)                                         'NumOfProbeRequests
    hci_long($7FF)                                      'ChannelMask $7FF= 1..11 NorthAmerica  ($1FFF= 1..13 worldwide) 
    hci_long(-120)                                      'RSSIThreshold
    hci_long(0)                                         'SNRThreshold
    hci_long(205)                                       'TXpower (not evaluated by CC3000 as off Service Pack 1.12)
    repeat 16
      hci_long(2000)                                    'Channel 1..16 Scan Timeout[ms] each channel gets own timeout  
    hci_cmnd($0003)
                                 
PUB get_scan_results(ScanTimeout)
    hci_len := 0                                        'each entry needs to be read out separately   
    hci_long(ScanTimeout)                               'NOT supported as of CC3000 service pack 1.12/firmware 1.26 
    hci_cmnd($0007)                                     'the event_reply includes a parameter w/ remaining count of unread SSID's

PUB smart_config_prefix(character)
    hci_len := 0
    hci_byte(character)                                 'should always be 3 ASCII characters, set to T T T
    hci_byte(character)
    hci_byte(character) 
    hci_cmnd($000C)
 
PUB smart_config_start(EncryptedFlag)
    hci_len := 0
    hci_long(EncryptedFlag)                             '0=No encryption  1=AES-128    
    hci_cmnd($000A)

PUB smart_config_stop
    hci_len := 0
    hci_cmnd($000B)
      
PUB wlan_statusget
    hci_len := 0                                        '4 possible status in event: Disconnected, Scanning, Connecting, Connected  
    hci_cmnd($0009)                                   
         
PUB wlan_set_event_mask(event_mask)
    hci_len := 0
    hci_long(event_mask)
    hci_cmnd($0008)                                    'HCI_TYPE_CMND  

PUB connection_policy(open_ap, fast_connect, auto_start)
    hci_len := 0
    hci_long(open_ap)
    hci_long(fast_connect)
    hci_long(auto_start)
    hci_cmnd($0004)                                    'HCI_TYPE_CMND 

PUB del_profile(index)          
    hci_len := 0
    hci_long(index)                                    '0-6 or 255 for delete all
    hci_cmnd($0006)                                    'HCI_TYPE_CMND
     
PUB connect(sockethandle,port,IPv4)
    hci_len := 0
    hci_long(sockethandle)
    hci_long(8)                                        'not documented yet
    hci_long(8)                                        'Address length
    hci_word(2)                                        'AF_INET
    hci_byte(port>>8)                                  'Destination Port (Big-endian)
    hci_byte(port)                                     'Destination Port   
    hci_byte(delimiter(IPv4,0,"."))                    'Destination IPv4 (Big-endian)
    hci_byte(delimiter(IPv4,1,"."))
    hci_byte(delimiter(IPv4,2,"."))
    hci_byte(delimiter(IPv4,3,"."))
    hci_cmnd($1007)                                    'HCI_TYPE_CMND                           

PUB nvmem_read(FileID, len, offset)
    hci_len := 0                                       'reply is hci_event 0x0201 
    hci_long(FileID)                                   'evet followed by HCI_DATA_NVMEM_READ (0x91) 
    hci_long(len)
    hci_long(offset)                                   'macid is 6,6,0
    hci_cmnd($0201)                                    'HCI_TYPE_CMND

PUB nvmem_create_entry(FileID, lenght)
    hci_len := 0 
    hci_long(FileID)                                   '12-15, mostly used to store AES-128 encryption key in file ID 12 
    hci_long(lenght)                                   'DATA_NVMEM_WRITE (0x90) to acctually write the data 
    hci_cmnd($0203)                                    'HCI_TYPE_CMND

PUB read_sp_version
    hci_len := 0                                       'get CC3000 service pack version (firmware version)
    hci_cmnd($0207)                                    'HCI_TYPE_CMND

PUB socket(Family,Type,Protocol)
    hci_len := 0  
    hci_long (Family)                                    'Protocol Family: AF_INET
    hci_long (Type)                                      'Socket Type: SOCK_STREAM 
    hci_long (Protocol)                                  'Protocol Type: TCP/IP
    hci_cmnd ($1001)   
  
PUB close_socket(sockhdl)
    hci_len := 0  
    hci_long (sockhdl)                                   'socket 0-3
    hci_cmnd ($100B)
    
PUB bind(sockhdl, port, IPv4)
    hci_len := 0  
    hci_long (sockhdl)                                  'socket 0-3
    hci_long (8)                                        'not documented
    hci_long (8)                                        'Address length
    hci_word (2)                                        'Protocol Family AF_INET
    hci_byte (port>>8)                                  '16bit big endian
    hci_byte (port)
    if IPv4 == 0
      hci_long(0)                                       '0 = ANY
    else
      hci_byte(delimiter(IPv4,0,"."))                   'IPv4(Big-endian)
      hci_byte(delimiter(IPv4,1,"."))                   'use dec, not hex values   
      hci_byte(delimiter(IPv4,2,"."))                 
      hci_byte(delimiter(IPv4,3,"."))     
    hci_cmnd ($1002)

PUB accept(sockhdl)
    hci_len := 0                                        'only required for serving SOCK_STREAM type 
    hci_long (sockhdl)                                  'socket 0-3
    hci_cmnd ($1005)
    
PUB listen(sockhdl,queue_depth)
    hci_len := 0 
    hci_long (sockhdl)                                  'socket 0-3
    hci_long (queue_depth)                              'not evaluated by CC3000 as of FW1.26, SP1.12
    hci_cmnd ($1006)
    
PUB setsockopt(sockhdl, optname, optval)
    hci_len := 0
    hci_long(sockhdl)
    hci_long($ffff)                                     'SOL_SOCKET=0xffff     
    hci_long(optname)                                   '1: SOCKOPT_RECV_TIMEOUT 2: SOCKOPT_NONBLOCK
    hci_long(8)                                         'optlen is 8                                         
    hci_long(optval)                                    'if TIMEOUT=millisec, if NONBLOCK:0=non-blocking enabled 1= blocking
    hci_cmnd ($1009)
    
PUB select(highest_socket, block, uSec, read_mask, write_mask, error_mask)   'quering the status or waiting state
    hci_len := 0                                        'there a three socket conditions 
    hci_long(highest_socket+1)                          'Ready-to-read, Ready-to-write, Error
    hci_long(20)                                        'Constant a
    hci_long(20)                                        'Constant b 
    hci_long(20)                                        'Constant c  
    hci_long(20)                                        'Constant d
    hci_long(block)                                     '0= No, don't block
    hci_long(read_mask)
    hci_long(write_mask)
    hci_long(error_mask)
    hci_long(0)                                         'timeout: seconds use 0
    hci_long(uSec)                                      'timeout: uS, minumum 5000 microseconds
    hci_cmnd ($1008) 

}}

Sign In or Register to comment.