bfb.c File Reference

BFB transport encapsulation (used for Siemens mobile equipment). More...

`#include <stdio.h>`
`#include <stdlib.h>`
`#include <inttypes.h>`
`#include <string.h>`
`#include <unistd.h>`
`#include <sys/select.h>`
`#include <netinet/in.h>`
`#include "crc.h"`
`#include "bfb.h"`
`#include <common.h>`

## Macros

#define | STRUCT_OFFSET(struct_type, member) ((uint64_t) ((char*) &((struct_type*) 0)->member))
#define | STRUCT_MEMBER_P(struct_p, struct_offset) ((void *) ((char*) (struct_p) + (uint64_t) (struct_offset)))
#define | STRUCT_MEMBER(member_type, struct_p, struct_offset) (*(member_type*) STRUCT_MEMBER_P ((struct_p), (struct_offset)))
#define | htoms(A) (A)
#define | htoml(A) (A)
#define | mtohs(A) (A)
#define | mtohl(A) (A)

## Functions

uint8_t | bfb_checksum (uint8_t *data, int len)
| Returns the whole buffer folded with xor. More...
int | bfb_stuff_data (uint8_t *buffer, uint8_t type, uint8_t *data, uint16_t len, uint8_t seq)
| Stuff data frame into serial cable encapsulation. More...
int | bfb_write_subcmd (fd_t fd, uint8_t type, uint8_t subtype)
| Send a cmd, subcmd packet, add chk (no parameters). More...
int | bfb_write_subcmd0 (fd_t fd, uint8_t type, uint8_t subtype)
| Send a cmd, subcmd packet. More...
int | bfb_write_subcmd8 (fd_t fd, uint8_t type, uint8_t subtype, uint8_t p1)
| Send a cmd, subcmd, data packet. More...
int | bfb_write_subcmd1 (fd_t fd, uint8_t type, uint8_t subtype, uint16_t p1)
| Send a cmd, subcmd packet, add chk (one word parameter). More...
int | bfb_write_subcmd2 (fd_t fd, uint8_t type, uint8_t subtype, uint16_t p1, uint16_t p2)
| Send a cmd, subcmd packet, add chk (two word parameter). More...
int | bfb_write_subcmd3 (fd_t fd, uint8_t type, uint8_t subtype, uint16_t p1, uint16_t p2, uint16_t p3)
| Send a cmd, subcmd packet, add chk (three word parameter). More...
int | bfb_write_subcmd_lw (fd_t fd, uint8_t type, uint8_t subtype, uint32_t p1, uint16_t p2)
| Send a cmd, subcmd packet, add long, word parameter. More...
int | bfb_write_packets (fd_t fd, uint8_t type, uint8_t *buffer, int length)
| Send actual packets. More...
int | bfb_send_data (fd_t fd, uint8_t type, uint8_t *data, uint16_t length, uint8_t seq)
| Stuff data into packet buffers and send all packets. More...
bfb_frame_t * | bfb_read_packets (uint8_t *buffer, int *length)
| Retrieve actual packets. More...
int | bfb_assemble_data (bfb_data_t **data, int *size, int *len, bfb_frame_t *frame)
| Append BFB frame to a data buffer. More...
int | bfb_check_data (bfb_data_t *data, int len)
| Check if data buffer is complete and valid. More...

## Detailed Description

BFB transport encapsulation (used for Siemens mobile equipment).

ObexFTP library - language bindings for OBEX file transfer.

Copyright (c) 2002-2007 Christian W. Zuckschwerdt zany@.nosp@m.triq.nosp@m..net

ObexFTP is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with ObexFTP. If not, see http://www.gnu.org/.

## Macro Definition Documentation

## htoml

#define htoml | ( |  | A | ) | (A)

## htoms

#define htoms | ( |  | A | ) | (A)

## mtohl

#define mtohl | ( |  | A | ) | (A)

## mtohs

#define mtohs | ( |  | A | ) | (A)

## STRUCT_MEMBER

#define STRUCT_MEMBER | ( |  | member_type,
|  |  | struct_p,
|  |  | struct_offset
| ) |  | (*(member_type*) STRUCT_MEMBER_P ((struct_p), (struct_offset)))

