テスト用

Fork of nRF51822 by Nordic Semiconductor

Revision:
65:98215c4f3a25
Parent:
0:eff01767de02
--- a/nordic/ble/ble_advdata.cpp	Mon Sep 08 15:45:22 2014 +0000
+++ b/nordic/ble/ble_advdata.cpp	Mon Sep 08 17:21:46 2014 +0100
@@ -19,33 +19,33 @@
 
 
 // Offset from where advertisement data other than flags information can start.
-#define ADV_FLAG_OFFSET    2
+#define ADV_FLAG_OFFSET 2
 
 // Offset for Advertising Data.
 // Offset is 2 as each Advertising Data contain 1 octet of Adveritising Data Type and
 // one octet Advertising Data Length.
-#define ADV_DATA_OFFSET    2
+#define ADV_DATA_OFFSET 2
 
 // NOTE: For now, Security Manager TK Value and Security Manager Out of Band Flags (OOB) are omitted
 //       from the advertising data.
 
 
 static uint32_t name_encode(const ble_advdata_t * p_advdata,
-                            uint8_t *             p_encoded_data,
-                            uint8_t *             p_len)
+                            uint8_t             * p_encoded_data,
+                            uint8_t             * p_len)
 {
     uint32_t err_code;
     uint16_t rem_adv_data_len;
     uint16_t actual_length;
     uint8_t  adv_data_format;
     uint8_t  adv_offset;
-    
+
     adv_offset = *p_len;
-    
-    
+
+
     // Check for buffer overflow.
     if ((adv_offset + ADV_DATA_OFFSET > BLE_GAP_ADV_MAX_SIZE) ||
-       ((p_advdata->short_name_len + ADV_DATA_OFFSET) > BLE_GAP_ADV_MAX_SIZE))
+        ((p_advdata->short_name_len + ADV_DATA_OFFSET) > BLE_GAP_ADV_MAX_SIZE))
     {
         return NRF_ERROR_DATA_SIZE;
     }
@@ -63,14 +63,14 @@
     if ((p_advdata->name_type == BLE_ADVDATA_FULL_NAME) && (actual_length <= rem_adv_data_len))
     {
         // Complete device name can fit, setting Complete Name in Adv Data.
-        adv_data_format = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME;
+        adv_data_format  = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME;
         rem_adv_data_len = actual_length;
     }
     else
     {
         // Else short name needs to be used. Or application has requested use of short name.
         adv_data_format = BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME;
-        
+
         // If application has set a preference on the short name size, it needs to be considered,
         // else fit what can be fit.
         if ((p_advdata->short_name_len != 0) && (p_advdata->short_name_len <= rem_adv_data_len))
@@ -84,12 +84,12 @@
             rem_adv_data_len = actual_length;
         }
     }
-    
+
     // Complete name field in encoded data.
     p_encoded_data[adv_offset++] = rem_adv_data_len + 1;
     p_encoded_data[adv_offset++] = adv_data_format;
-    (*p_len) += (rem_adv_data_len + ADV_DATA_OFFSET);
-    
+    (*p_len)                    += (rem_adv_data_len + ADV_DATA_OFFSET);
+
     return NRF_SUCCESS;
 }
 
@@ -111,21 +111,21 @@
     {
         return err_code;
     }
-    
+
     // Encode Length, AD Type and Appearance.
     p_encoded_data[(*p_len)++] = 3;
     p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_APPEARANCE;
 
     (*p_len) += uint16_encode(appearance, &p_encoded_data[*p_len]);
