SWRU455M February   2017  – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF

 

  1. Overview
    1. 1.1 Trademarks
  2. Introduction
    1. 1.1 Features
    2. 1.2 Key Features
    3. 1.3 Block Diagram
    4. 1.4 Host Driver Overview
      1. 1.4.1 Host Interface
      2. 1.4.2 OS versus Non-OS
      3. 1.4.3 Quick Reference
      4. 1.4.4 Porting to Different Platforms
    5. 1.5 Acronyms and Terminologies
  3. Networking Application
    1. 2.1 Introduction
      1. 2.1.1 Wi-Fi Connectivity
      2. 2.1.2 Traffic Types
      3. 2.1.3 Security
      4. 2.1.4 User Experience
      5. 2.1.5 Power Consumption
      6. 2.1.6 Provisioning
    2. 2.2 Basic Examples
      1. 2.2.1 Wi-Fi Doorbell
        1. 2.2.1.1 Description
        2. 2.2.1.2 Design Considerations
      2. 2.2.2 Power Socket
        1. 2.2.2.1 Description
        2. 2.2.2.2 Design Constraints
      3. 2.2.3 Wi-Fi Tag
        1. 2.2.3.1 Description
        2. 2.2.3.2 Design Consideration
  4. Device
    1. 3.1  Introduction
    2. 3.2  Key Features
    3. 3.3  Start and Stop
      1. 3.3.1 Start
      2. 3.3.2 Stop
      3. 3.3.3 Hibernate and Shutdown
      4. 3.3.4 Lock State
      5. 3.3.5 Initialization Sequence
    4. 3.4  Host Interface
      1. 3.4.1 SPI Interface
      2. 3.4.2 UART Interface
        1. 3.4.2.1 Change UART Baud Rate
    5. 3.5  Version
    6. 3.6  Event Mask
    7. 3.7  Time and Date
    8. 3.8  MAC Address
    9. 3.9  Device Name
    10. 3.10 Domain Name
    11. 3.11 Device Status
    12. 3.12 Persistent Configuration
    13. 3.13 Device Statistics
    14. 3.14 Errors
  5. WLAN
    1. 4.1  Introduction
    2. 4.2  Key Features
    3. 4.3  Station (STA)
      1. 4.3.1 General Description
      2. 4.3.2 Configurations and Settings
        1. 4.3.2.1 Set Mode
        2. 4.3.2.2 Set General STA Parameters
      3. 4.3.3 Connection
        1. 4.3.3.1 Connection Policies
        2. 4.3.3.2 Preferred Networks (Profiles)
        3. 4.3.3.3 Manual Connection
      4. 4.3.4 Events and Errors
      5. 4.3.5 RSSI Trigger
      6. 4.3.6 Soft-Roaming
      7. 4.3.7 Beacon Interval and DTIM Period
      8. 4.3.8 Agile Multiband
      9. 4.3.9 Triggered Roaming
    4. 4.4  Access Point
      1. 4.4.1 General Description
      2. 4.4.2 Configurations and Settings
        1. 4.4.2.1 Set Mode
        2. 4.4.2.2 Set General AP Parameters
        3. 4.4.2.3 Get General AP Parameters
        4. 4.4.2.4 Black List
      3. 4.4.3 Set Network Configuration
        1. 4.4.3.1 Set AP IP Parameters
      4. 4.4.4 Station Management
        1. 4.4.4.1 Get Connected Stations
        2. 4.4.4.2 Disconnect a Station
      5. 4.4.5 Events and Errors
      6. 4.4.6 Limitations
    5. 4.5  Wi-Fi Direct
      1. 4.5.1 General Description
      2. 4.5.2 Supported Features
      3. 4.5.3 Configurations and Settings
        1. 4.5.3.1 Configuring Wi-Fi Direct General Parameters
        2. 4.5.3.2 Set Wi-Fi Direct Policy
        3. 4.5.3.3 Configure Connection Policy
      4. 4.5.4 Connection
      5. 4.5.5 Events and Errors
      6. 4.5.6 Limitations
    6. 4.6  WLAN Security
      1. 4.6.1 Personal Security
      2. 4.6.2 Enterprise Security
      3. 4.6.3 WPS
    7. 4.7  Scan
      1. 4.7.1 General Description
      2. 4.7.2 Connection Scan
      3. 4.7.3 Configuration (AP/STA)
      4. 4.7.4 Usage
      5. 4.7.5 Miscellaneous
    8. 4.8  Antenna Diversity
      1. 4.8.1 Overview
      2. 4.8.2 Configuration
      3. 4.8.3 Pad Selection
    9. 4.9  Calibrations
      1. 4.9.1 2.4-GHz Wi-Fi Calibration Modes
      2. 4.9.2 5-GHz Wi-Fi Calibration Modes
        1. 4.9.2.1 Serving Channel Calibrations
        2. 4.9.2.2 Non-Serving Channel Calibrations
        3. 4.9.2.3 Storing Calibration Data
        4. 4.9.2.4 Transceiver Socket
    10. 4.10 BLE / 2.4-GHz Radio Coexistence
      1. 4.10.1 Key Features
      2. 4.10.2 Configuration and Settings
      3. 4.10.3 Operation
        1. 4.10.3.1 Calibration
  6. Network Addresses
    1. 5.1 Introduction
    2. 5.2 Key Features
    3. 5.3 Addressing
      1. 5.3.1 IPv4 Addresses
      2. 5.3.2 IPv6 Addresses
        1. 5.3.2.1 Local Link
        2. 5.3.2.2 Link-Global
      3. 5.3.3 DNS Addresses
    4. 5.4 DHCPv4 Client
      1. 5.4.1 Modes
      2. 5.4.2 Address Release
    5. 5.5 DHCPv4 Server
      1. 5.5.1 Enable and Disable the DHCP Server
      2. 5.5.2 Set DHCP Server Parameters
    6. 5.6 DNS Server
    7. 5.7 Errors and Asynchronous Events
  7. Socket
    1. 6.1 Introduction
    2. 6.2 Key Features
    3. 6.3 Socket Types
    4. 6.4 BSD API
    5. 6.5 Socket Working Flow
      1. 6.5.1 TCP
        1. 6.5.1.1 Client Side
        2. 6.5.1.2 Server Side
        3. 6.5.1.3 TCP Keep Alive
      2. 6.5.2 UDP
        1. 6.5.2.1 Multicast
        2. 6.5.2.2 Packet Boundary
      3. 6.5.3 RAW
        1. 6.5.3.1 Layer 4: Transport
        2. 6.5.3.2 Layer 3: Network
        3. 6.5.3.3 Layer 2: Data Link (Transceiver Mode, Not Connected)
      4. 6.5.4 Network Bypass Mode
    6. 6.6 DNS
    7. 6.7 Operation Modes
      1. 6.7.1 Nonblocking Mode
      2. 6.7.2 Trigger Mode
        1. 6.7.2.1 Trigger Mode for Accept
        2. 6.7.2.2 Trigger Mode for Data Reception
      3. 6.7.3 Multiple Select
    8. 6.8 IP Fragmentation
    9. 6.9 Errors
  8. Secure Socket
    1. 7.1 Introduction
    2. 7.2 Key Features
    3. 7.3 Opening a Secure Socket
    4. 7.4 Trusted Root-Certificate Catalog
    5. 7.5 Options and Features Use
      1. 7.5.1 Set TLS Version
      2. 7.5.2 Set Cipher Suites
      3. 7.5.3 Set Certificates, Root CA, Private Key, and DH Files
      4. 7.5.4 Disable the Use of the Trusted Root-Certificate Catalog
      5. 7.5.5 Set ALPN List
        1. 7.5.5.1 ALPN Fixed List
        2. 7.5.5.2 ALPN Generic
      6. 7.5.6 Set Domain Name for Verification and SNI
      7. 7.5.7 Enable OCSP Check
      8. 7.5.8 Upgrade Nonsecured Socket to Secured
      9. 7.5.9 Get Connection Parameters
    6. 7.6 Supported Cryptographic Algorithms
    7. 7.7 Common Errors and Asynchronous Events
      1. 7.7.1 Using Socket Asynchronous Events in TLS
      2. 7.7.2 Common Errors
  9. File System
    1. 8.1  Introduction
    2. 8.2  Key Features
    3. 8.3  File System Characteristics
    4. 8.4  Write a File
      1. 8.4.1 Introduction
      2. 8.4.2 Create a File versus Open for Write
      3. 8.4.3 Create a File
        1. 8.4.3.1 Secure File Creation Notes
        2. 8.4.3.2 Forced Creation Flags
      4. 8.4.4 Open a File for Write
      5. 8.4.5 Write an Opened File
      6. 8.4.6 Close an Opened File (for Write)
      7. 8.4.7 Close an Opened Secure-Signed File (for Write)
    5. 8.5  Read a File
      1. 8.5.1 Open a File for Read
      2. 8.5.2 Read an Opened File
      3. 8.5.3 Close an Opened File (for Read)
    6. 8.6  Delete a File
    7. 8.7  Rename a File
    8. 8.8  File System Helper Functions
      1. 8.8.1 Get File Information
      2. 8.8.2 Get Storage Information
      3. 8.8.3 Get List of Files
    9. 8.9  Bundle Protection
      1. 8.9.1 Bundle File States
      2. 8.9.2 Bundle States
        1. 8.9.2.1 STOPPED
        2. 8.9.2.2 STARTED
        3. 8.9.2.3 PENDING_COMMIT
      3. 8.9.3 Commit a Bundle
      4. 8.9.4 Rollback a Bundle
      5. 8.9.5 Retrieve the Bundle and Files State
      6. 8.9.6 M4 Host Application Bundle Aspects
    10. 8.10 File Commit Feature
      1. 8.10.1 File Commit Process
    11. 8.11 File Rollback Process
    12. 8.12 Programming
      1. 8.12.1 Creation of the Programming Image
        1. 8.12.1.1 Programming Image Types
        2. 8.12.1.2 Program the Device
          1. 8.12.1.2.1 Image Creator Tool (UART) Programming
          2. 8.12.1.2.2 Host Programming
          3. 8.12.1.2.3 External Tool Programming
    13. 8.13 Restore to Factory
      1. 8.13.1 Restore to Factory by the Host
      2. 8.13.2 Restore to Factory by Using the SOP
        1. 8.13.2.1 CC31xx
        2. 8.13.2.2 CC32xx
    14. 8.14 Security Alerts
    15. 8.15 Design Consideration
      1. 8.15.1 Choosing SFLASH Type
      2. 8.15.2 Software Design Consideration
      3. 8.15.3 Retrieving Info Regarding SFLASH Usage
      4. 8.15.4 SFLASH Size
        1. 8.15.4.1 Restore to Factory is Disabled
        2. 8.15.4.2 Restore to Factory is Enabled
      5. 8.15.5 Storage Usage Information
  10. HTTP Server
    1. 9.1 Introduction
      1. 9.1.1 Built-in Configuration Pages
      2. 9.1.2 RESTful APIs
        1. 9.1.2.1 Changing Configuration
        2. 9.1.2.2 Reading Configuration
      3. 9.1.3 Custom Static Pages
        1. 9.1.3.1 Custom Pages With Device Tokens
        2. 9.1.3.2 Static Pages With Host Tokens
      4. 9.1.4 Host Application Interface
    2. 9.2 Key Features
    3. 9.3 Configurations and Settings
    4. 9.4 RESTful API Processing
      1. 9.4.1  Ping
      2. 9.4.2  IP Configuration
      3. 9.4.3  URN Configuration
      4. 9.4.4  WLAN Profiles
      5. 9.4.5  WLAN Scan
      6. 9.4.6  Provisioning Confirmation
      7. 9.4.7  Connection Policy
      8. 9.4.8  Station Action
      9. 9.4.9  AP Black List
      10. 9.4.10 Date and Time
    5. 9.5 Device Parameter Querying Through HTTP (Device Tokens)
      1. 9.5.1  Retrieving Tokens Through GET Request
      2. 9.5.2  Embedded Tokens
      3. 9.5.3  System Information
      4. 9.5.4  Version Information
      5. 9.5.5  Network Information
      6. 9.5.6  Ping Results
      7. 9.5.7  Connection Policy Status
      8. 9.5.8  Provisioning
      9. 9.5.9  Display Profile Information
      10. 9.5.10 P2P Information
      11. 9.5.11 Host Tokens
    6. 9.6 Resource Search Order
      1. 9.6.1 GET Request Search Order
      2. 9.6.2 POST Request Search Order
      3. 9.6.3 PUT and DELETE Request Search Order
    7. 9.7 Host HTTP Requests Processing
      1. 9.7.1 Metadata (TLVs) Description
      2. 9.7.2 GET Processing
        1. 9.7.2.1 Fragmentation
      3. 9.7.3 POST Processing
        1. 9.7.3.1 Long Requests and Delayed Responses
      4. 9.7.4 PUT Processing
      5. 9.7.5 DELETE Processing
    8. 9.8 Security
      1. 9.8.1 Authentication
        1. 9.8.1.1 HTTP Realm
      2. 9.8.2 Secure Connection
    9. 9.9 Processing of Parallel Requests
  11. 10mDNS
    1. 10.1 Introduction
    2. 10.2 Key Features
    3. 10.3 Configurations and Settings
    4. 10.4 Query
      1. 10.4.1 One Shot Query
      2. 10.4.2 Continuous Query
      3. 10.4.3 Mask Services
    5. 10.5 Get Service List
    6. 10.6 Advertisement
      1. 10.6.1 Registering mDNS Services
      2. 10.6.2 Unregistering mDNS Services
      3. 10.6.3 Advertisement Settings
        1. 10.6.3.1 Timing
        2. 10.6.3.2 Update Text
    7. 10.7 Limitations
  12. 11Rx Filters
    1. 11.1 Introduction
    2. 11.2 Matching Process
      1. 11.2.1 Filter Matching
      2. 11.2.2 Tree Traversal
    3. 11.3 Examples of Filter Use
      1. 11.3.1 Example 1
      2. 11.3.2 Example 2
    4. 11.4 Filter Creation
      1. 11.4.1 Filter Type
      2. 11.4.2 Filter Flags
      3. 11.4.3 Rule Structure for Header Filters
        1. 11.4.3.1 Field
        2. 11.4.3.2 Compare Functions
        3. 11.4.3.3 Rule Fields
        4. 11.4.3.4 Pattern-Matching Rule Fields
      4. 11.4.4 Rule Structure for Combined Filters
      5. 11.4.5 Filter Trigger
        1. 11.4.5.1 Parent Filter ID
        2. 11.4.5.2 Connection State and Role
        3. 11.4.5.3 Filter During Transceiver Mode
      6. 11.4.6 Rx Filter Action
        1. 11.4.6.1 Send Events Action
        2. 11.4.6.2 Multiple Bits Set on the Same Event
        3. 11.4.6.3 Multiple Events From the Same Rx Frame
        4. 11.4.6.4 Code Example
        5. 11.4.6.5 Counter Action
    5. 11.5 Managing Filters
      1. 11.5.1 Enable and Disable Filters
      2. 11.5.2 Get Filter Status
      3. 11.5.3 Removing a Filter
      4. 11.5.4 Storing Filters into the SFLASH
      5. 11.5.5 Update Filter Arguments
  13. 12Ping
    1. 12.1 General Description
    2. 12.2 Start and Stop Ping
    3. 12.3 Limitations
  14. 13Transceiver
    1. 13.1 Introduction
    2. 13.2 Key Features
    3. 13.3 Configurations and Setting
      1. 13.3.1 Open Transceiver Socket
      2. 13.3.2 Close Transceiver Socket
      3. 13.3.3 Send Data
      4. 13.3.4 Receive Data
    4. 13.4 Internal Packet Generator
    5. 13.5 CW
    6. 13.6 Changing Socket Properties
      1. 13.6.1 Change Operating Channel
      2. 13.6.2 Change Default PHY Data Rate
      3. 13.6.3 Change Tx Power
      4. 13.6.4 Change Number of Frames to Transmit (Internal Packet Generator)
      5. 13.6.5 Change 802.11b Preamble
      6. 13.6.6 Set CCA Threshold
      7. 13.6.7 Set Tx Frames Time-out
      8. 13.6.8 Enable or Disable Sending ACKs
    7. 13.7 Limitations
  15. 14Real-Time RSSI
    1. 14.1 Introduction
    2. 14.2 Data Structure
    3. 14.3 Configurations and Settings
      1. 14.3.1 Connect to an AP
      2. 14.3.2 Opening Real-Time RSSI Socket
      3. 14.3.3 Example Code
    4. 14.4 Constraints
  16. 15Power Management
    1. 15.1 Introduction
      1. 15.1.1 Key Features
      2. 15.1.2 LPDS
      3. 15.1.3 802.11 Power Save
        1. 15.1.3.1 LSI (Long Sleep Interval)
      4. 15.1.4 WFA IoT Low Power
      5. 15.1.5 Low Power versus Latency
      6. 15.1.6 Power Modes versus Device Modes
    2. 15.2 Configurations and Settings
      1. 15.2.1 Changing Power Policy
      2. 15.2.2 Enabling Fast Connect
    3. 15.3 Network Applications and Power Consumption
      1. 15.3.1 mDNS
      2. 15.3.2 HTTP Server
    4. 15.4 Design Guidelines
      1. 15.4.1 LSI and Packet Loss
      2. 15.4.2 PHY Calibration Mode
  17. 16Provisioning
    1. 16.1  Introduction
    2. 16.2  Key Features
    3. 16.3  Provisioning Process Overview
      1. 16.3.1 Configuring a Profile
      2. 16.3.2 Confirming a Profile
    4. 16.4  Host Provisioning Application Flow
    5. 16.5  Configuration Modes
      1. 16.5.1 AP Provisioning
      2. 16.5.2 SC Provisioning
      3. 16.5.3 AP and SC Provisioning
      4. 16.5.4 AP and SC and External Configuration Provisioning
    6. 16.6  Starting and Stopping the Provisioning Process
    7. 16.7  Auto-Provisioning
    8. 16.8  Delivering Feedback to the User
      1. 16.8.1 External Confirmation
    9. 16.9  External Configuration
    10. 16.10 Common Events and Errors
      1. 16.10.1 Provisioning Status Event
      2. 16.10.2 Provisioning Profile-Added Event
      3. 16.10.3 Reset Request Event
      4. 16.10.4 Errors
      5. 16.10.5 Host Commands During Provisioning
    11. 16.11 Usage Examples
      1. 16.11.1 Successful SmartConfig Provisioning
      2. 16.11.2 Unsuccessful SmartConfig Provisioning
      3. 16.11.3 Successful SmartConfig Provisioning With AP Fallback
      4. 16.11.4 Successful AP Provisioning
      5. 16.11.5 Successful AP Provisioning With Cloud Confirmation
      6. 16.11.6 Using External Configuration Method: WAC
      7. 16.11.7 Successful SmartConfig Provisioning While External Configuration Enabled
  18. 17Crypto Utilities
    1. 17.1 Introduction
      1. 17.1.1 API and Usage
        1. 17.1.1.1 Install and Uninstall Key-Pairs and Certificates
        2. 17.1.1.2 Create or Remove Temporary Key
        3. 17.1.1.3 Get Public Key
        4. 17.1.1.4 Certificate Creation
        5. 17.1.1.5 Sign Buffer
        6. 17.1.1.6 Verify Buffer
        7. 17.1.1.7 True Random Number
      2. 17.1.2 Limitations and Constraints
      3. 17.1.3 Errors
    2. 17.2 Secured Content Delivery
      1. 17.2.1 SimpleLink Wi-Fi Side Process Flow
      2. 17.2.2 Encrypted File Format
  19. 18Hostless Mode
    1. 18.1 Introduction
    2. 18.2 Script Overview
    3. 18.3 Conditions
      1. 18.3.1 Pre-Initialization
      2. 18.3.2 System Event
      3. 18.3.3 Timer Expiration
      4. 18.3.4 Counter Threshold
      5. 18.3.5 Internal Errors
    4. 18.4 Sub-Conditions
    5. 18.5 Actions
      1. 18.5.1 Pre-Initialization Actions
        1. 18.5.1.1 Set Role
        2. 18.5.1.2 Delete All Profiles
        3. 18.5.1.3 Hardware GPIO
      2. 18.5.2 Run-Time Actions
        1. 18.5.2.1 Send Transceiver Packet
        2. 18.5.2.2 Send UDP Packet
        3. 18.5.2.3 Send TCP Packet
        4. 18.5.2.4 Set/Increment Counter
        5. 18.5.2.5 Timer Control
        6. 18.5.2.6 Set GPIO
        7. 18.5.2.7 Enter Hibernate
  20. 19Porting the Host Driver
    1. 19.1 Introduction
    2. 19.2 Create Platform Porting File
    3. 19.3 Select Capabilities Set
    4. 19.4 Bind the Device Enable/Disable Line
    5. 19.5 Implement the Interface Communication Abstract Layer
    6. 19.6 Choose Memory-Management Model
    7. 19.7 Implement OS Adaptation Layer
      1. 19.7.1 Sync Objects
      2. 19.7.2 Locking Objects
    8. 19.8 Implement Timestamp Services
    9. 19.9 Set Asynchronous Event Handler Routines
  21. 20Debug
    1. 20.1 Capture NWP Logs
      1. 20.1.1 Overview
      2. 20.1.2 Instructions
        1. 20.1.2.1 Configuring Pin Mux for CC32xx
        2. 20.1.2.2 Terminal Settings
        3. 20.1.2.3 Run Your Program
        4. 20.1.2.4 Send to TI Engineer
          1.        A Host APIs
            1.         A.1 Host APIs
              1.          B Persistency
                1.           B.1 Persistency
                  1.            C Regulatory Domain
                    1.             C.1 Regulatory Domain
                      1.              D Supported Host Interfaces
                        1.               D.1 SPI Host Interface
                          1.                D.1.1 Introduction
                          2.                D.1.2 Abbreviations
                          3.                D.1.3 SPI Modes
                          4.                D.1.4 SPI Configurations (Shared SPI)
                          5.                D.1.5 SPI Initialization
                          6.                D.1.6 Host Interface Protocol - SPI Perspective
                        2.               D.2 UART Host Interface
                          1.                D.2.1 Introduction
                          2.                D.2.2 Host Low Power Modes
                          3.                D.2.3 UART Host Topologies
                            1.                 D.2.3.1 5-Wire UART Topology
                            2.                 D.2.3.2 4-Wire UART Topology
                            3.                 D.2.3.3 3-Wire UART Topology
                          4.                D.2.4 UART Configuration
                          5.                D.2.5 UART Initialization
                            1.                 D.2.5.1 Changing the UART Baud Rate
                          6.                D.2.6 Implementing the UART Driver - Concept and Terminology
                            1.                 D.2.6.1 UART Read API Implementation
                            2.                 D.2.6.2 UART Write API Implementation
                          7.                D.2.7 Register/Unregister Interrupt Handler API Implementation
                          8.                D.2.8 Host Interface Protocol – UART Perspective
                            1.                 D.2.8.1 UART Host Command Flow
                            2.                 D.2.8.2 Synchronization Words
                              1.                  Revision History