## STRUCT_MEMBER_P

#define STRUCT_MEMBER_P | ( |  | struct_p,
|  |  | struct_offset
| ) |  | ((void *) ((char*) (struct_p) + (uint64_t) (struct_offset)))

## STRUCT_OFFSET

#define STRUCT_OFFSET | ( |  | struct_type,
|  |  | member
| ) |  | ((uint64_t) ((char*) &((struct_type*) 0)->member))

## Function Documentation

## bfb_assemble_data()

int bfb_assemble_data | ( | bfb_data_t ** | data,
|  | int * | size,
|  | int * | len,
|  | bfb_frame_t * | frame
| ) |  |

Append BFB frame to a data buffer.

## bfb_check_data()

int bfb_check_data | ( | bfb_data_t * | data,
|  | int | len
| ) |  |

Check if data buffer is complete and valid.

## bfb_checksum()

uint8_t bfb_checksum | ( | uint8_t * | data,
|  | int | len
| ) |  |

Returns the whole buffer folded with xor.

## bfb_read_packets()

bfb_frame_t* bfb_read_packets | ( | uint8_t * | buffer,
|  | int * | length
| ) |  |

Retrieve actual packets.

## bfb_send_data()

int bfb_send_data | ( | fd_t | fd,
|  | uint8_t | type,
|  | uint8_t * | data,
|  | uint16_t | length,
|  | uint8_t | seq
| ) |  |

Stuff data into packet buffers and send all packets.

## bfb_stuff_data()

int bfb_stuff_data | ( | uint8_t * | buffer,
|  | uint8_t | type,
|  | uint8_t * | data,
|  | uint16_t | len,
|  | uint8_t | seq
| ) |  |

Stuff data frame into serial cable encapsulation.

buffer needs to be of at leaset len+7 size Type 0x01: "prepare" command. Type 0x02: first transmission in a row. Type 0x03: continued transmission. seq needs to be incremented afterwards.

## bfb_write_packets()

int bfb_write_packets | ( | fd_t | fd,
|  | uint8_t | type,
|  | uint8_t * | buffer,
|  | int | length
| ) |  |

Send actual packets.

Patch from Jorge Ventura to handle EAGAIN from write.

## bfb_write_subcmd()

int bfb_write_subcmd | ( | fd_t | fd,
|  | uint8_t | type,
|  | uint8_t | subtype
| ) |  |

Send a cmd, subcmd packet, add chk (no parameters).

## bfb_write_subcmd0()

int bfb_write_subcmd0 | ( | fd_t | fd,
|  | uint8_t | type,
|  | uint8_t | subtype
| ) |  |

Send a cmd, subcmd packet.

## bfb_write_subcmd1()

int bfb_write_subcmd1 | ( | fd_t | fd,
|  | uint8_t | type,
|  | uint8_t | subtype,
|  | uint16_t | p1
| ) |  |

Send a cmd, subcmd packet, add chk (one word parameter).

## bfb_write_subcmd2()

int bfb_write_subcmd2 | ( | fd_t | fd,
|  | uint8_t | type,
|  | uint8_t | subtype,
|  | uint16_t | p1,
|  | uint16_t | p2
| ) |  |

Send a cmd, subcmd packet, add chk (two word parameter).

## bfb_write_subcmd3()

int bfb_write_subcmd3 | ( | fd_t | fd,
|  | uint8_t | type,
|  | uint8_t | subtype,
|  | uint16_t | p1,
|  | uint16_t | p2,
|  | uint16_t | p3
| ) |  |

Send a cmd, subcmd packet, add chk (three word parameter).

## bfb_write_subcmd8()

int bfb_write_subcmd8 | ( | fd_t | fd,
|  | uint8_t | type,
|  | uint8_t | subtype,
|  | uint8_t | p1
| ) |  |

Send a cmd, subcmd, data packet.

## bfb_write_subcmd_lw()

int bfb_write_subcmd_lw | ( | fd_t | fd,
|  | uint8_t | type,
|  | uint8_t | subtype,
|  | uint32_t | p1,
|  | uint16_t | p2
| ) |  |

Send a cmd, subcmd packet, add long, word parameter.