-    
+
     return NRF_SUCCESS;
 }
 
 
 static uint32_t uint8_array_encode(const uint8_array_t * p_uint8_array,
                                    uint8_t               adv_type,
-                                   uint8_t *             p_encoded_data,
-                                   uint8_t *             p_len)
+                                   uint8_t             * p_encoded_data,
+                                   uint8_t             * p_len)
 {
     // Check parameter consistency.
     if (p_uint8_array->p_data == NULL)
@@ -142,11 +142,11 @@
     // Encode Length and AD Type.
     p_encoded_data[(*p_len)++] = 1 + p_uint8_array->size;
     p_encoded_data[(*p_len)++] = adv_type;
-    
+
     // Encode array.
     memcpy(&p_encoded_data[*p_len], p_uint8_array->p_data, p_uint8_array->size);
     (*p_len) += p_uint8_array->size;
-    
+
     return NRF_SUCCESS;
 }
 
@@ -165,7 +165,7 @@
     p_encoded_data[(*p_len)++] = 2;
     p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_TX_POWER_LEVEL;
     p_encoded_data[(*p_len)++] = (uint8_t)tx_power_level;
-    
+
     return NRF_SUCCESS;
 }
 
@@ -173,13 +173,13 @@
 static uint32_t uuid_list_sized_encode(const ble_advdata_uuid_list_t * p_uuid_list,
                                        uint8_t                         adv_type,
                                        uint8_t                         uuid_size,
-                                       uint8_t *                       p_encoded_data,
-                                       uint8_t *                       p_len)
+                                       uint8_t                       * p_encoded_data,
+                                       uint8_t                       * p_len)
 {
     int     i;
     bool    is_heading_written = false;
-    uint8_t start_pos = *p_len;
-    
+    uint8_t start_pos          = *p_len;
+
     for (i = 0; i < p_uuid_list->uuid_cnt; i++)
     {
         uint32_t   err_code;
@@ -192,7 +192,7 @@
         {
             return err_code;
         }
-        
+
         // Check size.
         if (encoded_size == uuid_size)
         {
@@ -203,15 +203,15 @@
             {
                 return NRF_ERROR_DATA_SIZE;
             }
-            
+
             if (!is_heading_written)
             {
                 // Write AD structure heading.
                 (*p_len)++;
                 p_encoded_data[(*p_len)++] = adv_type;
-                is_heading_written = true;
+                is_heading_written         = true;
             }
-            
+
             // Write UUID.
             err_code = sd_ble_uuid_encode(&uuid, &encoded_size, &p_encoded_data[*p_len]);
             if (err_code != NRF_SUCCESS)
@@ -221,13 +221,13 @@
             (*p_len) += encoded_size;
         }
     }
-    
+
     if (is_heading_written)
     {
         // Write length.
         p_encoded_data[start_pos] = (*p_len) - (start_pos + 1);
     }
-    
+
     return NRF_SUCCESS;
 }
 
@@ -235,11 +235,11 @@
 static uint32_t uuid_list_encode(const ble_advdata_uuid_list_t * p_uuid_list,
                                  uint8_t                         adv_type_16,
                                  uint8_t                         adv_type_128,
-                                 uint8_t *                       p_encoded_data,
-                                 uint8_t *                       p_len)
+                                 uint8_t                       * p_encoded_data,
+                                 uint8_t                       * p_len)
 {
     uint32_t err_code;
-    
+
     // Encode 16 bit UUIDs.
     err_code = uuid_list_sized_encode(p_uuid_list,
                                       adv_type_16,
@@ -250,7 +250,7 @@
     {
         return err_code;
     }
-    
+
     // Encode 128 bit UUIDs.
     err_code = uuid_list_sized_encode(p_uuid_list,
                                       adv_type_128,
@@ -261,7 +261,7 @@
     {
         return err_code;
     }
-    
+
     return NRF_SUCCESS;
 }
 
@@ -269,12 +269,12 @@
 static uint32_t conn_int_check(const ble_advdata_conn_int_t *p_conn_int)
 {
     // Check Minimum Connection Interval.
-    if ((p_conn_int->min_conn_interval < 0x0006) || 
+    if ((p_conn_int->min_conn_interval < 0x0006) ||
         (
-            (p_conn_int->min_conn_interval > 0x0c80) && 
+            (p_conn_int->min_conn_interval > 0x0c80) &&
             (p_conn_int->min_conn_interval != 0xffff)
         )
-    )
+       )
     {
         return NRF_ERROR_INVALID_PARAM;
     }
@@ -285,7 +285,7 @@
             (p_conn_int->max_conn_interval > 0x0c80) && 
             (p_conn_int->max_conn_interval != 0xffff)
         )
-    )
+       )
     {
         return NRF_ERROR_INVALID_PARAM;
     }
