Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (c) 2013, The Linux Foundation. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are met:
      6  *
      7  *  1. Redistributions of source code must retain the above copyright notice,
      8  *     this list of conditions and the following disclaimer.
      9  *  2. Redistributions in binary form must reproduce the above copyright notice,
     10  *     this list of conditions and the following disclaimer in the documentation
     11  *     and/or other materials provided with the distribution.
     12  *  3. The name of the author may not be used to endorse or promote products
     13  *     derived from this software without specific prior written permission.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     16  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     17  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
     18  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     19  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     21  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     22  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     23  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     24  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 #include "bt_vendor_persist.h"
     28 
     29 #ifdef BT_NV_SUPPORT
     30 #include "bt_nv.h"
     31 #include <log/log.h>
     32 
     33 /*===========================================================================
     34 FUNCTION   bt_vendor_nv_read
     35 
     36 DESCRIPTION
     37  Helper Routine to process the nv read command
     38 
     39 DEPENDENCIES
     40   NIL
     41 
     42 RETURN VALUE
     43   RETURN VALUE
     44   FALSE = failure, else TRUE
     45 
     46 SIDE EFFECTS
     47   None
     48 
     49 ===========================================================================*/
     50 uint8_t bt_vendor_nv_read
     51 (
     52   uint8_t nv_item,
     53   uint8_t * rsp_buf
     54 )
     55 {
     56   nv_persist_item_type my_nv_item;
     57   nv_persist_stat_enum_type cmd_result;
     58   boolean result = FALSE;
     59 
     60   switch(nv_item)
     61   {
     62     case NV_BD_ADDR_I:
     63       cmd_result = (nv_persist_stat_enum_type)bt_nv_cmd(NV_READ_F,  NV_BD_ADDR_I, &my_nv_item);
     64       ALOGI("CMD result: %d", cmd_result);
     65       if (NV_SUCCESS != cmd_result)
     66       {
     67         ALOGE("Failed to read BD_ADDR from NV");
     68         /* Send fail response */
     69         result = FALSE;
     70       }
     71       else
     72       {
     73         /* copy bytes */
     74         rsp_buf[0] = my_nv_item.bd_addr[0];
     75         rsp_buf[1] = my_nv_item.bd_addr[1];
     76         rsp_buf[2] = my_nv_item.bd_addr[2];
     77         rsp_buf[3] = my_nv_item.bd_addr[3];
     78         rsp_buf[4] = my_nv_item.bd_addr[4];
     79         rsp_buf[5] = my_nv_item.bd_addr[5];
     80 
     81         ALOGI("BD address read for NV_BD_ADDR_I: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
     82                 (unsigned int) my_nv_item.bd_addr[0],(unsigned int) my_nv_item.bd_addr[1],
     83                 (unsigned int) my_nv_item.bd_addr[2],(unsigned int) my_nv_item.bd_addr[3],
     84                 (unsigned int) my_nv_item.bd_addr[4],(unsigned int) my_nv_item.bd_addr[5]);
     85         result = TRUE;
     86       }
     87       break;
     88   }
     89   return result;
     90 }
     91 #endif /* End of BT_NV_SUPPORT */
     92