Fragmentation

The host may choose to send the resource as a single chunk as part of the response from the handler (the payload fields in the ResponseData structure), or split it across multiple fragments. Fragmentation must be used to transfer resources larger than 1500 bytes (this is also the maximal size of a single fragment). Without fragmentation, the entire resource data is sent as part of the response from the handler. With fragmentation, the handler does not return anything but the pending status, while the fragments of the response are sent using the sl_NetAppSend API. Each fragment may be a different size (but smaller than 1500 bytes). While there are more fragments to send, the SL_NETAPP_REQUEST_RESPONSE_FLAGS_CONTINUATION bit must be set in the flags parameter of the API. On the last fragment, this bit must be zero. The first call to sl_NetAppSend API must carry the metadata (HTTP headers) of the response. For that, the SL_NETAPP_REQUEST_RESPONSE_FLAGS_METADATA bit must be set in the flags parameter of the API. Figure 10-11 demonstrates the handling of a GET request without (1) and with (2) fragmentation.

GUID-DAED74BB-DE61-414C-A28C-8CAF4A6AD4C7-low.pngFigure 9-11 GET Request With and Without Fragmentation

The following code demonstrates how to implement an HTTP GET handler that sends a response (a short text string) immediately. The code assumes that the macro slcb_NetAppRequestHdlr is mapped to NetAppRequestHandler in file user.h.