@@ -294,18 +294,18 @@
     if ((p_conn_int->min_conn_interval != 0xffff) &&
         (p_conn_int->max_conn_interval != 0xffff) &&
         (p_conn_int->min_conn_interval > p_conn_int->max_conn_interval)
-    )
+        )
     {
         return NRF_ERROR_INVALID_PARAM;
     }
-    
+
     return NRF_SUCCESS;
 }
 
 
 static uint32_t conn_int_encode(const ble_advdata_conn_int_t * p_conn_int,
-                                uint8_t *                      p_encoded_data,
-                                uint8_t *                      p_len)
+                                uint8_t                      * p_encoded_data,
+                                uint8_t                      * p_len)
 {
     uint32_t err_code;
 
@@ -314,32 +314,32 @@
     {
         return NRF_ERROR_DATA_SIZE;
     }
-    
+
     // Check parameters.
     err_code = conn_int_check(p_conn_int);
     if (err_code != NRF_SUCCESS)
     {
         return err_code;
     }
-    
+
     // Encode Length and AD Type.
     p_encoded_data[(*p_len)++] = 1 + 2 * sizeof(uint16_le_t);
     p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE;
-    
+
     // Encode Minimum and Maximum Connection Intervals.
     (*p_len) += uint16_encode(p_conn_int->min_conn_interval, &p_encoded_data[*p_len]);
     (*p_len) += uint16_encode(p_conn_int->max_conn_interval, &p_encoded_data[*p_len]);
-    
+
     return NRF_SUCCESS;
 }
 
 
 static uint32_t manuf_specific_data_encode(const ble_advdata_manuf_data_t * p_manuf_sp_data,
-                                           uint8_t *                        p_encoded_data,
-                                           uint8_t *                        p_len)
+                                           uint8_t                        * p_encoded_data,
+                                           uint8_t                        * p_len)
 {
     uint8_t data_size = sizeof(uint16_le_t) + p_manuf_sp_data->data.size;
-    
+
     // Check for buffer overflow.
     if ((*p_len) + ADV_DATA_OFFSET + data_size > BLE_GAP_ADV_MAX_SIZE)
     {
@@ -363,14 +363,14 @@
         memcpy(&p_encoded_data[*p_len], p_manuf_sp_data->data.p_data, p_manuf_sp_data->data.size);
         (*p_len) += p_manuf_sp_data->data.size;
     }
-    
+
     return NRF_SUCCESS;
 }
 
 
 static uint32_t service_data_encode(const ble_advdata_t * p_advdata,
-                                    uint8_t *             p_encoded_data,
-                                    uint8_t *             p_len)
+                                    uint8_t             * p_encoded_data,
+                                    uint8_t             * p_len)
 {
     uint8_t i;
 
@@ -379,22 +379,22 @@
     {
         return NRF_ERROR_INVALID_PARAM;
     }
-    
+
     for (i = 0; i < p_advdata->service_data_count; i++)
     {
         ble_advdata_service_data_t * p_service_data;
         uint8_t                      data_size;
-        
+
         p_service_data = &p_advdata->p_service_data_array[i];
         data_size      = sizeof(uint16_le_t) + p_service_data->data.size;
-    
+
         // Encode Length and AD Type.
         p_encoded_data[(*p_len)++] = 1 + data_size;
         p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_SERVICE_DATA;
-        
+
         // Encode service UUID.
         (*p_len) += uint16_encode(p_service_data->service_uuid, &p_encoded_data[*p_len]);
-        
+
         // Encode additional service data.
         if (p_service_data->data.size > 0)
         {
@@ -406,19 +406,19 @@
             (*p_len) += p_service_data->data.size;
         }
     }
-    
+
     return NRF_SUCCESS;
 }
 
 
 static uint32_t adv_data_encode(const ble_advdata_t * p_advdata,
-                                uint8_t *             p_encoded_data,
-                                uint8_t *             p_len)
+                                uint8_t             * p_encoded_data,
+                                uint8_t             * p_len)
 {
     uint32_t err_code = NRF_SUCCESS;
-    
+
     *p_len = 0;
-    
+
     // Encode name.
     if (p_advdata->name_type != BLE_ADVDATA_NO_NAME)
     {
@@ -428,7 +428,7 @@
             return err_code;
         }
     }
