Removed extra spaces at end of line in compat dir
Subsystems (2)
PATCH 1/6 Removed extra spaces at end of line in compat dir
--- compat/bnep.c | 10 +++++----- compat/dun.c | 4 ++-- compat/dund.c | 6 +++--- compat/hidd.c | 2 +- compat/msdun.c | 8 ++++---- compat/pand.c | 8 ++++---- compat/sdp.c | 12 ++++++------ 7 files changed, 25 insertions(+), 25 deletions(-)
compat/bnep.c +5 -5
@@ -93,7 +93,7 @@ int bnep_init(void) }/* Temporary ioctl compatibility hack */ - { + {struct bnep_connlist_req req;struct bnep_conninfo ci[1 ];
@@ -194,19 +194,19 @@ static int bnep_connadd(int sk, uint16_t role, char *dev)return 0 ; } -struct __service_16 { +struct __service_16 {uint16_t dst;uint16_t src; } __attribute__ ((packed)); -struct __service_32 { +struct __service_32 {uint16_t unused1;uint16_t dst;uint16_t unused2;uint16_t src; } __attribute__ ((packed)); -struct __service_128 { +struct __service_128 {uint16_t unused1;uint16_t dst;uint16_t unused2[8 ];
@@ -246,7 +246,7 @@ int bnep_accept_connection(int sk, uint16_t role, char *dev)return bnep_connadd (sk, role, dev); } -/* Create BNEP connection +/* Create BNEP connection * sk - Connect L2CAP socket * role - Local role * service - Remote service
compat/dun.c +2 -2
@@ -158,7 +158,7 @@ static int dun_exec(char *tty, char *prog, char **args) {int pid =fork ();int fd; - +switch (pid) {case -1 :return -1 ;
@@ -244,7 +244,7 @@ int dun_cleanup(void)static int show_conn (struct rfcomm_dev_info *di,unsigned long arg) {pid_t pid; - + if (di->state == BT_CONNECTED && (di->flags & (1<<RFCOMM_REUSE_DLC)) && (di->flags & (1<<RFCOMM_TTY_ATTACHED)) &&
compat/dund.c +3 -3
@@ -247,7 +247,7 @@ static int create_connection(char *dst, bdaddr_t *bdaddr, int mrouter) sa.rc_bdaddr = src_addr;if (bind (sk, (struct sockaddr *) &sa,sizeof (sa))) -syslog (LOG_ERR ,"Bind failed. %s(%d)" , +syslog (LOG_ERR ,"Bind failed. %s(%d)" ,strerror (errno), errno); sa.rc_channel = ch;
@@ -337,7 +337,7 @@ static int do_connect(void)for (i =0 ; i < n; i++) {char dst[40 ];ba2str (&ii[i].bdaddr, dst); - + r =create_connection (dst, &ii[i].bdaddr,0 );if (r <0 ) { terminate =1 ;
@@ -405,7 +405,7 @@ static struct option main_lopts[] = {static const char *main_sopts ="hsc:k:Kr:i:lnp::DQ::AESMP:C::P:Xam:u" ; -static const char *main_help = +static const char *main_help ="Bluetooth LAP (LAN Access over PPP) daemon version %s\n" "Usage:\n" "\tdund <options> [pppd options]\n"
compat/hidd.c +1 -1
@@ -573,7 +573,7 @@ static void do_search(int ctl, bdaddr_t *bdaddr, uint8_t subclass, int fakehid,for (i =0 ; i < num_rsp; i++) {memcpy (class, (info+i)->dev_class,3 ); -if ((class[0 ] ==0x00 && class[2 ] ==0x00 && +if ((class[0 ] ==0x00 && class[2 ] ==0x00 && (class[1 ] ==0x40 || class[1 ] ==0x1f )) || (class[0 ] ==0x10 && class[1 ] ==0x02 && class[2 ] ==0x40 )) {bacpy (&dst, &(info+i)->bdaddr);
compat/msdun.c +4 -4
@@ -58,7 +58,7 @@ static int w4_str(int fd, char *str)char buf[40 ];unsigned len =0 ;int r; - +while (1 ) { r =read (fd, buf + len,sizeof (buf) - len -1 );if (r <0 ) {
@@ -92,7 +92,7 @@ static int ms_server(int fd)write_n (fd,"CLIENTSERVER" ,12 );case MS_PPP :return MS_SUCCESS ; -default : +default :return MS_FAILED ; } }
@@ -123,7 +123,7 @@ int ms_dun(int fd, int server, int timeo)alarm (0 );signal (SIGALRM , osig); - +switch (r) {case MS_SUCCESS :case MS_PPP :
@@ -142,7 +142,7 @@ int ms_dun(int fd, int server, int timeo) }alarm (timeout); - +if (server) r =ms_server (fd);else
compat/pand.c +4 -4
@@ -343,7 +343,7 @@ static int create_connection(char *dst, bdaddr_t *bdaddr)bacpy (&l2a.l2_bdaddr, bdaddr); l2a.l2_psm =htobs (BNEP_PSM ); -if (!connect (sk, (struct sockaddr *) &l2a,sizeof (l2a)) && +if (!connect (sk, (struct sockaddr *) &l2a,sizeof (l2a)) && !bnep_create_connection (sk, role, service, netdev)) {syslog (LOG_INFO ,"%s connected" , netdev);
@@ -430,7 +430,7 @@ static int do_connect(void)ba2str (&ii[i].bdaddr, dst);if (use_sdp) { -syslog (LOG_INFO ,"Searching for %s on %s" , +syslog (LOG_INFO ,"Searching for %s on %s" ,bnep_svc2str (service), dst);if (bnep_sdp_search (&src_addr, &ii[i].bdaddr, service) <=0 )
@@ -488,7 +488,7 @@ static int write_pidfile(void) strerror(errno), errno);return -1 ; } - +/* We're already running; send a SIGHUP (we presume that they * are calling ifup for a reason, so they probably want to * rescan) and then exit cleanly and let things go on in the
@@ -571,7 +571,7 @@ static struct option main_lopts[] = {static const char *main_sopts ="hsc:k:Kr:d:e:i:lnp::DQ::AESMC::P:u:o:z" ; -static const char *main_help = +static const char *main_help ="Bluetooth PAN daemon version %s\n" "Usage:\n" "\tpand <options>\n"
compat/sdp.c +6 -6
@@ -368,7 +368,7 @@ int get_alternate_device_info(const bdaddr_t *src, const bdaddr_t *dst, uint16_treturn -EIO ; } -void bnep_sdp_unregister (void ) +void bnep_sdp_unregister (void ) {if (record &&sdp_record_unregister (session, record))syslog (LOG_ERR ,"Service record unregistration failed." );
@@ -424,7 +424,7 @@ int bnep_sdp_register(bdaddr_t *device, uint16_t role)/* Supported protocols */ { -uint16_t ptype[4 ] = { +uint16_t ptype[4 ] = {0x0800 ,/* IPv4 */ 0x0806 ,/* ARP */ };
@@ -483,7 +483,7 @@ int bnep_sdp_register(bdaddr_t *device, uint16_t role) profile[0 ].version =0x0100 ; pfseq =sdp_list_append (NULL , &profile[0 ]);sdp_set_profile_descs (record, pfseq); - +sdp_set_info_attr (record,"Group Network Service" , name, desc);break ;
@@ -558,7 +558,7 @@ int bnep_sdp_search(bdaddr_t *src, bdaddr_t *dst, uint16_t service)static unsigned char async_uuid[] = {0x03 ,0x50 ,0x27 ,0x8F ,0x3D ,0xCA ,0x4E ,0x62 ,0x83 ,0x1D ,0xA4 ,0x11 ,0x65 ,0xFF ,0x90 ,0x6C }; -void dun_sdp_unregister (void ) +void dun_sdp_unregister (void ) {if (record &&sdp_record_unregister (session, record))syslog (LOG_ERR ,"Service record unregistration failed." );
@@ -575,7 +575,7 @@ int dun_sdp_register(bdaddr_t *device, uint8_t channel, int type) session =sdp_connect (BDADDR_ANY ,BDADDR_LOCAL ,0 );if (!session) { -syslog (LOG_ERR ,"Failed to connect to the local SDP server. %s(%d)" , +syslog (LOG_ERR ,"Failed to connect to the local SDP server. %s(%d)" ,strerror (errno), errno);return -1 ; }
@@ -670,7 +670,7 @@ int dun_sdp_search(bdaddr_t *src, bdaddr_t *dst, int *channel, int type) s =sdp_connect (src, dst,0 );if (!s) { -syslog (LOG_ERR ,"Failed to connect to the SDP server. %s(%d)" , +syslog (LOG_ERR ,"Failed to connect to the SDP server. %s(%d)" ,strerror (errno), errno);return -1 ; }
Signature · 1 line
1.7.0.4
PATCH 1/6 Remove extra spaces at end of line in compat dir
--- compat/bnep.c | 10 +++++----- compat/dun.c | 4 ++-- compat/dund.c | 6 +++--- compat/hidd.c | 2 +- compat/msdun.c | 8 ++++---- compat/pand.c | 8 ++++---- compat/sdp.c | 12 ++++++------ 7 files changed, 25 insertions(+), 25 deletions(-)
compat/bnep.c +5 -5
@@ -93,7 +93,7 @@ int bnep_init(void) }/* Temporary ioctl compatibility hack */ - { + {struct bnep_connlist_req req;struct bnep_conninfo ci[1 ];
@@ -194,19 +194,19 @@ static int bnep_connadd(int sk, uint16_t role, char *dev)return 0 ; } -struct __service_16 { +struct __service_16 {uint16_t dst;uint16_t src; } __attribute__ ((packed)); -struct __service_32 { +struct __service_32 {uint16_t unused1;uint16_t dst;uint16_t unused2;uint16_t src; } __attribute__ ((packed)); -struct __service_128 { +struct __service_128 {uint16_t unused1;uint16_t dst;uint16_t unused2[8 ];
@@ -246,7 +246,7 @@ int bnep_accept_connection(int sk, uint16_t role, char *dev)return bnep_connadd (sk, role, dev); } -/* Create BNEP connection +/* Create BNEP connection * sk - Connect L2CAP socket * role - Local role * service - Remote service
compat/dun.c +2 -2
@@ -158,7 +158,7 @@ static int dun_exec(char *tty, char *prog, char **args) {int pid =fork ();int fd; - +switch (pid) {case -1 :return -1 ;
@@ -244,7 +244,7 @@ int dun_cleanup(void)static int show_conn (struct rfcomm_dev_info *di,unsigned long arg) {pid_t pid; - + if (di->state == BT_CONNECTED && (di->flags & (1<<RFCOMM_REUSE_DLC)) && (di->flags & (1<<RFCOMM_TTY_ATTACHED)) &&
compat/dund.c +3 -3
@@ -247,7 +247,7 @@ static int create_connection(char *dst, bdaddr_t *bdaddr, int mrouter) sa.rc_bdaddr = src_addr;if (bind (sk, (struct sockaddr *) &sa,sizeof (sa))) -syslog (LOG_ERR ,"Bind failed. %s(%d)" , +syslog (LOG_ERR ,"Bind failed. %s(%d)" ,strerror (errno), errno); sa.rc_channel = ch;
@@ -337,7 +337,7 @@ static int do_connect(void)for (i =0 ; i < n; i++) {char dst[40 ];ba2str (&ii[i].bdaddr, dst); - + r =create_connection (dst, &ii[i].bdaddr,0 );if (r <0 ) { terminate =1 ;
@@ -405,7 +405,7 @@ static struct option main_lopts[] = {static const char *main_sopts ="hsc:k:Kr:i:lnp::DQ::AESMP:C::P:Xam:u" ; -static const char *main_help = +static const char *main_help ="Bluetooth LAP (LAN Access over PPP) daemon version %s\n" "Usage:\n" "\tdund <options> [pppd options]\n"
compat/hidd.c +1 -1
@@ -573,7 +573,7 @@ static void do_search(int ctl, bdaddr_t *bdaddr, uint8_t subclass, int fakehid,for (i =0 ; i < num_rsp; i++) {memcpy (class, (info+i)->dev_class,3 ); -if ((class[0 ] ==0x00 && class[2 ] ==0x00 && +if ((class[0 ] ==0x00 && class[2 ] ==0x00 && (class[1 ] ==0x40 || class[1 ] ==0x1f )) || (class[0 ] ==0x10 && class[1 ] ==0x02 && class[2 ] ==0x40 )) {bacpy (&dst, &(info+i)->bdaddr);
compat/msdun.c +4 -4
@@ -58,7 +58,7 @@ static int w4_str(int fd, char *str)char buf[40 ];unsigned len =0 ;int r; - +while (1 ) { r =read (fd, buf + len,sizeof (buf) - len -1 );if (r <0 ) {
@@ -92,7 +92,7 @@ static int ms_server(int fd)write_n (fd,"CLIENTSERVER" ,12 );case MS_PPP :return MS_SUCCESS ; -default : +default :return MS_FAILED ; } }
@@ -123,7 +123,7 @@ int ms_dun(int fd, int server, int timeo)alarm (0 );signal (SIGALRM , osig); - +switch (r) {case MS_SUCCESS :case MS_PPP :
@@ -142,7 +142,7 @@ int ms_dun(int fd, int server, int timeo) }alarm (timeout); - +if (server) r =ms_server (fd);else
compat/pand.c +4 -4
@@ -343,7 +343,7 @@ static int create_connection(char *dst, bdaddr_t *bdaddr)bacpy (&l2a.l2_bdaddr, bdaddr); l2a.l2_psm =htobs (BNEP_PSM ); -if (!connect (sk, (struct sockaddr *) &l2a,sizeof (l2a)) && +if (!connect (sk, (struct sockaddr *) &l2a,sizeof (l2a)) && !bnep_create_connection (sk, role, service, netdev)) {syslog (LOG_INFO ,"%s connected" , netdev);
@@ -430,7 +430,7 @@ static int do_connect(void)ba2str (&ii[i].bdaddr, dst);if (use_sdp) { -syslog (LOG_INFO ,"Searching for %s on %s" , +syslog (LOG_INFO ,"Searching for %s on %s" ,bnep_svc2str (service), dst);if (bnep_sdp_search (&src_addr, &ii[i].bdaddr, service) <=0 )
@@ -488,7 +488,7 @@ static int write_pidfile(void) strerror(errno), errno);return -1 ; } - +/* We're already running; send a SIGHUP (we presume that they * are calling ifup for a reason, so they probably want to * rescan) and then exit cleanly and let things go on in the
@@ -571,7 +571,7 @@ static struct option main_lopts[] = {static const char *main_sopts ="hsc:k:Kr:d:e:i:lnp::DQ::AESMC::P:u:o:z" ; -static const char *main_help = +static const char *main_help ="Bluetooth PAN daemon version %s\n" "Usage:\n" "\tpand <options>\n"
compat/sdp.c +6 -6
@@ -368,7 +368,7 @@ int get_alternate_device_info(const bdaddr_t *src, const bdaddr_t *dst, uint16_treturn -EIO ; } -void bnep_sdp_unregister (void ) +void bnep_sdp_unregister (void ) {if (record &&sdp_record_unregister (session, record))syslog (LOG_ERR ,"Service record unregistration failed." );
@@ -424,7 +424,7 @@ int bnep_sdp_register(bdaddr_t *device, uint16_t role)/* Supported protocols */ { -uint16_t ptype[4 ] = { +uint16_t ptype[4 ] = {0x0800 ,/* IPv4 */ 0x0806 ,/* ARP */ };
@@ -483,7 +483,7 @@ int bnep_sdp_register(bdaddr_t *device, uint16_t role) profile[0 ].version =0x0100 ; pfseq =sdp_list_append (NULL , &profile[0 ]);sdp_set_profile_descs (record, pfseq); - +sdp_set_info_attr (record,"Group Network Service" , name, desc);break ;
@@ -558,7 +558,7 @@ int bnep_sdp_search(bdaddr_t *src, bdaddr_t *dst, uint16_t service)static unsigned char async_uuid[] = {0x03 ,0x50 ,0x27 ,0x8F ,0x3D ,0xCA ,0x4E ,0x62 ,0x83 ,0x1D ,0xA4 ,0x11 ,0x65 ,0xFF ,0x90 ,0x6C }; -void dun_sdp_unregister (void ) +void dun_sdp_unregister (void ) {if (record &&sdp_record_unregister (session, record))syslog (LOG_ERR ,"Service record unregistration failed." );
@@ -575,7 +575,7 @@ int dun_sdp_register(bdaddr_t *device, uint8_t channel, int type) session =sdp_connect (BDADDR_ANY ,BDADDR_LOCAL ,0 );if (!session) { -syslog (LOG_ERR ,"Failed to connect to the local SDP server. %s(%d)" , +syslog (LOG_ERR ,"Failed to connect to the local SDP server. %s(%d)" ,strerror (errno), errno);return -1 ; }
@@ -670,7 +670,7 @@ int dun_sdp_search(bdaddr_t *src, bdaddr_t *dst, int *channel, int type) s =sdp_connect (src, dst,0 );if (!s) { -syslog (LOG_ERR ,"Failed to connect to the SDP server. %s(%d)" , +syslog (LOG_ERR ,"Failed to connect to the SDP server. %s(%d)" ,strerror (errno), errno);return -1 ; }
Signature · 1 line
1.7.0.4
PATCH 2/6 Remove extra spaces at end of line in lib dir
In reply to Jose Antonio Santos Cadenas--- lib/bluetooth.c | 2 +- lib/hci.c | 10 ++-- lib/hci.h | 6 +- lib/sdp.h | 2 +- lib/sdp_lib.h | 130 +++++++++++++++++++++++++++--------------------------- 5 files changed, 75 insertions(+), 75 deletions(-)
lib/bluetooth.c +1 -1
@@ -55,7 +55,7 @@ char *batostr(const bdaddr_t *ba)return NULL ;sprintf (str,"%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X" , - ba->b[0 ], ba->b[1 ], ba->b[2 ], + ba->b[0 ], ba->b[1 ], ba->b[2 ], ba->b[3 ], ba->b[4 ], ba->b[5 ]);return str;
lib/hci.c +5 -5
@@ -54,7 +54,7 @@ typedef struct {unsigned int val; } hci_map; -static char *hci_bit2str (hci_map *m,unsigned int val) +static char *hci_bit2str (hci_map *m,unsigned int val) {char *str =malloc (120 );char *ptr = str;
@@ -95,7 +95,7 @@ static int hci_str2bit(hci_map *map, char *str, unsigned int *val)return set; } -static char *hci_uint2str (hci_map *m,unsigned int val) +static char *hci_uint2str (hci_map *m,unsigned int val) {char *str =malloc (50 );char *ptr = str;
@@ -209,7 +209,7 @@ char *hci_dflagstostr(uint32_t flags)if (hci_test_bit (m->val, &flags)) ptr +=sprintf (ptr,"%s " , m->str); m++; - } + }return str; }
@@ -959,7 +959,7 @@ int hci_inquiry(int dev_id, int len, int nrsp, const uint8_t *lap, inquiry_info errno =ENODEV ;return -1 ; } - } + } dd =socket (AF_BLUETOOTH ,SOCK_RAW ,BTPROTO_HCI );if (dd <0 )
@@ -1009,7 +1009,7 @@ done:return ret; } -/* Open HCI device. +/* Open HCI device. * Returns device descriptor (dd). */ int hci_open_dev (int dev_id) {
lib/hci.h +3 -3
@@ -733,14 +733,14 @@ typedef struct {typedef struct {uint8_t name[248 ]; } __attribute__ ((packed))change_local_name_cp ; -#define CHANGE_LOCAL_NAME_CP_SIZE 248 +#define CHANGE_LOCAL_NAME_CP_SIZE 248#define OCF_READ_LOCAL_NAME 0x0014typedef struct {uint8_t status;uint8_t name[248 ]; } __attribute__ ((packed))read_local_name_rp ; -#define READ_LOCAL_NAME_RP_SIZE 249 +#define READ_LOCAL_NAME_RP_SIZE 249#define OCF_READ_CONN_ACCEPT_TIMEOUT 0x0015 typedef struct {
@@ -828,7 +828,7 @@ typedef struct {uint8_t status;uint8_t dev_class[3 ]; } __attribute__ ((packed)) read_class_of_dev_rp; -#define READ_CLASS_OF_DEV_RP_SIZE 4 +#define READ_CLASS_OF_DEV_RP_SIZE 4#define OCF_WRITE_CLASS_OF_DEV 0x0024 typedef struct {
lib/sdp.h +1 -1
@@ -297,7 +297,7 @@ extern "C" {#define SDP_ATTR_HID_BOOT_DEVICE 0x020e/* -* These identifiers are based on the SDP spec stating that +* These identifiers are based on the SDP spec stating that * "base attribute id of the primary (universal) language must be 0x0100" * * Other languages should have their own offset; e.g.:
lib/sdp_lib.h +65 -65
341 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 3/6 Remove extra spaces from sdpd-request.c
In reply to Jose Antonio Santos Cadenas--- src/sdpd-request.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-)
src/sdpd-request.c +9 -9
@@ -98,7 +98,7 @@ struct attrid {/* * Generic data element sequence extractor. Builds -* a list whose elements are those found in the +* a list whose elements are those found in the * sequence. The data type of elements found in the * sequence is returned in the reference pDataType */
@@ -301,8 +301,8 @@ static int sdp_cstate_get(uint8_t *buffer, size_t len,* specified in the "search pattern" must be present in the * "target pattern". Here "search pattern" is the set of UUIDs * specified by the service discovery client and "target pattern" -* is the set of UUIDs present in a service record. -* +* is the set of UUIDs present in a service record. +* * Return 1 if each and every UUID in the search * pattern exists in the target pattern, 0 if the * match succeeds and -1 on error.
@@ -420,7 +420,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)sdp_record_t *rec = (sdp_record_t *) list->data;SDPDBG ("Checking svcRec : 0x%x" , rec->handle); - +if (sdp_match_uuid (pattern, rec->pattern) >0 &&sdp_check_access (rec->handle, &req->device)) { rsp_count++;
@@ -429,7 +429,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf) handleSize +=sizeof (uint32_t ); } } - +SDPDBG ("Match count: %d" , rsp_count); buf->data_size += handleSize;
@@ -525,7 +525,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf) } } -done: +done:if (cstate)free (cstate);if (pattern)
@@ -684,11 +684,11 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf)SDPDBG ("SvcRecHandle : 0x%x" , handle);SDPDBG ("max_rsp_size : %d" , max_rsp_size); -/* +/* * Calculate Attribute size acording to MTU * We can send only (MTU - sizeof(sdp_pdu_hdr_t) - sizeof(sdp_cont_state_t)) */ - max_rsp_size =MIN (max_rsp_size, req->mtu -sizeof (sdp_pdu_hdr_t) - + max_rsp_size =MIN (max_rsp_size, req->mtu -sizeof (sdp_pdu_hdr_t) -sizeof (uint32_t ) -SDP_CONT_STATE_SIZE -sizeof (uint16_t ));/* pull header for AttributeList byte count */
@@ -840,7 +840,7 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf) tmpbuf.buf_size =USHRT_MAX ;memset (tmpbuf.data,0 ,USHRT_MAX ); -/* +/* * Calculate Attribute size acording to MTU * We can send only (MTU - sizeof(sdp_pdu_hdr_t) - sizeof(sdp_cont_state_t)) */
Signature · 1 line
1.7.0.4
PATCH 4/6 Remove extra spaces in test dir
In reply to Jose Antonio Santos Cadenas--- test/hciemu.c | 6 +++--- test/hstest.c | 2 +- test/rctest.c | 10 +++++----- test/scotest.c | 2 +- test/test-textfile.c | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-)
test/hciemu.c +3 -3
@@ -295,7 +295,7 @@ static void command_complete(uint16_t ogf, uint16_t ocf, int plen, void *data) he = (void *) ptr; ptr +=HCI_EVENT_HDR_SIZE ; he->evt =EVT_CMD_COMPLETE ; - he->plen =EVT_CMD_COMPLETE_SIZE + plen; + he->plen =EVT_CMD_COMPLETE_SIZE + plen; cc = (void *) ptr; ptr +=EVT_CMD_COMPLETE_SIZE ;
@@ -327,7 +327,7 @@ static void connect_request(struct vhci_conn *conn) he = (void *) ptr; ptr +=HCI_EVENT_HDR_SIZE ; he->evt =EVT_CONN_REQUEST ; - he->plen =EVT_CONN_REQUEST_SIZE ; + he->plen =EVT_CONN_REQUEST_SIZE ; cr = (void *) ptr; ptr +=EVT_CONN_REQUEST_SIZE ;
@@ -355,7 +355,7 @@ static void connect_complete(struct vhci_conn *conn) he = (void *) ptr; ptr +=HCI_EVENT_HDR_SIZE ; he->evt =EVT_CONN_COMPLETE ; - he->plen =EVT_CONN_COMPLETE_SIZE ; + he->plen =EVT_CONN_COMPLETE_SIZE ; cc = (void *) ptr; ptr +=EVT_CONN_COMPLETE_SIZE ;
test/hstest.c +1 -1
@@ -277,7 +277,7 @@ int main(int argc, char *argv[])case PLAY : rlen =read (fd, buf, rlen); - wlen =0 ; + wlen =0 ; p = buf;while (rlen > sco_mtu) { wlen +=write (sd, p, sco_mtu);
test/rctest.c +5 -5
@@ -436,7 +436,7 @@ static void recv_mode(int sk)if (r <0 )syslog (LOG_ERR ,"Read failed: %s (%d)" ,strerror (errno), errno); -return ; +return ; }if (timestamp) {
@@ -459,15 +459,15 @@ static void recv_mode(int sk) seq = sq; } seq++; - +/* Check length */ l =btohs (*(uint16_t *) (buf +4 ));if (r != l) {syslog (LOG_INFO ,"size missmatch: %d -> %d" , r, l);continue ; } - -/* Verify data */ + +/* Verify data */ for (i =6 ; i < r; i++) {if (buf[i] !=0x7f )syslog (LOG_INFO ,"data missmatch: byte %d 0x%2.2x" , i, buf[i]);
@@ -511,7 +511,7 @@ static void do_send(int sk) *(uint32_t *) buf =htobl (seq); *(uint16_t *) (buf +4 ) =htobs (data_size); seq++; - +if (send (sk, buf, data_size,0 ) <=0 ) {syslog (LOG_ERR ,"Send failed: %s (%d)" ,strerror (errno), errno);
test/scotest.c +1 -1
@@ -230,7 +230,7 @@ static void recv_mode(int sk)if (r <0 )syslog (LOG_ERR ,"Read failed: %s (%d)" ,strerror (errno), errno); -return ; +return ; } total += r; }
test/test-textfile.c +2 -2
@@ -65,7 +65,7 @@ int main(int argc, char *argv[])sprintf (key,"00:00:00:00:00:00" ); -if (textfile_del (filename, key) <0 ) +if (textfile_del (filename, key) <0 )fprintf (stderr,"%s (%d)\n" ,strerror (errno), errno);memset (value,0 ,sizeof (value));
@@ -88,7 +88,7 @@ int main(int argc, char *argv[])if (textfile_put (filename, key, value) <0 )fprintf (stderr,"%s (%d)\n" ,strerror (errno), errno); -if (textfile_del (filename, key) <0 ) +if (textfile_del (filename, key) <0 )fprintf (stderr,"%s (%d)\n" ,strerror (errno), errno); str =textfile_get (filename, key);
Signature · 1 line
1.7.0.4
PATCH 5/6 Remove extra spaces from tools dir
In reply to Jose Antonio Santos Cadenas--- tools/bccmd.c | 2 +- tools/dfutool.c | 4 +- tools/hciattach.c | 48 +++++++++++++++++++++++----------------------- tools/hciattach_st.c | 12 +++++----- tools/hciattach_ti.c | 2 +- tools/hciattach_tialt.c | 22 ++++++++++---------- tools/hciconfig.c | 6 ++-- tools/kword.h | 2 +- tools/main.c | 6 ++-- tools/ppporc.c | 4 +- tools/sdptool.c | 36 +++++++++++++++++----------------- 11 files changed, 72 insertions(+), 72 deletions(-)
tools/bccmd.c +1 -1
@@ -984,7 +984,7 @@ static int cmd_psread(int transport, int argc, char *argv[]) str =NULL ; } -printf ("// %s%s\n&%04x =" , str ?"PSKEY_" :"" , +printf ("// %s%s\n&%04x =" , str ?"PSKEY_" :"" , str ? str : val, pskey);for (i =0 ; i < length; i++)printf (" %02x%02x" , array[(i *2 ) +7 ], array[(i *2 ) +6 ]);
tools/dfutool.c +2 -2
@@ -341,7 +341,7 @@ static void cmd_verify(char *device, int argc, char **argv) size = st.st_size;if (!(buf =malloc (size))) { -perror ("Unable to allocate file buffer" ); +perror ("Unable to allocate file buffer" );exit (1 ); }
@@ -442,7 +442,7 @@ static void cmd_upgrade(char *device, int argc, char **argv) filesize = st.st_size;if (!(buf =malloc (filesize))) { -perror ("Unable to allocate file buffer" ); +perror ("Unable to allocate file buffer" );exit (1 ); }
tools/hciattach.c +24 -24
147 lines not on this page · raw message
tools/hciattach_st.c +6 -6
@@ -140,7 +140,7 @@ static int load_file(int dd, uint16_t version, const char *suffix)return -errno; } - found_fw_file =0 ; + found_fw_file =0 ;while (1 ) { d =readdir (dir);if (!d)
@@ -203,14 +203,14 @@ int stlc2500_init(int dd, bdaddr_t *bdaddr)int len;int err; -/* Hci_Cmd_Ericsson_Read_Revision_Information */ +/* Hci_Cmd_Ericsson_Read_Revision_Information */ len =do_command (dd,0xff ,0x000f ,NULL ,0 , buf,sizeof (buf));if (len <0 )return -1 ;printf ("%s\n" , buf); -/* HCI_Read_Local_Version_Information */ +/* HCI_Read_Local_Version_Information */ len =do_command (dd,0x04 ,0x0001 ,NULL ,0 , buf,sizeof (buf));if (len <0 )return -1 ;
@@ -219,7 +219,7 @@ int stlc2500_init(int dd, bdaddr_t *bdaddr) err =load_file (dd, version,".ptc" );if (err <0 ) { -if (err == -ENOENT ) +if (err == -ENOENT )fprintf (stderr,"No ROM patch file loaded.\n" );else return -1 ;
@@ -227,7 +227,7 @@ int stlc2500_init(int dd, bdaddr_t *bdaddr) err =load_file (dd, buf[2 ] <<8 | buf[1 ],".ssf" );if (err <0 ) { -if (err == -ENOENT ) +if (err == -ENOENT )fprintf (stderr,"No static settings file loaded.\n" );else return -1 ;
@@ -237,7 +237,7 @@ int stlc2500_init(int dd, bdaddr_t *bdaddr) cmd[1 ] =0x06 ;bacpy ((bdaddr_t *) (cmd +2 ), bdaddr); -/* Hci_Cmd_ST_Store_In_NVDS */ +/* Hci_Cmd_ST_Store_In_NVDS */ len =do_command (dd,0xff ,0x0022 , cmd,8 , buf,sizeof (buf));if (len <0 )return -1 ;
tools/hciattach_ti.c +1 -1
@@ -446,7 +446,7 @@ int texas_init(int fd, struct termios *ti)memset (resp,'\0' ,100 ); -/* It is possible to get software version with manufacturer specific +/* It is possible to get software version with manufacturer specific HCI command HCI_VS_TI_Version_Number. But the only thing you get more is if this is point-to-point or point-to-multipoint module */
tools/hciattach_tialt.c +11 -11
@@ -68,10 +68,10 @@ static int read_command_complete(int fd, unsigned short opcode, unsigned char le/* Read reply. */ FAILIF (read_hci_event (fd, (unsigned char *)&resp,sizeof (resp)) <0 ,"Failed to read response" ); - +/* Parse speed-change reply */ FAILIF (resp.uart_prefix !=HCI_EVENT_PKT , -"Error in response: not an event packet, but 0x%02x!\n" , +"Error in response: not an event packet, but 0x%02x!\n" , resp.uart_prefix); FAILIF(resp.hci_hdr.evt != EVT_CMD_COMPLETE, /* event must be event-complete */
@@ -107,7 +107,7 @@ static int texas_load_firmware(int fd, const char *firmware) {fprintf (stdout,"Opening firmware file: %s\n" , firmware); -FAILIF (fw <0 , +FAILIF (fw <0 ,"Could not open firmware file %s: %s (%d).\n" , firmware,strerror (errno), errno);
@@ -123,17 +123,17 @@ static int texas_load_firmware(int fd, const char *firmware) {break ;FAILIF (nr !=sizeof (cmdp),"Could not read H4 + HCI header!\n" );FAILIF (*cmdp !=HCI_COMMAND_PKT ,"Command is not an H4 command packet!\n" ); - +FAILIF (read (fw, data, cmd->plen) != cmd->plen,"Could not read %d bytes of data for command with opcode %04x!\n" , cmd->plen, cmd->opcode); - + {int nw;#if 0 -fprintf (stdout,"\topcode 0x%04x (%d bytes of data).\n" , - cmd->opcode, +fprintf (stdout,"\topcode 0x%04x (%d bytes of data).\n" , + cmd->opcode, cmd->plen);#endif struct iovec iov_cmd[2 ];
@@ -142,18 +142,18 @@ static int texas_load_firmware(int fd, const char *firmware) { iov_cmd[1 ].iov_base = data; iov_cmd[1 ].iov_len = cmd->plen; nw =writev (fd, iov_cmd,2 ); -FAILIF (nw != (int )sizeof (cmd) + cmd->plen, +FAILIF (nw != (int )sizeof (cmd) + cmd->plen,"Could not send entire command (sent only %d bytes)!\n" , nw); }/* Wait for response */ -if (read_command_complete (fd, +if (read_command_complete (fd, cmd->opcode, cmd->plen) <0 ) {return -1 ; } - + }while (1 );fprintf (stdout,"Firmware upload successful.\n" );
@@ -170,7 +170,7 @@ int texasalt_init(int fd, int speed, struct termios *ti)memset (resp,'\0' ,100 ); -/* It is possible to get software version with manufacturer specific +/* It is possible to get software version with manufacturer specific HCI command HCI_VS_TI_Version_Number. But the only thing you get more is if this is point-to-point or point-to-multipoint module */
tools/hciconfig.c +3 -3
@@ -453,7 +453,7 @@ static void cmd_name(int ctl, int hdev, char *opt)hci_close_dev (dd); } -/* +/* * see http://www.bluetooth.org/assigned-numbers/baseband.htm --- all * strings are reproduced verbatim */
@@ -562,7 +562,7 @@ static char *get_minor_device_name(int major, int minor)break ;case 5 :/* peripheral */ {static char cls_str[48 ]; - + cls_str[0 ] ='\0' ;switch (minor &48 ) {
@@ -1380,7 +1380,7 @@ static void cmd_page_to(int ctl, int hdev, char *opt)exit (1 ); }print_dev_hdr (&di); - + timeout =btohs (rp.timeout);printf ("\tPage timeout: %u slots (%.2f ms)\n" , timeout, (float )timeout *0.625 );
tools/kword.h +1 -1
@@ -28,7 +28,7 @@ struct keyword_t {int type; }; -extern struct keyword_t rfcomm_keyword[]; +extern struct keyword_t rfcomm_keyword[];int rfcomm_find_keyword (struct keyword_t *keyword,char *string);
tools/main.c +3 -3
@@ -118,7 +118,7 @@ static void print_dev_info(struct rfcomm_dev_info *di)printf ("rfcomm%d: %s channel %d %s %s\n" , di->id, addr, di->channel, - rfcomm_state[di->state], + rfcomm_state[di->state], di->flags ?rfcomm_flagstostr (di->flags) :"" ); }
@@ -717,7 +717,7 @@ static void usage(void)"\t-E, --encrypt Enable encryption\n" "\t-S, --secure Secure connection\n" "\t-M, --master Become the master of a piconet\n" -"\t-f, --config [file] Specify alternate config file\n" +"\t-f, --config [file] Specify alternate config file\n" "\t-a Show all devices (default)\n" "\n");
@@ -743,7 +743,7 @@ static struct option main_options[] = { { 0, 0, 0, 0 } }; -int main (int argc,char *argv[]) +int main (int argc,char *argv[]) {bdaddr_t bdaddr;int i, opt, ctl, dev_id, show_all =0 ;
tools/ppporc.c +2 -2
@@ -147,7 +147,7 @@ static int process_data(int fd) p[0 ].fd =0 ; p[0 ].events =POLLIN |POLLERR |POLLHUP |POLLNVAL ; - + p[1 ].fd = fd; p[1 ].events =POLLIN |POLLERR |POLLHUP |POLLNVAL ;
@@ -156,7 +156,7 @@ static int process_data(int fd)while (!__io_canceled) { p[0 ].revents =0 ; p[1 ].revents =0 ; - + err =poll (p,2 ,-1 );if (err <0 )break ;
tools/sdptool.c +18 -18
@@ -753,7 +753,7 @@ static void print_raw_attr(sdp_record_t *rec)* Set attributes with single values in SDP record * Jean II */ -static int set_attrib (sdp_session_t *sess,uint32_t handle,uint16_t attrib,char *value) +static int set_attrib (sdp_session_t *sess,uint32_t handle,uint16_t attrib,char *value) {sdp_list_t *attrid_list;uint32_t range =0x0000ffff ;
@@ -783,7 +783,7 @@ static int set_attrib(sdp_session_t *sess, uint32_t handle, uint16_t attrib, chasdp_attr_add_new (rec, attrib,SDP_UUID16 , &value_uuid.value.uuid16); }else if (!strncasecmp (value,"0x" ,2 )) {/* Int */ -uint32_t value_int; +uint32_t value_int; value_int =strtoul (value +2 ,NULL ,16 );printf ("Adding attrib 0x%X int 0x%X to record 0x%X\n" , attrib, value_int, handle);
@@ -811,7 +811,7 @@ static struct option set_options[] = { { 0, 0, 0, 0 } }; -static const char *set_help = +static const char *set_help ="Usage:\n" "\tget record_handle attrib_id attrib_value\n" ;
@@ -949,7 +949,7 @@ static struct option seq_options[] = { { 0, 0, 0, 0 } }; -static const char *seq_help = +static const char *seq_help ="Usage:\n" "\tget record_handle attrib_id attrib_values\n" ;
@@ -1685,7 +1685,7 @@ static int add_simaccess(sdp_session_t *session, svc_info_t *si)sdp_record_t record;uint8_t u8 = si->channel? si->channel :8 ;uint16_t u16 =0x31 ; -sdp_data_t *channel, *features; +sdp_data_t *channel, *features;int ret =0 ;memset ((void *)&record,0 ,sizeof (sdp_record_t));
@@ -2250,7 +2250,7 @@ static int add_hid_keyb(sdp_session_t *session, svc_info_t *si)static const uint16_t intr =0x13 ;static const uint16_t hid_attr[] = {0x100 ,0x111 ,0x40 ,0x0d ,0x01 ,0x01 };static const uint16_t hid_attr2[] = {0x0 ,0x01 ,0x100 ,0x1f40 ,0x01 ,0x01 }; -const uint8_t hid_spec[] = { +const uint8_t hid_spec[] = {0x05 ,0x01 ,// usage page 0x09 ,0x06 ,// keyboard 0xa1 ,0x01 ,// key codes
@@ -2263,14 +2263,14 @@ static int add_hid_keyb(sdp_session_t *session, svc_info_t *si)0x75 ,0x01 ,// input data variable absolute 0x95 ,0x08 ,// report count 0x81 ,0x02 ,// report size -0x75 ,0x08 , -0x95 ,0x01 , -0x81 ,0x01 , -0x75 ,0x01 , +0x75 ,0x08 , +0x95 ,0x01 , +0x81 ,0x01 , +0x75 ,0x01 ,0x95 ,0x05 ,0x05 ,0x08 ,0x19 ,0x01 , -0x29 ,0x05 , +0x29 ,0x05 ,0x91 ,0x02 ,0x75 ,0x03 , 0x95, 0x01,
@@ -3526,7 +3526,7 @@ static struct option add_options[] = { { 0, 0, 0, 0 } }; -static const char *add_help = +static const char *add_help ="Usage:\n" "\tadd [--handle=RECORD_HANDLE --channel=CHANNEL] service\n" ;
@@ -3591,7 +3591,7 @@ static int del_service(bdaddr_t *bdaddr, void *arg)sdp_session_t *sess;sdp_record_t *rec; -if (!arg) { +if (!arg) {printf ("Record handle was not specified.\n" );return -1 ; }
@@ -3630,7 +3630,7 @@ static struct option del_options[] = { { 0, 0, 0, 0 } }; -static const char *del_help = +static const char *del_help ="Usage:\n" "\tdel record_handle\n" ;
@@ -3771,7 +3771,7 @@ static struct option browse_options[] = { { 0, 0, 0, 0 } }; -static const char *browse_help = +static const char *browse_help ="Usage:\n" "\tbrowse [--tree] [--raw] [--xml] [--uuid uuid] [--l2cap] [bdaddr]\n" ;
@@ -3837,7 +3837,7 @@ static struct option search_options[] = { { 0, 0, 0, 0} }; -static const char *search_help = +static const char *search_help ="Usage:\n" "\tsearch [--bdaddr bdaddr] [--tree] [--raw] [--xml] SERVICE\n" "SERVICE is a name (string) or UUID (0x1002)\n" ;
@@ -3996,7 +3996,7 @@ static struct option records_options[] = { { 0, 0, 0, 0 } }; -static const char *records_help = +static const char *records_help ="Usage:\n" "\trecords [--tree] [--raw] [--xml] bdaddr\n" ;
@@ -4066,7 +4066,7 @@ static struct option get_options[] = { { 0, 0, 0, 0 } }; -static const char *get_help = +static const char *get_help ="Usage:\n" "\tget [--tree] [--raw] [--xml] [--bdaddr bdaddr] record_handle\n" ;
Signature · 1 line
1.7.0.4
Sorry, this subject should be:
Remove extra spaces at end of line in compat dir
I'll resend it.
Quoted 260 lines · El Friday 07 May 2010 00:27:07 Jose Antonio Santos Cadenas escribió:
--- compat/bnep.c | 10 +++++----- compat/dun.c | 4 ++-- compat/dund.c | 6 +++--- compat/hidd.c | 2 +- compat/msdun.c | 8 ++++---- compat/pand.c | 8 ++++---- compat/sdp.c | 12 ++++++------ 7 files changed, 25 insertions(+), 25 deletions(-)compat/bnep.c +5
-5@@ -93,7 +93,7 @@ int bnep_init(void) }/* Temporary ioctl compatibility hack */ - { + {struct bnep_connlist_req req;struct bnep_conninfo ci[1 ];@@ -194,19 +194,19 @@ static int bnep_connadd(int sk, uint16_t role, char *dev)return 0 ; } -struct __service_16 { +struct __service_16 {uint16_t dst;uint16_t src; } __attribute__ ((packed)); -struct __service_32 { +struct __service_32 {uint16_t unused1;uint16_t dst;uint16_t unused2;uint16_t src; } __attribute__ ((packed)); -struct __service_128 { +struct __service_128 {uint16_t unused1;uint16_t dst;uint16_t unused2[8 ];@@ -246,7 +246,7 @@ int bnep_accept_connection(int sk, uint16_t role, char *dev)return bnep_connadd (sk, role, dev); } -/* Create BNEP connection +/* Create BNEP connection * sk - Connect L2CAP socket * role - Local role * service - Remote service compat/dun.c +2
-2@@ -158,7 +158,7 @@ static int dun_exec(char *tty, char *prog, char **args) {int pid =fork ();int fd; - +switch (pid) {case -1 :return -1 ;@@ -244,7 +244,7 @@ int dun_cleanup(void)static int show_conn (struct rfcomm_dev_info *di,unsigned long arg) {pid_t pid; - + if (di->state == BT_CONNECTED && (di->flags & (1<<RFCOMM_REUSE_DLC)) && (di->flags & (1<<RFCOMM_TTY_ATTACHED)) &&compat/dund.c +3
-3@@ -247,7 +247,7 @@ static int create_connection(char *dst, bdaddr_t *bdaddr, int mrouter) sa.rc_bdaddr = src_addr;if (bind (sk, (struct sockaddr *) &sa,sizeof (sa))) -syslog (LOG_ERR ,"Bind failed. %s(%d)" , +syslog (LOG_ERR ,"Bind failed. %s(%d)" ,strerror (errno), errno); sa.rc_channel = ch;@@ -337,7 +337,7 @@ static int do_connect(void)for (i =0 ; i < n; i++) {char dst[40 ];ba2str (&ii[i].bdaddr, dst); - + r =create_connection (dst, &ii[i].bdaddr,0 );if (r <0 ) { terminate =1 ;@@ -405,7 +405,7 @@ static struct option main_lopts[] = {static const char *main_sopts ="hsc:k:Kr:i:lnp::DQ::AESMP:C::P:Xam:u" ; -static const char *main_help = +static const char *main_help ="Bluetooth LAP (LAN Access over PPP) daemon version %s\n" "Usage:\n" "\tdund <options> [pppd options]\n" compat/hidd.c +1
-1@@ -573,7 +573,7 @@ static void do_search(int ctl, bdaddr_t *bdaddr, uint8_t subclass, int fakehid,for (i =0 ; i < num_rsp; i++) {memcpy (class, (info+i)->dev_class,3 ); -if ((class[0 ] ==0x00 && class[2 ] ==0x00 && +if ((class[0 ] ==0x00 && class[2 ] ==0x00 && (class[1 ] ==0x40 || class[1 ] ==0x1f )) || (class[0 ] ==0x10 && class[1 ] ==0x02 && class[2 ] ==0x40 )) {bacpy (&dst, &(info+i)->bdaddr);compat/msdun.c +4
-4@@ -58,7 +58,7 @@ static int w4_str(int fd, char *str)char buf[40 ];unsigned len =0 ;int r; - +while (1 ) { r =read (fd, buf + len,sizeof (buf) - len -1 );if (r <0 ) {@@ -92,7 +92,7 @@ static int ms_server(int fd)write_n (fd,"CLIENTSERVER" ,12 );case MS_PPP :return MS_SUCCESS ; -default : +default :return MS_FAILED ; } }@@ -123,7 +123,7 @@ int ms_dun(int fd, int server, int timeo)alarm (0 );signal (SIGALRM , osig); - +switch (r) {case MS_SUCCESS :case MS_PPP :@@ -142,7 +142,7 @@ int ms_dun(int fd, int server, int timeo) }alarm (timeout); - +if (server) r =ms_server (fd);else compat/pand.c +4
-4@@ -343,7 +343,7 @@ static int create_connection(char *dst, bdaddr_t *bdaddr)bacpy (&l2a.l2_bdaddr, bdaddr); l2a.l2_psm =htobs (BNEP_PSM ); -if (!connect (sk, (struct sockaddr *) &l2a,sizeof (l2a)) && +if (!connect (sk, (struct sockaddr *) &l2a,sizeof (l2a)) && !bnep_create_connection (sk, role, service, netdev)) {syslog (LOG_INFO ,"%s connected" , netdev);@@ -430,7 +430,7 @@ static int do_connect(void)ba2str (&ii[i].bdaddr, dst);if (use_sdp) { -syslog (LOG_INFO ,"Searching for %s on %s" , +syslog (LOG_INFO ,"Searching for %s on %s" ,bnep_svc2str (service), dst);if (bnep_sdp_search (&src_addr, &ii[i].bdaddr, service) <=0 )@@ -488,7 +488,7 @@ static int write_pidfile(void) strerror(errno), errno);return -1 ; } - +/* We're already running; send a SIGHUP (we presume that they * are calling ifup for a reason, so they probably want to * rescan) and then exit cleanly and let things go on in the @@ -571,7 +571,7 @@ static struct option main_lopts[] = {static const char *main_sopts ="hsc:k:Kr:d:e:i:lnp::DQ::AESMC::P:u:o:z" ; -static const char *main_help = +static const char *main_help ="Bluetooth PAN daemon version %s\n" "Usage:\n" "\tpand <options>\n" compat/sdp.c +6
-6@@ -368,7 +368,7 @@ int get_alternate_device_info(const bdaddr_t *src, const bdaddr_t *dst, uint16_treturn -EIO ; } -void bnep_sdp_unregister (void ) +void bnep_sdp_unregister (void ) {if (record &&sdp_record_unregister (session, record))syslog (LOG_ERR ,"Service record unregistration failed." );@@ -424,7 +424,7 @@ int bnep_sdp_register(bdaddr_t *device, uint16_t role)/* Supported protocols */ { -uint16_t ptype[4 ] = { +uint16_t ptype[4 ] = {0x0800 ,/* IPv4 */ 0x0806 ,/* ARP */ };@@ -483,7 +483,7 @@ int bnep_sdp_register(bdaddr_t *device, uint16_t role) profile[0 ].version =0x0100 ; pfseq =sdp_list_append (NULL , &profile[0 ]);sdp_set_profile_descs (record, pfseq); - +sdp_set_info_attr (record,"Group Network Service" , name, desc);break ;@@ -558,7 +558,7 @@ int bnep_sdp_search(bdaddr_t *src, bdaddr_t *dst, uint16_t service)static unsigned char async_uuid[] = {0x03 ,0x50 ,0x27 ,0x8F ,0x3D ,0xCA ,0x4E ,0x62 ,0x83 ,0x1D ,0xA4 ,0x11 ,0x65 ,0xFF ,0x90 ,0x6C }; -void dun_sdp_unregister (void ) +void dun_sdp_unregister (void ) {if (record &&sdp_record_unregister (session, record))syslog (LOG_ERR ,"Service record unregistration failed." );@@ -575,7 +575,7 @@ int dun_sdp_register(bdaddr_t *device, uint8_t channel, int type) session =sdp_connect (BDADDR_ANY ,BDADDR_LOCAL ,0 );if (!session) { -syslog (LOG_ERR ,"Failed to connect to the local SDP server. %s(%d)" , +syslog (LOG_ERR ,"Failed to connect to the local SDP server. %s(%d)" ,strerror (errno), errno);return -1 ; }@@ -670,7 +670,7 @@ int dun_sdp_search(bdaddr_t *src, bdaddr_t *dst, int *channel, int type) s =sdp_connect (src, dst,0 );if (!s) { -syslog (LOG_ERR ,"Failed to connect to the SDP server. %s(%d)" , +syslog (LOG_ERR ,"Failed to connect to the SDP server. %s(%d)" ,strerror (errno), errno);return -1 ; }
PATCH 6/6 Change end of line from DOS to UNIX
In reply to Jose Antonio Santos CadenasFiles tools/ubcsp.c and tools/ubcsp.h had DOS end of line now they are changed to UNIX end of line
--- tools/ubcsp.c | 2360 ++++++++++++++++++++++++++++---------------------------- tools/ubcsp.h | 414 +++++----- 2 files changed, 1387 insertions(+), 1387 deletions(-)
tools/ubcsp.c +1180 -1180
@@ -1,1180 +1,1180 @@ -/* -* -* BlueZ - Bluetooth protocol stack for Linux -* -* Copyright (C) 2000-2005 CSR Ltd. -* -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -/*****************************************************************************/ -/*****************************************************************************/ -/*****************************************************************************/ -/** **/ -/** ubcsp,c **/ -/** **/ -/** MicroBCSP - a very low cost implementation of the BCSP protocol **/ -/** **/ -/*****************************************************************************/ - -#include "ubcsp.h" - -#if SHOW_PACKET_ERRORS ||SHOW_LE_STATES -#include <stdio.h> -#include <windows.h> -#endif - -static uint16 ubcsp_calc_crc (uint8 ch,uint16 crc); -static uint16 ubcsp_crc_reverse (uint16 ); - -/*****************************************************************************/ -/** **/ -/** Constant Data - ROM **/ -/** **/ -/*****************************************************************************/ - -/* This is the storage for the link establishment messages */ - -static const uint8 ubcsp_le_buffer[4 ][4 ] = - { - {0xDA ,0xDC ,0xED ,0xED }, - {0xAC ,0xAF ,0xEF ,0xEE }, - {0xAD ,0xEF ,0xAC ,0xED }, - {0xDE ,0xAD ,0xD0 ,0xD0 }, - }; - -/* These are the link establishment headers */ -/* The two version are for the CRC and non-CRC varients */ - -#if UBCSP_CRC -static const uint8 ubcsp_send_le_header[4 ] = - { -0x40 ,0x41 ,0x00 ,0x7E - }; -#else -static const uint8 ubcsp_send_le_header[4 ] = - { -0x00 ,0x41 ,0x00 ,0xBE - }; -#endif - -/*****************************************************************************/ -/** **/ -/** Static Data - RAM **/ -/** **/ -/*****************************************************************************/ - -/* This is the storage for all state data for ubcsp */ - -static struct ubcsp_configuration ubcsp_config; - -/* This is the ACK packet header - this will be overwritten when -we create an ack packet */ - -static uint8 ubcsp_send_ack_header[4 ] = - { -0x00 ,0x00 ,0x00 ,0x00 - }; - -/* This is the deslip lookup table */ - -static const uint8 ubcsp_deslip[2 ] = - { -SLIP_FRAME ,SLIP_ESCAPE , - }; - -/* This is a state machine table for link establishment */ - -static uint8 next_le_packet[16 ] = - { - ubcsp_le_sync,// uninit - ubcsp_le_conf,// init - ubcsp_le_none,// active - ubcsp_le_none, - ubcsp_le_sync_resp,// sync_resp - ubcsp_le_sync_resp, - ubcsp_le_none, - ubcsp_le_none, - ubcsp_le_none,// conf_resp - ubcsp_le_conf_resp, - ubcsp_le_conf_resp, - ubcsp_le_none, - }; - -/* This is the storage required for building send and crc data */ - -static uint8 ubcsp_send_header[4 ]; -static uint8 ubcsp_send_crc[2 ]; - -/* This is where the receive header is stored before the payload arrives */ - -static uint8 ubcsp_receive_header[4 ]; - -/*****************************************************************************/ -/** **/ -/** Code - ROM or RAM **/ -/** **/ -/*****************************************************************************/ - -/*****************************************************************************/ -/** **/ -/** ubcsp_initialize **/ -/** **/ -/** This initializes the state of the ubcsp engine to a known values **/ -/** **/ -/*****************************************************************************/ - -void ubcsp_initialize (void ) -{ - ubcsp_config.ack_number =0 ; - ubcsp_config.sequence_number =0 ; - ubcsp_config.send_ptr =0 ; - ubcsp_config.send_size =0 ; - ubcsp_config.receive_index =-4 ; - - ubcsp_config.delay =0 ; - -#if SHOW_LE_STATES -printf ("Hello Link Uninitialized\n" ); -#endif - - ubcsp_config.link_establishment_state = ubcsp_le_uninitialized; - ubcsp_config.link_establishment_packet = ubcsp_le_sync; -} - -/*****************************************************************************/ -/** **/ -/** ubcsp_send_packet **/ -/** **/ -/** This sends a packet structure for sending to the ubcsp engine **/ -/** This can only be called when the activity indication from ubcsp_poll **/ -/** indicates that a packet can be sent with UBCSP_PACKET_SENT **/ -/** **/ -/*****************************************************************************/ - -void ubcsp_send_packet (struct ubcsp_packet *send_packet) -{ -/* Initialize the send data to the packet we want to send */ - - ubcsp_config.send_packet = send_packet; - -/* we cannot send the packet at the moment -when we can at the moment, just set things to 0 */ - - ubcsp_config.send_size =0 ; - ubcsp_config.send_ptr =0 ; -} - -/*****************************************************************************/ -/** **/ -/** ubcsp_receive_packet **/ -/** **/ -/** This sends a packet structure for receiving to the ubcsp engine **/ -/** This can only be called when the activity indication from ubcsp_poll **/ -/** indicates that a packet can be sent with UBCSP_PACKET_RECEIVED **/ -/** **/ -/*****************************************************************************/ - -void ubcsp_receive_packet (struct ubcsp_packet *receive_packet) -{ -/* Initialize the receive data to the packet we want to receive */ - - ubcsp_config.receive_packet = receive_packet; - -/* setup to receive the header first */ - - ubcsp_config.receive_index =-4 ; -} - -/*****************************************************************************/ -/** **/ -/** ubcsp_calc_crc **/ -/** **/ -/** Takes the next 8 bit value ch, and updates the crc with this value **/ -/** **/ -/*****************************************************************************/ - - -#ifdef UBCSP_CRC - -static uint16 ubcsp_calc_crc (uint8 ch,uint16 crc) -{ -/* Calculate the CRC using the above 16 entry lookup table */ - -static const uint16 crc_table[] = - { -0x0000 ,0x1081 ,0x2102 ,0x3183 , -0x4204 ,0x5285 ,0x6306 ,0x7387 , -0x8408 ,0x9489 ,0xa50a ,0xb58b , -0xc60c ,0xd68d ,0xe70e ,0xf78f - }; - -/* Do this four bits at a time - more code, less space */ - - crc = (crc >>4 ) ^ crc_table[(crc ^ ch) &0x000f ]; - crc = (crc >>4 ) ^ crc_table[(crc ^ (ch >>4 )) &0x000f ]; - -return crc; -} - -/*****************************************************************************/ -/** **/ -/** ubcsp_crc_reverse **/ -/** **/ -/** Reserves the bits in crc and returns the new value **/ -/** **/ -/*****************************************************************************/ - -static uint16 ubcsp_crc_reverse (uint16 crc) -{ -int32 - b, - rev; - -/* Reserse the bits to compute the actual CRC value */ - -for (b =0 , rev=0 ; b <16 ; b++) - { - rev = rev <<1 ; - rev |= (crc &1 ); - crc = crc >>1 ; - } - -return rev; -} - -#endif - -/*****************************************************************************/ -/** **/ -/** ubcsp_put_slip_uart **/ -/** **/ -/** Outputs a single octet to the uart **/ -/** If the octet needs to be escaped, then output the escape value **/ -/** and then store the second octet to be output later **/ -/** **/ -/*****************************************************************************/ - -static void ubcsp_put_slip_uart (uint8 ch) -{ -/* output a single UART octet */ - -/* If it needs to be escaped, then output the escape octet -and set the send_slip_escape so that the next time we -output the second octet for the escape correctly. -This is done right at the top of ubcsp_poll */ - -if (ch ==SLIP_FRAME ) - { -put_uart (SLIP_ESCAPE ); - ubcsp_config.send_slip_escape =SLIP_ESCAPE_FRAME ; - } -else if (ch ==SLIP_ESCAPE ) - { -put_uart (SLIP_ESCAPE ); - ubcsp_config.send_slip_escape =SLIP_ESCAPE_ESCAPE ; - } -else - { -/* Not escaped, so just output octet */ - -put_uart (ch); - } -} - -/*****************************************************************************/ -/** **/ -/** ubcsp_which_le_payload **/ -/** **/ -/** Check the payload of this packet, and determine which of the four **/ -/** link establishment packets this was. **/ -/** Can return 5 if it is not a valid link establishment packet **/ -/** **/ -/*****************************************************************************/ - -static uint32 ubcsp_which_le_payload (const uint8 *payload) -{ -static int32 - octet, - loop; - -/* Search through the various link establishment payloads to find -which one we have received */ - -for (loop =0 ; loop <4 ; loop ++) - { -for (octet =0 ; octet <4 ; octet ++) - { -if (payload[octet] != ubcsp_le_buffer[loop][octet]) - { -/* Bad match, just to loop again */ - goto bad_match_loop; - } - } - -/* All the octets matched, return the value */ - -return loop; - -/* Jumps out of octet loop if we got a bad match */ -bad_match_loop: - {} - } - -/* Non of the link establishment payloads matched - return invalid value */ - -return 5 ; -} - -/*****************************************************************************/ -/** **/ -/** ubcsp_recevied_packet **/ -/** **/ -/** This function is called when we have a SLIP END octet and a full **/ -/** packet header and possibly data in the receive packet **/ -/** **/ -/*****************************************************************************/ - -static uint8 ubcsp_recevied_packet (void ) -{ -static uint8 - receive_crc, - receive_seq, - receive_ack, - activity; - -#if UBCSP_CRC -static int32 - loop; - -static uint16 - crc; -#endif - -static uint16 - length; - -/* Keep track of what activity this received packet will cause */ - - activity =0 ; - -/*** Do all error checks that we can ***/ - -/* First check the header checksum */ - -if (((ubcsp_receive_header[0 ] + ubcsp_receive_header[1 ] + ubcsp_receive_header[2 ] + ubcsp_receive_header[3 ]) &0xff ) !=0xff ) - { -/* Header Checksum Error */ - -#if SHOW_PACKET_ERRORS -printf ("\n######################## Header Checksum Error %02X %02X %02X %02X\n" , - ubcsp_receive_header[0 ], - ubcsp_receive_header[1 ], - ubcsp_receive_header[2 ], - ubcsp_receive_header[3 ]); -#endif - -/* If we have a header checksum error, send an ack in return -this gets a packet to be resent as quickly as possible */ - - ubcsp_config.send_ack =1 ; - -return activity; - } - -/* Decode the received packets header */ - - ubcsp_config.receive_packet->reliable = (ubcsp_receive_header[0 ] &0x80 ) >>7 ; - - receive_crc = (ubcsp_receive_header[0 ] &0x40 ) >>6 ; - receive_ack = (ubcsp_receive_header[0 ] &0x38 ) >>3 ; - receive_seq = (ubcsp_receive_header[0 ] &0x07 ); - - ubcsp_config.receive_packet->channel = (ubcsp_receive_header[1 ] &0x0f ); - - length = - ((ubcsp_receive_header[1 ] &0xf0 ) >>4 ) | - (ubcsp_receive_header[2 ] <<4 ); - -#if SHOW_PACKET_ERRORS -if (ubcsp_config.receive_packet->reliable) - { -printf (" : %10d Recv SEQ: %d ACK %d\n" , -GetTickCount () %100000 , - receive_seq, - receive_ack); - } -else if (ubcsp_config.receive_packet->channel !=1 ) - { -printf (" : %10d Recv ACK %d\n" , -GetTickCount () %100000 , - receive_ack); - } -#endif - -/* Check for length errors */ - -#if UBCSP_CRC -if (receive_crc) - { -/* If this packet had a CRC, then the length of the payload -should be 2 less than the received size of the payload */ - -if (length +2 != ubcsp_config.receive_index) - { -/* Slip Length Error */ - -#if SHOW_PACKET_ERRORS -printf ("\n######################## Slip Length Error (With CRC) %d,%d\n" , length, ubcsp_config.receive_index -2 ); -#endif - -/* If we have a payload length error, send an ack in return -this gets a packet to be resent as quickly as possible */ - - ubcsp_config.send_ack =1 ; -return activity; - } - -/* We have a CRC at the end of this packet */ - - ubcsp_config.receive_index -=2 ; - -/* Calculate the packet CRC */ - - crc =0xffff ; - -/* CRC the packet header */ - -for (loop =0 ; loop <4 ; loop ++) - { - crc =ubcsp_calc_crc (ubcsp_receive_header[loop], crc); - } - -/* CRC the packet payload - without the CRC bytes */ - -for (loop =0 ; loop < ubcsp_config.receive_index; loop ++) - { - crc =ubcsp_calc_crc (ubcsp_config.receive_packet->payload[loop], crc); - } - -/* Reverse the CRC */ - - crc =ubcsp_crc_reverse (crc); - -/* Check the CRC is correct */ - -if - ( - (((crc &0xff00 ) >>8 ) != ubcsp_config.receive_packet->payload[ubcsp_config.receive_index]) || - ((crc &0xff ) != ubcsp_config.receive_packet->payload[ubcsp_config.receive_index +1 ]) - ) - { -#if SHOW_PACKET_ERRORS -printf ("\n######################## CRC Error\n" ); -#endif - -/* If we have a packet crc error, send an ack in return -this gets a packet to be resent as quickly as possible */ - - ubcsp_config.send_ack =1 ; -return activity; - } - } -else - { -#endif -/* No CRC present, so just check the length of payload with that received */ - -if (length != ubcsp_config.receive_index) - { -/* Slip Length Error */ - -#if SHOW_PACKET_ERRORS -printf ("\n######################## Slip Length Error (No CRC) %d,%d\n" , length, ubcsp_config.receive_index); -#endif - -/* If we have a payload length error, send an ack in return -this gets a packet to be resent as quickly as possible */ - - ubcsp_config.send_ack =1 ; -return activity; - } -#if UBCSP_CRC - } -#endif - -/*** We have a fully formed packet having passed all data integrity checks ***/ - -/* Check if we have an ACK for the last packet we sent */ - -if (receive_ack != ubcsp_config.sequence_number) - { -/* Since we only have a window size of 1, if the ACK is not equal to SEQ -then the packet was sent */ - -if - ( - (ubcsp_config.send_packet) && - (ubcsp_config.send_packet->reliable) - ) - { -/* We had sent a reliable packet, so clear this packet -Then increament the sequence number for the next packet */ - - ubcsp_config.send_packet =0 ; - ubcsp_config.sequence_number ++; - ubcsp_config.delay =0 ; - -/* Notify the caller that we have SENT a packet */ - - activity |=UBCSP_PACKET_SENT ; - } - } - -/*** Now we can concentrate of the packet we have received ***/ - -/* Check for Link Establishment packets */ - -if (ubcsp_config.receive_packet->channel ==1 ) - { -/* Link Establishment */ - - ubcsp_config.delay =0 ; - -/* Find which link establishment packet this payload means -This could return 5, meaning none */ - -switch (ubcsp_which_le_payload (ubcsp_config.receive_packet->payload)) - { -case 0 : - { -/* SYNC Recv'd */ - -#if SHOW_LE_STATES -printf ("Recv SYNC\n" ); -#endif - -/* If we receive a SYNC, then we respond to it with a SYNC RESP -but only if we are not active. -If we are active, then we have a PEER RESET */ - -if (ubcsp_config.link_establishment_state < ubcsp_le_active) - { - ubcsp_config.link_establishment_resp =1 ; - } -else - { -/* Peer reset !!!! */ - -#if SHOW_LE_STATES -printf ("\n\n\n\n\nPEER RESET\n\n" ); -#endif - -/* Reinitialize the link */ - -ubcsp_initialize (); - -/* Tell the host what has happened */ - -return UBCSP_PEER_RESET ; - } -break ; - } - -case 1 : - { -/* SYNC RESP Recv'd */ - -#if SHOW_LE_STATES -printf ("Recv SYNC RESP\n" ); -#endif - -/* If we receive a SYNC RESP, push us into the initialized state */ - -if (ubcsp_config.link_establishment_state < ubcsp_le_initialized) - { -#if SHOW_LE_STATES -printf ("Link Initialized\n" ); -#endif - ubcsp_config.link_establishment_state = ubcsp_le_initialized; - } - -break ; - } - -case 2 : - { -/* CONF Recv'd */ - -#if SHOW_LE_STATES -printf ("Recv CONF\n" ); -#endif - -/* If we receive a CONF, and we are initialized or active -then respond with a CONF RESP */ - -if (ubcsp_config.link_establishment_state >= ubcsp_le_initialized) - { - ubcsp_config.link_establishment_resp =2 ; - } - -break ; - } - -case 3 : - { -/* CONF RESP Recv'd */ - -#if SHOW_LE_STATES -printf ("Recv CONF RESP\n" ); -#endif - -/* If we received a CONF RESP, then push us into the active state */ - -if (ubcsp_config.link_establishment_state < ubcsp_le_active) - { -#if SHOW_LE_STATES -printf ("Link Active\n" ); -#endif - - ubcsp_config.link_establishment_state = ubcsp_le_active; - ubcsp_config.send_size =0 ; - -return activity |UBCSP_PACKET_SENT ; - } - -break ; - } - } - -/* We have finished processing Link Establishment packets */ - } -else if (ubcsp_config.receive_index) - { -/* We have some payload data we need to process -but only if we are active - otherwise, we just ignore it */ - -if (ubcsp_config.link_establishment_state == ubcsp_le_active) - { -if (ubcsp_config.receive_packet->reliable) - { -/* If the packet we've just received was reliable -then send an ACK */ - - ubcsp_config.send_ack =1 ; - -/* We the sequence number we received is the same as -the last ACK we sent, then we have received a packet in sequence */ - -if (receive_seq == ubcsp_config.ack_number) - { -/* Increase the ACK number - which will be sent in the next ACK -or normal packet we send */ - - ubcsp_config.ack_number ++; - -/* Set the values in the receive_packet structure, so the caller -knows how much data we have */ - - ubcsp_config.receive_packet->length = length; - ubcsp_config.receive_packet =0 ; - -/* Tell the caller that we have received a packet, and that it -will be ACK'ed */ - - activity |=UBCSP_PACKET_RECEIVED |UBCSP_PACKET_ACK ; - } - } -else - { -/* Set the values in the receive_packet structure, so the caller -knows how much data we have */ - - ubcsp_config.receive_packet->length = length; - ubcsp_config.receive_packet =0 ; - -/* Tell the caller that we have received a packet */ - - activity |=UBCSP_PACKET_RECEIVED ; - } - } - } - -/* Just return any activity that occured */ - -return activity; -} - -/*****************************************************************************/ -/** **/ -/** ubcsp_setup_packet **/ -/** **/ -/** This function is called to setup a packet to be sent **/ -/** This allows just a header, or a header and payload to be sent **/ -/** It also allows the header checksum to be precalcuated **/ -/** or calculated here **/ -/** part1 is always 4 bytes **/ -/** **/ -/*****************************************************************************/ - -static void ubcsp_setup_packet (uint8 *part1,uint8 calc,uint8 *part2,uint16 len2) -{ -/* If we need to calculate the checksum, do that now */ - -if (calc) - { - part1[3 ] = - ~(part1[0 ] + part1[1 ] + part1[2 ]); - } - -/* Setup the header send pointer and size so we can clock this out */ - - ubcsp_config.send_ptr = part1; - ubcsp_config.send_size =4 ; - -/* Setup the payload send pointer and size */ - - ubcsp_config.next_send_ptr = part2; - ubcsp_config.next_send_size = len2; - -#if UBCSP_CRC -/* Initialize the crc as required */ - - ubcsp_config.send_crc =-1 ; - - ubcsp_config.need_send_crc =1 ; -#endif -} - -/*****************************************************************************/ -/** **/ -/** ubcsp_sent_packet **/ -/** **/ -/** Called when we have finished sending a packet **/ -/** If this packet was unreliable, then notify caller, and clear the data **/ -/** **/ -/*****************************************************************************/ - -static uint8 ubcsp_sent_packet (void ) -{ -if (ubcsp_config.send_packet) - { -if (!ubcsp_config.send_packet->reliable) - { -/* We had a packet sent that was unreliable */ - -/* Forget about this packet */ - - ubcsp_config.send_packet =0 ; - -/* Notify caller that they can send another one */ - -return UBCSP_PACKET_SENT ; - } - } - -/* We didn't have a packet, or it was reliable -Must wait for ACK before allowing another packet to be sent */ - -return 0 ; -} - -/*****************************************************************************/ -/** **/ -/** ubcsp_poll **/ -/** **/ -/** This is the main function for ubcsp **/ -/** It performs a number of tasks **/ -/** **/ -/** 1) Send another octet to the UART - escaping as required **/ -/** 2) Setup the payload to be sent after the header has been sent **/ -/** 3) Send the CRC for the packet if required **/ -/** **/ -/** 4) Calculate the next Link Establishment State **/ -/** 5) Send a Link Establishment packet **/ -/** 6) Send a normal packet if available **/ -/** 7) Send an ACK packet if required **/ -/** **/ -/** 8) Receive octets from UART and deslip them as required **/ -/** 9) Place received octets into receive header or receive payload buffer **/ -/** 10) Process received packet when SLIP_END is received **/ -/** **/ -/** 11) Keep track of ability of caller to delay recalling **/ -/** **/ -/*****************************************************************************/ - -uint8 ubcsp_poll (uint8 *activity) -{ -uint8 - delay =UBCSP_POLL_TIME_IMMEDIATE ; - -uint8 - value; - -/* Assume no activity to start with */ - - *activity =0 ; - -/* If we don't have to delay, then send something if we can */ - -if (!ubcsp_config.delay) - { -/* Do we have something we are sending to send */ - -if (ubcsp_config.send_size) - { -/* We have something to send so send it */ - -if (ubcsp_config.send_slip_escape) - { -/* Last time we send a SLIP_ESCAPE octet -this time send the second escape code */ - -put_uart (ubcsp_config.send_slip_escape); - - ubcsp_config.send_slip_escape =0 ; - } -else - { -#if UBCSP_CRC -/* get the value to send, and calculate CRC as we go */ - - value = *ubcsp_config.send_ptr ++; - - ubcsp_config.send_crc =ubcsp_calc_crc (value, ubcsp_config.send_crc); - -/* Output the octet */ - -ubcsp_put_slip_uart (value); -#else -/* Just output the octet*/ - -ubcsp_put_slip_uart (*ubcsp_config.send_ptr ++); -#endif - } - -/* If we did output a SLIP_ESCAPE, then don't process the end of a block */ - -if ((!ubcsp_config.send_slip_escape) && ((ubcsp_config.send_size = ubcsp_config.send_size -1 ) ==0 )) - { -/*** We are at the end of a block - either header or payload ***/ - -/* setup the next block */ - - ubcsp_config.send_ptr = ubcsp_config.next_send_ptr; - ubcsp_config.send_size = ubcsp_config.next_send_size; - ubcsp_config.next_send_ptr =0 ; - ubcsp_config.next_send_size =0 ; - -#if UBCSP_CRC -/* If we have no successor block -then we might need to send the CRC */ - -if (!ubcsp_config.send_ptr) - { -if (ubcsp_config.need_send_crc) - { -/* reverse the CRC from what we computed along the way */ - - ubcsp_config.need_send_crc =0 ; - - ubcsp_config.send_crc =ubcsp_crc_reverse (ubcsp_config.send_crc); - -/* Save in the send_crc buffer */ - - ubcsp_send_crc[0 ] = (uint8) (ubcsp_config.send_crc >>8 ); - ubcsp_send_crc[1 ] = (uint8 ) ubcsp_config.send_crc; - -/* Setup to send this buffer */ - - ubcsp_config.send_ptr = ubcsp_send_crc; - ubcsp_config.send_size =2 ; - } -else - { -/* We don't need to send the crc -either we just have, or this packet doesn't include it */ - -/* Output the end of FRAME marker */ - -put_uart (SLIP_FRAME ); - -/* Check if this is an unreliable packet */ - - *activity |=ubcsp_sent_packet (); - -/* We've sent the packet, so don't need to have be called quickly soon */ - - delay =UBCSP_POLL_TIME_DELAY ; - } - } -#else -/* If we have no successor block -then we might need to send the CRC */ - -if (!ubcsp_config.send_ptr) - { -/* Output the end of FRAME marker */ - -put_uart (SLIP_FRAME ); - -/* Check if this is an unreliable packet */ - - *activity |=ubcsp_sent_packet (); - -/* We've sent the packet, so don't need to have be called quickly soon */ - - delay =UBCSP_POLL_TIME_DELAY ; - } -#endif - } - } -else if (ubcsp_config.link_establishment_packet == ubcsp_le_none) - { -/* We didn't have something to send -AND we have no Link Establishment packet to send */ - -if (ubcsp_config.link_establishment_resp &2 ) - { -/* Send the start of FRAME packet */ - -put_uart (SLIP_FRAME ); - -/* We did require a RESP packet - so setup the send */ - -ubcsp_setup_packet ((uint8 *) ubcsp_send_le_header,0 , (uint8 *) ubcsp_le_buffer[ubcsp_le_conf_resp],4 ); - -/* We have now "sent" this packet */ - - ubcsp_config.link_establishment_resp =0 ; - } -else if (ubcsp_config.send_packet) - { -/* There is a packet ready to be sent */ - -/* Send the start of FRAME packet */ - -put_uart (SLIP_FRAME ); - -/* Encode up the packet header using ACK and SEQ numbers */ - - ubcsp_send_header[0] = - (ubcsp_config.send_packet->reliable << 7) | -#if UBCSP_CRC -0x40 |/* Always use CRC's */ -#endif - (ubcsp_config.ack_number <<3 ) | - (ubcsp_config.sequence_number); - -/* Encode up the packet header's channel and length */ - ubcsp_send_header[1 ] = - (ubcsp_config.send_packet->channel &0x0f ) | - ((ubcsp_config.send_packet->length <<4 ) &0xf0 ); - - ubcsp_send_header[2 ] = - (ubcsp_config.send_packet->length >>4 ) &0xff ; - -/* Let the ubcsp_setup_packet function calculate the header checksum */ - -ubcsp_setup_packet ((uint8 *) ubcsp_send_header,1 , ubcsp_config.send_packet->payload, ubcsp_config.send_packet->length); - -/* Don't need to send an ACK - we just place on in this packet */ - - ubcsp_config.send_ack =0 ; - -#if SHOW_PACKET_ERRORS -printf (" : %10d Send %d Ack %d\n" , -GetTickCount () %100000 , - ubcsp_config.sequence_number, - ubcsp_config.ack_number); -#endif - } -else if (ubcsp_config.send_ack) - { -/* Send the start of FRAME packet */ - -put_uart (SLIP_FRAME ); - -#if SHOW_PACKET_ERRORS -printf (" : %10d Send ACK %d\n" , -GetTickCount () %100000 , - ubcsp_config.ack_number); -#endif - -/* The ack packet is already computed apart from the first octet */ - - ubcsp_send_ack_header[0] = -#if UBCSP_CRC -0x40 | -#endif - (ubcsp_config.ack_number <<3 ); - -/* Let the ubcsp_setup_packet function calculate the header checksum */ - -ubcsp_setup_packet (ubcsp_send_ack_header,1 ,0 ,0 ); - -/* We've now sent the ack */ - - ubcsp_config.send_ack = 0; - } -else - { -/* We didn't have a Link Establishment response packet, -a normal packet or an ACK packet to send */ - - delay =UBCSP_POLL_TIME_DELAY ; - } - } -else - { -#if SHOW_PACKET_ERRORS -// printf (" : %10d Send LE %d\n", -// GetTickCount () % 100000, -// ubcsp_config.link_establishment_packet); -#endif - -/* Send A Link Establishment Message */ - -put_uart (SLIP_FRAME ); - -/* Send the Link Establishment header followed by the -Link Establishment packet */ - -ubcsp_setup_packet ((uint8 *) ubcsp_send_le_header,0 , (uint8 *) ubcsp_le_buffer[ubcsp_config.link_establishment_packet],4 ); - -/* start sending immediately */ - - ubcsp_config.delay =0 ; - -/* workout what the next link establishment packet should be */ - - ubcsp_config.link_establishment_packet = next_le_packet[ubcsp_config.link_establishment_state + ubcsp_config.link_establishment_resp *4 ]; - -/* We have now delt with any response packet that we needed */ - - ubcsp_config.link_establishment_resp =0 ; - -return 0 ; - } - } - -/* We now need to receive any octets from the UART */ - -while ((ubcsp_config.receive_packet) && (get_uart (&value))) - { -/* If the last octet was SLIP_ESCAPE, then special processing is required */ - -if (ubcsp_config.receive_slip_escape) - { -/* WARNING - out of range values are not detected !!! -This will probably be caught with the checksum or CRC check */ - - value = ubcsp_deslip[value -SLIP_ESCAPE_FRAME ]; - - ubcsp_config.receive_slip_escape =0 ; - } -else - { -/* Check for the SLIP_FRAME octet - must be start or end of packet */ -if (value ==SLIP_FRAME ) - { -/* If we had a full header then we have a packet */ - -if (ubcsp_config.receive_index >=0 ) - { -/* process the received packet */ - - *activity |=ubcsp_recevied_packet (); - -if (*activity &UBCSP_PACKET_ACK ) - { -/* We need to ACK this packet, then don't delay its sending */ - ubcsp_config.delay =0 ; - } - } - -/* Setup to receive the next packet */ - - ubcsp_config.receive_index =-4 ; - -/* Ok, next octet */ - - goto finished_receive; - } -else if (value ==SLIP_ESCAPE ) - { -/* If we receive a SLIP_ESCAPE, -then remember to process the next special octet */ - - ubcsp_config.receive_slip_escape =1 ; - - goto finished_receive; - } - } - -if (ubcsp_config.receive_index <0 ) - { -/* We are still receiving the header */ - - ubcsp_receive_header[ubcsp_config.receive_index +4 ] = value; - - ubcsp_config.receive_index ++; - } -else if (ubcsp_config.receive_index < ubcsp_config.receive_packet->length) - { -/* We are receiving the payload */ -/* We might stop comming here if we are receiving a -packet which is longer than the receive_packet->length -given by the host */ - - ubcsp_config.receive_packet->payload[ubcsp_config.receive_index] = value; - - ubcsp_config.receive_index ++; - } - -finished_receive: - { - } - } - -if (ubcsp_config.delay >0 ) - { -/* We were delayed so delay some more -this could be cancelled if we received something */ - - ubcsp_config.delay --; - } -else - { -/* We had no delay, so use the delay we just decided to us */ - - ubcsp_config.delay = delay; - } - -/* Report the current delay to the user */ - -return ubcsp_config.delay; -} +/* +* +* BlueZ - Bluetooth protocol stack for Linux +* +* Copyright (C) 2000-2005 CSR Ltd. +* +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +/*****************************************************************************/ +/*****************************************************************************/ +/*****************************************************************************/ +/** **/ +/** ubcsp,c **/ +/** **/ +/** MicroBCSP - a very low cost implementation of the BCSP protocol **/ +/** **/ +/*****************************************************************************/ + +#include "ubcsp.h" + +#if SHOW_PACKET_ERRORS ||SHOW_LE_STATES +#include <stdio.h> +#include <windows.h> +#endif + +static uint16 ubcsp_calc_crc (uint8 ch,uint16 crc); +static uint16 ubcsp_crc_reverse (uint16 ); + +/*****************************************************************************/ +/** **/ +/** Constant Data - ROM **/ +/** **/ +/*****************************************************************************/ + +/* This is the storage for the link establishment messages */ + +static const uint8 ubcsp_le_buffer[4 ][4 ] = + { + {0xDA ,0xDC ,0xED ,0xED }, + {0xAC ,0xAF ,0xEF ,0xEE }, + {0xAD ,0xEF ,0xAC ,0xED }, + {0xDE ,0xAD ,0xD0 ,0xD0 }, + }; + +/* These are the link establishment headers */ +/* The two version are for the CRC and non-CRC varients */ + +#if UBCSP_CRC +static const uint8 ubcsp_send_le_header[4 ] = + { +0x40 ,0x41 ,0x00 ,0x7E + }; +#else +static const uint8 ubcsp_send_le_header[4 ] = + { +0x00 ,0x41 ,0x00 ,0xBE + }; +#endif + +/*****************************************************************************/ +/** **/ +/** Static Data - RAM **/ +/** **/ +/*****************************************************************************/ + +/* This is the storage for all state data for ubcsp */ + +static struct ubcsp_configuration ubcsp_config; + +/* This is the ACK packet header - this will be overwritten when +we create an ack packet */ + +static uint8 ubcsp_send_ack_header[4 ] = + { +0x00 ,0x00 ,0x00 ,0x00 + }; + +/* This is the deslip lookup table */ + +static const uint8 ubcsp_deslip[2 ] = + { +SLIP_FRAME ,SLIP_ESCAPE , + }; + +/* This is a state machine table for link establishment */ + +static uint8 next_le_packet[16 ] = + { + ubcsp_le_sync,// uninit + ubcsp_le_conf,// init + ubcsp_le_none,// active + ubcsp_le_none, + ubcsp_le_sync_resp,// sync_resp + ubcsp_le_sync_resp, + ubcsp_le_none, + ubcsp_le_none, + ubcsp_le_none,// conf_resp + ubcsp_le_conf_resp, + ubcsp_le_conf_resp, + ubcsp_le_none, + }; + +/* This is the storage required for building send and crc data */ + +static uint8 ubcsp_send_header[4 ]; +static uint8 ubcsp_send_crc[2 ]; + +/* This is where the receive header is stored before the payload arrives */ + +static uint8 ubcsp_receive_header[4 ]; + +/*****************************************************************************/ +/** **/ +/** Code - ROM or RAM **/ +/** **/ +/*****************************************************************************/ + +/*****************************************************************************/ +/** **/ +/** ubcsp_initialize **/ +/** **/ +/** This initializes the state of the ubcsp engine to a known values **/ +/** **/ +/*****************************************************************************/ + +void ubcsp_initialize (void ) +{ + ubcsp_config.ack_number =0 ; + ubcsp_config.sequence_number =0 ; + ubcsp_config.send_ptr =0 ; + ubcsp_config.send_size =0 ; + ubcsp_config.receive_index =-4 ; + + ubcsp_config.delay =0 ; + +#if SHOW_LE_STATES +printf ("Hello Link Uninitialized\n" ); +#endif + + ubcsp_config.link_establishment_state = ubcsp_le_uninitialized; + ubcsp_config.link_establishment_packet = ubcsp_le_sync; +} + +/*****************************************************************************/ +/** **/ +/** ubcsp_send_packet **/ +/** **/ +/** This sends a packet structure for sending to the ubcsp engine **/ +/** This can only be called when the activity indication from ubcsp_poll **/ +/** indicates that a packet can be sent with UBCSP_PACKET_SENT **/ +/** **/ +/*****************************************************************************/ + +void ubcsp_send_packet (struct ubcsp_packet *send_packet) +{ +/* Initialize the send data to the packet we want to send */ + + ubcsp_config.send_packet = send_packet; + +/* we cannot send the packet at the moment +when we can at the moment, just set things to 0 */ + + ubcsp_config.send_size =0 ; + ubcsp_config.send_ptr =0 ; +} + +/*****************************************************************************/ +/** **/ +/** ubcsp_receive_packet **/ +/** **/ +/** This sends a packet structure for receiving to the ubcsp engine **/ +/** This can only be called when the activity indication from ubcsp_poll **/ +/** indicates that a packet can be sent with UBCSP_PACKET_RECEIVED **/ +/** **/ +/*****************************************************************************/ + +void ubcsp_receive_packet (struct ubcsp_packet *receive_packet) +{ +/* Initialize the receive data to the packet we want to receive */ + + ubcsp_config.receive_packet = receive_packet; + +/* setup to receive the header first */ + + ubcsp_config.receive_index =-4 ; +} + +/*****************************************************************************/ +/** **/ +/** ubcsp_calc_crc **/ +/** **/ +/** Takes the next 8 bit value ch, and updates the crc with this value **/ +/** **/ +/*****************************************************************************/ + + +#ifdef UBCSP_CRC + +static uint16 ubcsp_calc_crc (uint8 ch,uint16 crc) +{ +/* Calculate the CRC using the above 16 entry lookup table */ + +static const uint16 crc_table[] = + { +0x0000 ,0x1081 ,0x2102 ,0x3183 , +0x4204 ,0x5285 ,0x6306 ,0x7387 , +0x8408 ,0x9489 ,0xa50a ,0xb58b , +0xc60c ,0xd68d ,0xe70e ,0xf78f + }; + +/* Do this four bits at a time - more code, less space */ + + crc = (crc >>4 ) ^ crc_table[(crc ^ ch) &0x000f ]; + crc = (crc >>4 ) ^ crc_table[(crc ^ (ch >>4 )) &0x000f ]; + +return crc; +} + +/*****************************************************************************/ +/** **/ +/** ubcsp_crc_reverse **/ +/** **/ +/** Reserves the bits in crc and returns the new value **/ +/** **/ +/*****************************************************************************/ + +static uint16 ubcsp_crc_reverse (uint16 crc) +{ +int32 + b, + rev; + +/* Reserse the bits to compute the actual CRC value */ + +for (b =0 , rev=0 ; b <16 ; b++) + { + rev = rev <<1 ; + rev |= (crc &1 ); + crc = crc >>1 ; + } + +return rev; +} + +#endif + +/*****************************************************************************/ +/** **/ +/** ubcsp_put_slip_uart **/ +/** **/ +/** Outputs a single octet to the uart **/ +/** If the octet needs to be escaped, then output the escape value **/ +/** and then store the second octet to be output later **/ +/** **/ +/*****************************************************************************/ + +static void ubcsp_put_slip_uart (uint8 ch) +{ +/* output a single UART octet */ + +/* If it needs to be escaped, then output the escape octet +and set the send_slip_escape so that the next time we +output the second octet for the escape correctly. +This is done right at the top of ubcsp_poll */ + +if (ch ==SLIP_FRAME ) + { +put_uart (SLIP_ESCAPE ); + ubcsp_config.send_slip_escape =SLIP_ESCAPE_FRAME ; + } +else if (ch ==SLIP_ESCAPE ) + { +put_uart (SLIP_ESCAPE ); + ubcsp_config.send_slip_escape =SLIP_ESCAPE_ESCAPE ; + } +else + { +/* Not escaped, so just output octet */ + +put_uart (ch); + } +} + +/*****************************************************************************/ +/** **/ +/** ubcsp_which_le_payload **/ +/** **/ +/** Check the payload of this packet, and determine which of the four **/ +/** link establishment packets this was. **/ +/** Can return 5 if it is not a valid link establishment packet **/ +/** **/ +/*****************************************************************************/ + +static uint32 ubcsp_which_le_payload (const uint8 *payload) +{ +static int32 + octet, + loop; + +/* Search through the various link establishment payloads to find +which one we have received */ + +for (loop =0 ; loop <4 ; loop ++) + { +for (octet =0 ; octet <4 ; octet ++) + { +if (payload[octet] != ubcsp_le_buffer[loop][octet]) + { +/* Bad match, just to loop again */ + goto bad_match_loop; + } + } + +/* All the octets matched, return the value */ + +return loop; + +/* Jumps out of octet loop if we got a bad match */ +bad_match_loop: + {} + } + +/* Non of the link establishment payloads matched - return invalid value */ + +return 5 ; +} + +/*****************************************************************************/ +/** **/ +/** ubcsp_recevied_packet **/ +/** **/ +/** This function is called when we have a SLIP END octet and a full **/ +/** packet header and possibly data in the receive packet **/ +/** **/ +/*****************************************************************************/ + +static uint8 ubcsp_recevied_packet (void ) +{ +static uint8 + receive_crc, + receive_seq, + receive_ack, + activity; + +#if UBCSP_CRC +static int32 + loop; + +static uint16 + crc; +#endif + +static uint16 + length; + +/* Keep track of what activity this received packet will cause */ + + activity =0 ; + +/*** Do all error checks that we can ***/ + +/* First check the header checksum */ + +if (((ubcsp_receive_header[0 ] + ubcsp_receive_header[1 ] + ubcsp_receive_header[2 ] + ubcsp_receive_header[3 ]) &0xff ) !=0xff ) + { +/* Header Checksum Error */ + +#if SHOW_PACKET_ERRORS +printf ("\n######################## Header Checksum Error %02X %02X %02X %02X\n" , + ubcsp_receive_header[0 ], + ubcsp_receive_header[1 ], + ubcsp_receive_header[2 ], + ubcsp_receive_header[3 ]); +#endif + +/* If we have a header checksum error, send an ack in return +this gets a packet to be resent as quickly as possible */ + + ubcsp_config.send_ack =1 ; + +return activity; + } + +/* Decode the received packets header */ + + ubcsp_config.receive_packet->reliable = (ubcsp_receive_header[0 ] &0x80 ) >>7 ; + + receive_crc = (ubcsp_receive_header[0 ] &0x40 ) >>6 ; + receive_ack = (ubcsp_receive_header[0 ] &0x38 ) >>3 ; + receive_seq = (ubcsp_receive_header[0 ] &0x07 ); + + ubcsp_config.receive_packet->channel = (ubcsp_receive_header[1 ] &0x0f ); + + length = + ((ubcsp_receive_header[1 ] &0xf0 ) >>4 ) | + (ubcsp_receive_header[2 ] <<4 ); + +#if SHOW_PACKET_ERRORS +if (ubcsp_config.receive_packet->reliable) + { +printf (" : %10d Recv SEQ: %d ACK %d\n" , +GetTickCount () %100000 , + receive_seq, + receive_ack); + } +else if (ubcsp_config.receive_packet->channel !=1 ) + { +printf (" : %10d Recv ACK %d\n" , +GetTickCount () %100000 , + receive_ack); + } +#endif + +/* Check for length errors */ + +#if UBCSP_CRC +if (receive_crc) + { +/* If this packet had a CRC, then the length of the payload +should be 2 less than the received size of the payload */ + +if (length +2 != ubcsp_config.receive_index) + { +/* Slip Length Error */ + +#if SHOW_PACKET_ERRORS +printf ("\n######################## Slip Length Error (With CRC) %d,%d\n" , length, ubcsp_config.receive_index -2 ); +#endif + +/* If we have a payload length error, send an ack in return +this gets a packet to be resent as quickly as possible */ + + ubcsp_config.send_ack =1 ; +return activity; + } + +/* We have a CRC at the end of this packet */ + + ubcsp_config.receive_index -=2 ; + +/* Calculate the packet CRC */ + + crc =0xffff ; + +/* CRC the packet header */ + +for (loop =0 ; loop <4 ; loop ++) + { + crc =ubcsp_calc_crc (ubcsp_receive_header[loop], crc); + } + +/* CRC the packet payload - without the CRC bytes */ + +for (loop =0 ; loop < ubcsp_config.receive_index; loop ++) + { + crc =ubcsp_calc_crc (ubcsp_config.receive_packet->payload[loop], crc); + } + +/* Reverse the CRC */ + + crc =ubcsp_crc_reverse (crc); + +/* Check the CRC is correct */ + +if + ( + (((crc &0xff00 ) >>8 ) != ubcsp_config.receive_packet->payload[ubcsp_config.receive_index]) || + ((crc &0xff ) != ubcsp_config.receive_packet->payload[ubcsp_config.receive_index +1 ]) + ) + { +#if SHOW_PACKET_ERRORS +printf ("\n######################## CRC Error\n" ); +#endif + +/* If we have a packet crc error, send an ack in return +this gets a packet to be resent as quickly as possible */ + + ubcsp_config.send_ack =1 ; +return activity; + } + } +else + { +#endif +/* No CRC present, so just check the length of payload with that received */ + +if (length != ubcsp_config.receive_index) + { +/* Slip Length Error */ + +#if SHOW_PACKET_ERRORS +printf ("\n######################## Slip Length Error (No CRC) %d,%d\n" , length, ubcsp_config.receive_index); +#endif + +/* If we have a payload length error, send an ack in return +this gets a packet to be resent as quickly as possible */ + + ubcsp_config.send_ack =1 ; +return activity; + } +#if UBCSP_CRC + } +#endif + +/*** We have a fully formed packet having passed all data integrity checks ***/ + +/* Check if we have an ACK for the last packet we sent */ + +if (receive_ack != ubcsp_config.sequence_number) + { +/* Since we only have a window size of 1, if the ACK is not equal to SEQ +then the packet was sent */ + +if + ( + (ubcsp_config.send_packet) && + (ubcsp_config.send_packet->reliable) + ) + { +/* We had sent a reliable packet, so clear this packet +Then increament the sequence number for the next packet */ + + ubcsp_config.send_packet =0 ; + ubcsp_config.sequence_number ++; + ubcsp_config.delay =0 ; + +/* Notify the caller that we have SENT a packet */ + + activity |=UBCSP_PACKET_SENT ; + } + } + +/*** Now we can concentrate of the packet we have received ***/ + +/* Check for Link Establishment packets */ + +if (ubcsp_config.receive_packet->channel ==1 ) + { +/* Link Establishment */ + + ubcsp_config.delay =0 ; + +/* Find which link establishment packet this payload means +This could return 5, meaning none */ + +switch (ubcsp_which_le_payload (ubcsp_config.receive_packet->payload)) + { +case 0 : + { +/* SYNC Recv'd */ + +#if SHOW_LE_STATES +printf ("Recv SYNC\n" ); +#endif + +/* If we receive a SYNC, then we respond to it with a SYNC RESP +but only if we are not active. +If we are active, then we have a PEER RESET */ + +if (ubcsp_config.link_establishment_state < ubcsp_le_active) + { + ubcsp_config.link_establishment_resp =1 ; + } +else + { +/* Peer reset !!!! */ + +#if SHOW_LE_STATES +printf ("\n\n\n\n\nPEER RESET\n\n" ); +#endif + +/* Reinitialize the link */ + +ubcsp_initialize (); + +/* Tell the host what has happened */ + +return UBCSP_PEER_RESET ; + } +break ; + } + +case 1 : + { +/* SYNC RESP Recv'd */ + +#if SHOW_LE_STATES +printf ("Recv SYNC RESP\n" ); +#endif + +/* If we receive a SYNC RESP, push us into the initialized state */ + +if (ubcsp_config.link_establishment_state < ubcsp_le_initialized) + { +#if SHOW_LE_STATES +printf ("Link Initialized\n" ); +#endif + ubcsp_config.link_establishment_state = ubcsp_le_initialized; + } + +break ; + } + +case 2 : + { +/* CONF Recv'd */ + +#if SHOW_LE_STATES +printf ("Recv CONF\n" ); +#endif + +/* If we receive a CONF, and we are initialized or active +then respond with a CONF RESP */ + +if (ubcsp_config.link_establishment_state >= ubcsp_le_initialized) + { + ubcsp_config.link_establishment_resp =2 ; + } + +break ; + } + +case 3 : + { +/* CONF RESP Recv'd */ + +#if SHOW_LE_STATES +printf ("Recv CONF RESP\n" ); +#endif + +/* If we received a CONF RESP, then push us into the active state */ + +if (ubcsp_config.link_establishment_state < ubcsp_le_active) + { +#if SHOW_LE_STATES +printf ("Link Active\n" ); +#endif + + ubcsp_config.link_establishment_state = ubcsp_le_active; + ubcsp_config.send_size =0 ; + +return activity |UBCSP_PACKET_SENT ; + } + +break ; + } + } + +/* We have finished processing Link Establishment packets */ + } +else if (ubcsp_config.receive_index) + { +/* We have some payload data we need to process +but only if we are active - otherwise, we just ignore it */ + +if (ubcsp_config.link_establishment_state == ubcsp_le_active) + { +if (ubcsp_config.receive_packet->reliable) + { +/* If the packet we've just received was reliable +then send an ACK */ + + ubcsp_config.send_ack =1 ; + +/* We the sequence number we received is the same as +the last ACK we sent, then we have received a packet in sequence */ + +if (receive_seq == ubcsp_config.ack_number) + { +/* Increase the ACK number - which will be sent in the next ACK +or normal packet we send */ + + ubcsp_config.ack_number ++; + +/* Set the values in the receive_packet structure, so the caller +knows how much data we have */ + + ubcsp_config.receive_packet->length = length; + ubcsp_config.receive_packet =0 ; + +/* Tell the caller that we have received a packet, and that it +will be ACK'ed */ + + activity |=UBCSP_PACKET_RECEIVED |UBCSP_PACKET_ACK ; + } + } +else + { +/* Set the values in the receive_packet structure, so the caller +knows how much data we have */ + + ubcsp_config.receive_packet->length = length; + ubcsp_config.receive_packet =0 ; + +/* Tell the caller that we have received a packet */ + + activity |=UBCSP_PACKET_RECEIVED ; + } + } + } + +/* Just return any activity that occured */ + +return activity; +} + +/*****************************************************************************/ +/** **/ +/** ubcsp_setup_packet **/ +/** **/ +/** This function is called to setup a packet to be sent **/ +/** This allows just a header, or a header and payload to be sent **/ +/** It also allows the header checksum to be precalcuated **/ +/** or calculated here **/ +/** part1 is always 4 bytes **/ +/** **/ +/*****************************************************************************/ + +static void ubcsp_setup_packet (uint8 *part1,uint8 calc,uint8 *part2,uint16 len2) +{ +/* If we need to calculate the checksum, do that now */ + +if (calc) + { + part1[3 ] = + ~(part1[0 ] + part1[1 ] + part1[2 ]); + } + +/* Setup the header send pointer and size so we can clock this out */ + + ubcsp_config.send_ptr = part1; + ubcsp_config.send_size =4 ; + +/* Setup the payload send pointer and size */ + + ubcsp_config.next_send_ptr = part2; + ubcsp_config.next_send_size = len2; + +#if UBCSP_CRC +/* Initialize the crc as required */ + + ubcsp_config.send_crc =-1 ; + + ubcsp_config.need_send_crc =1 ; +#endif +} + +/*****************************************************************************/ +/** **/ +/** ubcsp_sent_packet **/ +/** **/ +/** Called when we have finished sending a packet **/ +/** If this packet was unreliable, then notify caller, and clear the data **/ +/** **/ +/*****************************************************************************/ + +static uint8 ubcsp_sent_packet (void ) +{ +if (ubcsp_config.send_packet) + { +if (!ubcsp_config.send_packet->reliable) + { +/* We had a packet sent that was unreliable */ + +/* Forget about this packet */ + + ubcsp_config.send_packet =0 ; + +/* Notify caller that they can send another one */ + +return UBCSP_PACKET_SENT ; + } + } + +/* We didn't have a packet, or it was reliable +Must wait for ACK before allowing another packet to be sent */ + +return 0 ; +} + +/*****************************************************************************/ +/** **/ +/** ubcsp_poll **/ +/** **/ +/** This is the main function for ubcsp **/ +/** It performs a number of tasks **/ +/** **/ +/** 1) Send another octet to the UART - escaping as required **/ +/** 2) Setup the payload to be sent after the header has been sent **/ +/** 3) Send the CRC for the packet if required **/ +/** **/ +/** 4) Calculate the next Link Establishment State **/ +/** 5) Send a Link Establishment packet **/ +/** 6) Send a normal packet if available **/ +/** 7) Send an ACK packet if required **/ +/** **/ +/** 8) Receive octets from UART and deslip them as required **/ +/** 9) Place received octets into receive header or receive payload buffer **/ +/** 10) Process received packet when SLIP_END is received **/ +/** **/ +/** 11) Keep track of ability of caller to delay recalling **/ +/** **/ +/*****************************************************************************/ + +uint8 ubcsp_poll (uint8 *activity) +{ +uint8 + delay =UBCSP_POLL_TIME_IMMEDIATE ; + +uint8 + value; + +/* Assume no activity to start with */ + + *activity =0 ; + +/* If we don't have to delay, then send something if we can */ + +if (!ubcsp_config.delay) + { +/* Do we have something we are sending to send */ + +if (ubcsp_config.send_size) + { +/* We have something to send so send it */ + +if (ubcsp_config.send_slip_escape) + { +/* Last time we send a SLIP_ESCAPE octet +this time send the second escape code */ + +put_uart (ubcsp_config.send_slip_escape); + + ubcsp_config.send_slip_escape =0 ; + } +else + { +#if UBCSP_CRC +/* get the value to send, and calculate CRC as we go */ + + value = *ubcsp_config.send_ptr ++; + + ubcsp_config.send_crc =ubcsp_calc_crc (value, ubcsp_config.send_crc); + +/* Output the octet */ + +ubcsp_put_slip_uart (value); +#else +/* Just output the octet*/ + +ubcsp_put_slip_uart (*ubcsp_config.send_ptr ++); +#endif + } + +/* If we did output a SLIP_ESCAPE, then don't process the end of a block */ + +if ((!ubcsp_config.send_slip_escape) && ((ubcsp_config.send_size = ubcsp_config.send_size -1 ) ==0 )) + { +/*** We are at the end of a block - either header or payload ***/ + +/* setup the next block */ + + ubcsp_config.send_ptr = ubcsp_config.next_send_ptr; + ubcsp_config.send_size = ubcsp_config.next_send_size; + ubcsp_config.next_send_ptr =0 ; + ubcsp_config.next_send_size =0 ; + +#if UBCSP_CRC +/* If we have no successor block +then we might need to send the CRC */ + +if (!ubcsp_config.send_ptr) + { +if (ubcsp_config.need_send_crc) + { +/* reverse the CRC from what we computed along the way */ + + ubcsp_config.need_send_crc =0 ; + + ubcsp_config.send_crc =ubcsp_crc_reverse (ubcsp_config.send_crc); + +/* Save in the send_crc buffer */ + + ubcsp_send_crc[0 ] = (uint8) (ubcsp_config.send_crc >>8 ); + ubcsp_send_crc[1 ] = (uint8 ) ubcsp_config.send_crc; + +/* Setup to send this buffer */ + + ubcsp_config.send_ptr = ubcsp_send_crc; + ubcsp_config.send_size =2 ; + } +else + { +/* We don't need to send the crc +either we just have, or this packet doesn't include it */ + +/* Output the end of FRAME marker */ + +put_uart (SLIP_FRAME ); + +/* Check if this is an unreliable packet */ + + *activity |=ubcsp_sent_packet (); + +/* We've sent the packet, so don't need to have be called quickly soon */ + + delay =UBCSP_POLL_TIME_DELAY ; + } + } +#else +/* If we have no successor block +then we might need to send the CRC */ + +if (!ubcsp_config.send_ptr) + { +/* Output the end of FRAME marker */ + +put_uart (SLIP_FRAME ); + +/* Check if this is an unreliable packet */ + + *activity |=ubcsp_sent_packet (); + +/* We've sent the packet, so don't need to have be called quickly soon */ + + delay =UBCSP_POLL_TIME_DELAY ; + } +#endif + } + } +else if (ubcsp_config.link_establishment_packet == ubcsp_le_none) + { +/* We didn't have something to send +AND we have no Link Establishment packet to send */ + +if (ubcsp_config.link_establishment_resp &2 ) + { +/* Send the start of FRAME packet */ + +put_uart (SLIP_FRAME ); + +/* We did require a RESP packet - so setup the send */ + +ubcsp_setup_packet ((uint8 *) ubcsp_send_le_header,0 , (uint8 *) ubcsp_le_buffer[ubcsp_le_conf_resp],4 ); + +/* We have now "sent" this packet */ + + ubcsp_config.link_establishment_resp =0 ; + } +else if (ubcsp_config.send_packet) + { +/* There is a packet ready to be sent */ + +/* Send the start of FRAME packet */ + +put_uart (SLIP_FRAME ); + +/* Encode up the packet header using ACK and SEQ numbers */ + + ubcsp_send_header[0] = + (ubcsp_config.send_packet->reliable << 7) | +#if UBCSP_CRC +0x40 |/* Always use CRC's */ +#endif + (ubcsp_config.ack_number <<3 ) | + (ubcsp_config.sequence_number); + +/* Encode up the packet header's channel and length */ + ubcsp_send_header[1 ] = + (ubcsp_config.send_packet->channel &0x0f ) | + ((ubcsp_config.send_packet->length <<4 ) &0xf0 ); + + ubcsp_send_header[2 ] = + (ubcsp_config.send_packet->length >>4 ) &0xff ; + +/* Let the ubcsp_setup_packet function calculate the header checksum */ + +ubcsp_setup_packet ((uint8 *) ubcsp_send_header,1 , ubcsp_config.send_packet->payload, ubcsp_config.send_packet->length); + +/* Don't need to send an ACK - we just place on in this packet */ + + ubcsp_config.send_ack =0 ; + +#if SHOW_PACKET_ERRORS +printf (" : %10d Send %d Ack %d\n" , +GetTickCount () %100000 , + ubcsp_config.sequence_number, + ubcsp_config.ack_number); +#endif + } +else if (ubcsp_config.send_ack) + { +/* Send the start of FRAME packet */ + +put_uart (SLIP_FRAME ); + +#if SHOW_PACKET_ERRORS +printf (" : %10d Send ACK %d\n" , +GetTickCount () %100000 , + ubcsp_config.ack_number); +#endif + +/* The ack packet is already computed apart from the first octet */ + + ubcsp_send_ack_header[0] = +#if UBCSP_CRC +0x40 | +#endif + (ubcsp_config.ack_number <<3 ); + +/* Let the ubcsp_setup_packet function calculate the header checksum */ + +ubcsp_setup_packet (ubcsp_send_ack_header,1 ,0 ,0 ); + +/* We've now sent the ack */ + + ubcsp_config.send_ack = 0; + } +else + { +/* We didn't have a Link Establishment response packet, +a normal packet or an ACK packet to send */ + + delay =UBCSP_POLL_TIME_DELAY ; + } + } +else + { +#if SHOW_PACKET_ERRORS +// printf (" : %10d Send LE %d\n", +// GetTickCount () % 100000, +// ubcsp_config.link_establishment_packet); +#endif + +/* Send A Link Establishment Message */ + +put_uart (SLIP_FRAME ); + +/* Send the Link Establishment header followed by the +Link Establishment packet */ + +ubcsp_setup_packet ((uint8 *) ubcsp_send_le_header,0 , (uint8 *) ubcsp_le_buffer[ubcsp_config.link_establishment_packet],4 ); + +/* start sending immediately */ + + ubcsp_config.delay =0 ; + +/* workout what the next link establishment packet should be */ + + ubcsp_config.link_establishment_packet = next_le_packet[ubcsp_config.link_establishment_state + ubcsp_config.link_establishment_resp *4 ]; + +/* We have now delt with any response packet that we needed */ + + ubcsp_config.link_establishment_resp =0 ; + +return 0 ; + } + } + +/* We now need to receive any octets from the UART */ + +while ((ubcsp_config.receive_packet) && (get_uart (&value))) + { +/* If the last octet was SLIP_ESCAPE, then special processing is required */ + +if (ubcsp_config.receive_slip_escape) + { +/* WARNING - out of range values are not detected !!! +This will probably be caught with the checksum or CRC check */ + + value = ubcsp_deslip[value -SLIP_ESCAPE_FRAME ]; + + ubcsp_config.receive_slip_escape =0 ; + } +else + { +/* Check for the SLIP_FRAME octet - must be start or end of packet */ +if (value ==SLIP_FRAME ) + { +/* If we had a full header then we have a packet */ + +if (ubcsp_config.receive_index >=0 ) + { +/* process the received packet */ + + *activity |=ubcsp_recevied_packet (); + +if (*activity &UBCSP_PACKET_ACK ) + { +/* We need to ACK this packet, then don't delay its sending */ + ubcsp_config.delay =0 ; + } + } + +/* Setup to receive the next packet */ + + ubcsp_config.receive_index =-4 ; + +/* Ok, next octet */ + + goto finished_receive; + } +else if (value ==SLIP_ESCAPE ) + { +/* If we receive a SLIP_ESCAPE, +then remember to process the next special octet */ + + ubcsp_config.receive_slip_escape =1 ; + + goto finished_receive; + } + } + +if (ubcsp_config.receive_index <0 ) + { +/* We are still receiving the header */ + + ubcsp_receive_header[ubcsp_config.receive_index +4 ] = value; + + ubcsp_config.receive_index ++; + } +else if (ubcsp_config.receive_index < ubcsp_config.receive_packet->length) + { +/* We are receiving the payload */ +/* We might stop comming here if we are receiving a +packet which is longer than the receive_packet->length +given by the host */ + + ubcsp_config.receive_packet->payload[ubcsp_config.receive_index] = value; + + ubcsp_config.receive_index ++; + } + +finished_receive: + { + } + } + +if (ubcsp_config.delay >0 ) + { +/* We were delayed so delay some more +this could be cancelled if we received something */ + + ubcsp_config.delay --; + } +else + { +/* We had no delay, so use the delay we just decided to us */ + + ubcsp_config.delay = delay; + } + +/* Report the current delay to the user */ + +return ubcsp_config.delay; +}
tools/ubcsp.h +207 -207
415 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH 6/6] Change end of line from DOS to UNIX
Hi,
Quoted 6 lines · Jose Antonio Santos Cadenas
Files
tools/ubcsp.candtools/ubcsp.hhad DOS end of line now they are changed to UNIX end of line--- tools/ubcsp.c | 2360 ++++++++++++++++++++++++++++---------------------------- tools/ubcsp.h | 414 +++++----- 2 files changed, 1387 insertions(+), 1387 deletions(-)
Thanks for these cleanup patches. I've pushed the first five upstream but am a little bit hesitant about this sixth one since it essentially replaces every line in the existing file and I'm not sure if it's worth having that obfuscating the commit history (e.g. git blame wouldn't be useful anymore). Marcel, do you have any opinion about having a patch like that in the tree?
Johan
Re: [PATCH 6/6] Change end of line from DOS to UNIX
El Friday 07 May 2010 00:56:33 Johan Hedberg escribi=F3:
Quoted 7 lines
Hi,
=20Quoted 4 lines · Jose Antonio Santos Cadenas
Files
tools/ubcsp.candtools/ubcsp.hhad DOS end of line now they are changed to UNIX end of line
---
tools/ubcsp.c| 2360 ++++++++++++++++++++++++++++---------------------=
=2D------
Quoted 9 lines
Quoted 2 lines
tools/ubcsp.h | 414 +++++----- 2 files changed, 1387 insertions(+), 1387 deletions(-)=20
Thanks for these cleanup patches. I've pushed the first five upstream but am a little bit hesitant about this sixth one since it essentially replaces every line in the existing file and I'm not sure if it's worth having that obfuscating the commit history (e.g. git blame wouldn't be useful anymore). Marcel, do you have any opinion about having a patch like that in the tree?
That's what I put this in a separate patch. I just wanted to note that some=
files had this=20
end of line. One of them had also some lines with DOS end fo line and other= s with UNIX eol.
Quoted 4 lines
=20
Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth=
" in
Quoted 3 lines
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
=20