#define RESPONSE_TEXT "Example text to be displayed in browser"
void NetAppRequestHandler(  SlNetAppRequest_t *pNetAppRequest, 
                            SlNetAppResponse_t *pNetAppResponse)
{
    char *contentType = "text/html";
    unsigned char *pMetadata;
    unsigned char *pResponseText;
    
    pMetadata = (unsigned char*)malloc(128);
    pResponseText = (unsigned char*)malloc(sizeof(RESPONSE_TEXT));
    if ((NULL == pMetadata) || (NULL == pResponseText))
    {
        /* Allocation error */
    }
    memcpy(pResponseText, RESPONSE_TEXT, sizeof(RESPONSE_TEXT));
    switch(pNetAppRequest->Type)
    {
        case SL_NETAPP_REQUEST_HTTP_GET:
        {
            pNetAppResponse->Status = SL_NETAPP_HTTP_RESPONSE_200_OK;
            /* Write the content type TLV to buffer */
            pNetAppResponse->ResponseData.pMetadata = pMetadata;
            *pMetadata = 
                (_u8) SL_NETAPP_REQUEST_METADATA_TYPE_HTTP_CONTENT_TYPE;
            pMetadata++;
            *(_u16 *)pMetadata = (_u16) strlen (contentType);
            pMetadata+=2;
            memcpy (pMetadata, contentType, strlen(contentType));
            pMetadata+=strlen(contentType);
            /* Write the content length TLV to buffer */
            *pMetadata = SL_NETAPP_REQUEST_METADATA_TYPE_HTTP_CONTENT_LEN;
            pMetadata++;
            *(_u16 *)pMetadata = 2;
            pMetadata+=2;
            *(_u16 *) pMetadata = (_u16) sizeof(RESPONSE_TEXT);
            pMetadata+=2;
            /* Calculate and write the total length of meta data */
            pNetAppResponse->ResponseData.MetadataLen = 
                pMetadata - pNetAppResponse->ResponseData.pMetadata;
            /* Write the text of the response */
            pNetAppResponse->ResponseData.PayloadLen = sizeof(RESPONSE_TEXT);
            pNetAppResponse->ResponseData.pPayload = pResponseText;
            pNetAppResponse->ResponseData.Flags = 0;
        }
        break;
        default:
            /* POST/PUT/DELETE requests will reach here. */break;
    }
}

 