-    
+
     // Encode appearance.
     if (p_advdata->include_appearance)
     {
@@ -438,7 +438,7 @@
             return err_code;
         }
     }
-    
+
     // Encode flags.
     if (p_advdata->flags.size > 0)
     {
@@ -451,7 +451,7 @@
             return err_code;
         }
     }
-    
+
     // Encode TX power level.
     if (p_advdata->p_tx_power_level != NULL)
     {
@@ -475,7 +475,7 @@
             return err_code;
         }
     }
-    
+
     // Encode 'complete' uuid list.
     if (p_advdata->uuids_complete.uuid_cnt > 0)
     {
@@ -489,7 +489,7 @@
             return err_code;
         }
     }
-    
+
     // Encode 'solicited service' uuid list.
     if (p_advdata->uuids_solicited.uuid_cnt > 0)
     {
@@ -503,7 +503,7 @@
             return err_code;
         }
     }
-    
+
     // Encode Slave Connection Interval Range.
     if (p_advdata->p_slave_conn_int != NULL)
     {
@@ -513,7 +513,7 @@
             return err_code;
         }
     }
-    
+
     // Encode Manufacturer Specific Data.
     if (p_advdata->p_manuf_specific_data != NULL)
     {
@@ -525,7 +525,7 @@
             return err_code;
         }
     }
-    
+
     // Encode Service Data.
     if (p_advdata->service_data_count > 0)
     {
@@ -535,7 +535,7 @@
             return err_code;
         }
     }
-    
+
     return err_code;
 }
 
@@ -546,11 +546,11 @@
     if ((p_advdata->flags.size == 0)      ||
         (p_advdata->flags.p_data == NULL) ||
         ((p_advdata->flags.p_data[0] & BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED) == 0)
-    )
+       )
     {
         return NRF_ERROR_INVALID_PARAM;
     }
-    
+
     return NRF_SUCCESS;
 }
 
@@ -562,7 +562,7 @@
     {
         return NRF_ERROR_INVALID_PARAM;
     }
-    
+
     return NRF_SUCCESS;
 }
 
@@ -571,7 +571,7 @@
 {
     uint32_t  err_code;
     uint8_t   len_advdata = 0;
-    uint8_t   len_srdata = 0;
+    uint8_t   len_srdata  = 0;
     uint8_t   encoded_advdata[BLE_GAP_ADV_MAX_SIZE];
     uint8_t   encoded_srdata[BLE_GAP_ADV_MAX_SIZE];
     uint8_t * p_encoded_advdata;
@@ -585,7 +585,7 @@
         {
             return err_code;
         }
-        
+
         err_code = adv_data_encode(p_advdata, encoded_advdata, &len_advdata);
         if (err_code != NRF_SUCCESS)
         {
@@ -597,7 +597,7 @@
     {
         p_encoded_advdata = NULL;
     }
-    
+
     // Encode scan response data (if supplied).
     if (p_srdata != NULL)
     {
@@ -606,7 +606,7 @@
         {
             return err_code;
         }
-        
+
         err_code = adv_data_encode(p_srdata, encoded_srdata, &len_srdata);
         if (err_code != NRF_SUCCESS)
         {