The following code demonstrates how to implement HTTP GET handler that delegates the request to some other application. The user must extract any relevant information from the request and save it as the data buffers are freed when the handler returns.

void NetAppRequestHandler(  SlNetAppRequest_t *pNetAppRequest, 
                            SlNetAppResponse_t *pNetAppResponse)
{
    switch(pNetAppRequest->Type)
    {
        case SL_NETAPP_REQUEST_HTTP_GET:
        {
            /* Prepare pending response */
            pNetAppResponse->Status = SL_NETAPP_RESPONSE_PENDING;
            pNetAppResponse->ResponseData.pMetadata = NULL;
            pNetAppResponse->ResponseData.MetadataLen = 0;
            pNetAppResponse->ResponseData.pPayload = NULL;
            pNetAppResponse->ResponseData.PayloadLen = 0;
            pNetAppResponse->ResponseData.Flags = 0;
            /* Copy to some global buffer any relevant info from  pNetAppRequest (the handle 
            In particular) and signal the user application that a new HTTP request has arrived. */
        }
        break;
        default:
            /* POST/PUT/DELETE requests will reach here. */break;
    }   
}

When signaled, the user application can then send this suggested response:

#define RESPONSE_TEXT "Example text part 1 --- "
#define RESPONSE_TEXT2 "Example text part 2"
_u8 *metadataBuff;
_u8 *pResponseText;
_u8 *pMetadata;
_u16 MetadataLen = 0;
const _u8 *contentType =  "text/html"; 
_u8 Flags = 0;          
_u16 TextLength;
metadataBuff = (_u8 *) malloc (128);
pMetadata = metadataBuff;
/* HTTP status is sent as part of the meta-data*/
*pMetadata = (_u8) SL_NETAPP_REQUEST_METADATA_TYPE_STATUS;
pMetadata++;
*(_u16 *)pMetadata = (_u16) 2;
pMetadata+=2;
*(_u16 *)pMetadata = (_u16) SL_NETAPP_HTTP_RESPONSE_200_OK;
pMetadata+=2;
/* Write the content type TLV to buffer */
*pMetadata = (_u8) SL_NETAPP_REQUEST_METADATA_TYPE_HTTP_CONTENT_TYPE;
pMetadata++;
*(_u16 *)pMetadata = (_u16) strlen((char*)contentType);
pMetadata+=2;
memcpy (pMetadata, contentType, strlen((char*)contentType));
pMetadata+=strlen((char*)contentType);
/* Write the content length TLV to buffer */
*pMetadata = SL_NETAPP_REQUEST_METADATA_TYPE_HTTP_CONTENT_LEN;
pMetadata++;
*(_u16 *)pMetadata = 2;
pMetadata+=2;
TextLength = sizeof(RESPONSE_TEXT) + sizeof(RESPONSE_TEXT2);
*(_u16 *) pMetadata = TextLength;
pMetadata+=2;
MetadataLen = pMetadata - metadataBuff;
/* First send the meta-data (note the METADATA flag).
Continuation flag indicates there are more fragments to follow.
gHandle is assumed to be populated by the handler.  */
Flags |= SL_NETAPP_REQUEST_RESPONSE_FLAGS_CONTINUATION;
Flags |= SL_NETAPP_REQUEST_RESPONSE_FLAGS_METADATA;
sl_NetAppSend (gHandle, MetadataLen, metadataBuff, Flags);
/* Send first data fragment. Continuation flag still 
indicates there are more fragments to follow, */
Flags = SL_NETAPP_REQUEST_RESPONSE_FLAGS_CONTINUATION;
pResponseText = (_u8 *) malloc (sizeof(RESPONSE_TEXT));
memcpy(pResponseText, RESPONSE_TEXT, sizeof(RESPONSE_TEXT));
sl_NetAppSend (gHandle, sizeof(RESPONSE_TEXT), pResponseText, Flags);
/* Last data fragment - continuation flag is cleared. */
Flags = 0;
pResponseText = (_u8 *) malloc (sizeof(RESPONSE_TEXT2));
memcpy(pResponseText, RESPONSE_TEXT2, sizeof(RESPONSE_TEXT2));
sl_NetAppSend (gHandle, sizeof(RESPONSE_TEXT2), pResponseText, Flags);