Tag Archives: english

BlueZ now has A2DP Sink support

Last week was the midterm evaluations for GSoC and also the very same week when my patches were merged upstream into BlueZ. Most of the work was to adapt the existing Source functions to support both Source and Sink and to add Sink logic to the A2DP Server.

There is now a new Source interface on D-Bus, similar to the Sink interface, than can be used to access the Sink functionality. It may sound odd the Sink being accessed through an interface called Source, but in this case it actually acts as a sink on the air interface (receives audio stream from other bluetooth device) and as a source on the application interface (generates audio stream to applications).

Unfortunately, that’s not enough for one to be able to stream audio to a BlueZ device. Right now there is no client able to handle the incoming stream. The good news are that this is part 2 of my SoC project, to implement some clients outside BlueZ to handle this stream. I’m gonna start with PulseAudio, since I’ve implemented the bluetooth sink module on it last year and am more familiar with it’s implementation. After that, I’ll probably implement an ALSA client too.

So what’s the current implementation useful for? From an users perspective, not much. But it shows we are on the way to have it done. Right now it’s possible to connect to the audio sink and put it on STREAMING state, but it doesn’t know how handle the stream and disconnects after a few packets. I’ve tested it with two bluetooth adapter on my laptop and also trying to stream from an Android phone to the laptop.

The Source interface is disabled by default, so if want to test it, make sure to add an “Enable=Source” line to your audio.conf. The code is available on bluez git repo and will be on release 4.46.

FISL10 Programming Arena

This is the third edition FISL organizes a programming contest called Programming Arena. This name came from the original idea that the participants had to stay inside a glass room in the middle of the event area without being allowed to exit (except for bathroom, which they had go accompanied). This year some of this restrictions were relaxed and participants could go in and out as they wish, with the only restriction they had to arrive before 10AM every day of the competition.

The competition consists in two phases: Qualifying, in which participants have to discover a nine letter code that’s needed for the inscription, and Insanifying, when participants spend three days working on a challenge proposed by the organization.

I wasn’t very excited about it at the beginning, since I didn’t want to spend a lot of time working on discovering the code and then spend almost the whole FISL programming (the same thing I usually do every day). But then, some weeks after the qualifying had started, they published a notice telling that no one had found out the right code yet. It was a cold friday night, I had gone to spend the weekend at my parents house, and after having some fondue and wine for dinner, I grabbed the remaining half bottle of wine, sat with my laptop by the fireplace, and decided to give it a try. I already knew that there were some hints for the code as comments in the HTML source of first link in this post, and then discovered one additional hint in the source of the second link on this post. About 4:00 in the morning, I’ve managed to find out that the code was hidden in a pseudo-echo server at arena.softwarelivre.org:1996, that when string “peixe” (a keyword on the Tux profile at the softwarelivre.org social network) is inputed, responds with a cyphered string. During the whole process, I had been chating with Padovan on IM, since he had spent some time working on the problem with his housemate, a few days before, with no success. We both agreed that it should be some simple cypher, some sort of substitution-based cypher, since there was no hints on cypher algorithms so far and that the string was short and had some blank spaces, resembling a phrase of a few words. At that moment Padovan stopped what he was doing before and said: “Let’s break that cypher!”. So I continued working on trying to find a key hidden somewhere else while he wrote a script for a dictionary-based attack using the Firefox portuguese dictionary. Since one of the words had 2 letters that repeated, he aimed at it and no much time latter he could guess that word: inscricao, the ascii-only version of the word inscription in portuguese (“inscrição”). With the mapping of this word and guessing some other letters we could find out almost the whole phrase, missing only one letter, exactly in the middle of the 9-letter code. There were only 12 letters not matched, so we could had tryed the inscription using brute-force, but we decided to have some sleep and try a bit more in the next day. In the next morning, someone had find out the key and posted it on a blog. The key was hidden as the TXT DNS record of arena.softwarelivre.org, and had the matching for the whole alphabet. The whole decyphered phrase was “parabens seu codigo de inscricao eh goosfabra” (congratulations your inscription code is goosfraba).

The second phase, during FISL, was even more interesting. The challenge was to implement DNSCurve, a security extension of the DNS protocol, both in a forwarder (server) and in a cache (client). Before the implementation started we saw a panel discussion about DNSCurve vs DNSSEC with Daniel J. Bernstein, the creator of DNSCurve (and also of djbdns and qmail). DJB was also responsible for judgin the code produced during the arena. There was a draw to group the participants in three groups of three people and one group of two people, and luckily me and Padovan ended in the same group, together with Rodrigo Tjäder, from UFSM. After three days of work, we had the following work done:

(1) DNS Server — pymdscurve.tar.bz2

We based our implementation on pymds, a modular python DNS server licensed under the MIT license. It’s a standalone DNS server, in terms it doesn’t resolve any names it doesn’t know. For the NaCl (crypto) functions, we used the slownacl lib from dnscurve. Despite it doesn’t says on the website, we contacted the authors (both Matthew and Angel) and both of them told us it’s public domain and a note on the project page is missing. Matthew even added a README to the code which says it’s public domain and updated some code on the lib to make it compliant with NaCl newer spec on DJB’s website.

(2) DNS Cache

For the cache we tried two different approaches.

(i) PyDNSCacheCurve.tar.bz2 — First we added the DNSCurve messages to PyDNSCache, which is a very simple DNS cache written in python and intended to be used as a python library. This code didn’t had any license note on the project page either, but we contacted the author and he licensed it under Creative Commons Attribution 3.0 United States License. Since it’s just a cache of DNS information, it used
gethostbyname() from the socket module. We changed it to use a function we implemented, gethostfromDNS(), to send the necessary DNS messages to get the information from a server. For the cryptography part we’ve also used slownacl from dnscurve. We didn’t implemented the ability to resolve names recursively on PyDNSCache, so we hardcoded the server public key inside the code.

(ii) dnspythoncurve.tar.bz2 — Since solution (i) was unable to resolve names recursively, we decided to use dnspython, which provides a lot of helper functions to deal with DNS. We’ve added DNSCurve extensions to it and also added a recursive resolver. dnspython is released under a BSD-style license. Since recursive resolution works we can get the server name to check if it a DNSCurve enabled server and, if so, obtain it’s public key. We’ve tested pymdscurve and dnspythoncurve under a scenery with two servers, one configured as authority for .com and other as authority for example.com, in order to test recursive resolution. Both config files are shipped in pymdscurve package.

So much work worth every line of code. Besides learning a lot and having fun, we also won the contest, getting an Android Dev Phone 1 for each participant of the team as a stipend (thanks google!) and lots of good words about our implementation from DJB. I will son add some photos and a video of the winners announcement.:

Explaining our implementation

The winner team with DJB

 

We gonna send patches back to all projects we’ve added code to. We have also added some code to some dns helper functions on dnscurve, outside of slownacl. The source code of our implementation can be found at http://www.las.ic.unicamp.br/~joaopaulo/dnscurve/ http://www.las.ic.unicamp.br/~jprvita/dnscurve/.

GSoC09 is up and running!

I’m glad to announce that I was accepted for one more Google Summer of Code program. I’m going to work with BlueZ again, this year to implement the A2DP sink profile. Full proposal following.

Abstract

This project is to implement the Sink role on BlueZ, according to the A2DP specification v1.2. This role provide means to receive an audio stream coming from an audio Source on the same piconet. It’s very important, and can add several use cases for the Linux bluetooth stack, like Linux to Linux streams, bluetooth microphones support or using a Linux device as bluetooth speakers. It’s also a mandatory feature for an implementation to be full compliant with A2DP v1.2.

Content

Have you worked on a Linux system before?

I’ve been working with Linux since 2002, when I’ve started the Computer Engineering undergrad. In the beginning I just did the school projects on Linux, but since the middle of 2002 it’s my main system. By that time I had Conectiva on my home computer, RedHat on the school, and Slackware on my home router. After a few years I got in touch with Gentoo, and I liked so much the idea that it became my main distro. In addition, I’ve also started working on a project at University of Campinas, to make a Linux distribution for Itautec, a brazilian IT company, which was Gentoo based. Nowadays I’m using Ubuntu in my laptop, because of the speedy install and no need of much tweaking, so I have more time to work with other projects, but I’m confortable using and administrating any distribution.

Have you contributed to a open source project? if yes, please provide the details

My first contribution was a little bit frustrating, since I never got any answer (a two lines patch to python-dialog – http://sourceforge.net/projects/pythondialog/ – to support one dialog that was missing). After that I’ve made some performance improvements in ImageMagick and DevIL using OpenMP, both of them being accepted upstream. I was also accepted and successfully completed a GSoC 08 project with BlueZ to make the bluetooth audio client for PulseAudio. All these successful experiences were outstanding and all of them (now including the never answered patch) were very useful to learn about the community and how to work with open source model. Now I’m looking for a job with open source, and also plan to continue contributing to some projects of my personal interest. Right now I’m following the BlueZ and PulseAudio mailing lists.

What is your educational Qualification (grad/under-grad) ?

I’m a Computer Engineer, majored on University of Campinas (Unicamp), Brazil. I’ve started my master degree on Computer Science studies last year, on the same university, working with visualization of concurrent algorithms. I’ve also been working as a teaching assistant of the Operating Systems course in my university, for two semesters. The last time we proposed to the students to make some changes in a memory filesystem that was developed for them to work on. This activity is giving me a bit more of knowledge on the Linux kernel, that maybe can be helpful to complete this project.

Why do you want to do a project involving Bluetooth/BlueZ ?

I’ve already been a GSoC student with BlueZ and was a very good experience. I’ve worked with the same protocol of this project, so I already have some knowledge on it. The initial motivation to choose BlueZ last year was because it’s something that I use on my daily activities (I have a bluetooth mouse on my notebook and a headset that I use to talk with friends and family on VoIP systems) and because I’m very enthusiastic about wireless devices and mobility. Besides that, I always had interest about network-related stuff.

If your application is accepted will it be a part of your graduation process or it will it be just for hobby?

If I get accepted to this project, it will not be part of my graduation process.

Give us an *estimative* of your schedule (exams period, etc.) and how much time you would be able to dedicate to the project.

The project will be divided into 5 activities. I plan to work around 20h per week with this project, during the whole program. The other 20h of a working week are going to be dedicated to my Master degree program, but it’s flexible enough to allow me some extra hours near deadlines, if needed.

1. Re-read the A2DP specification v1.2 from bluetooth.com (and related specs like AVDTP, GAVDP etc) and understand it’s current implementation. The A2DP Sink role is the dual of the A2DP Source role, with the main difference being the implementation of the “Receive Audio Stream” procedure, described in Section 3.2.2 of the spec, instead of the “Send Audio Stream procedure”. Together with this study of the spec, the code under the audio dir on BlueZ source code will be studied, to learn exactly what’s implemented and which files implement each part.

2. Maybe reorganize some code to enable reuse. If there are some already implemented parts for the Source which the Sink is also going to use (likely the AVDTP signaling procedures), the idea is to use the same implementation to minimize bugs and easy the maintenance.

3. Find out which are the missing parts and procedures to full support the Sink role and implement them.

4. Create the API for clients that want to obtain the audio received by BlueZ and export it via D-Bus, as it already done for the Source profile (which acts as a sink for software clients like media players).

Community Bounding Period (April 20th – May 22nd): Activities 1 and 2 are going to be performed on this period.

Coding Phase I (May 23rd – July 12nd): Most of activity 3 is going to be performed on this period.

Coding Phase II (July 13rd – August 17th): Finish of activity 3 and activity 4 are going to be performed on this period.

Future Work: If there is enough time, or as a future project, I would like to implement a client that uses the bluetooth audio somehow, in order to test the Sink implementation. My first idea is to do so on PulseAudio, as I’ve already worked with it before, but other ideas are also welcome.

GSoC09 Talk at University of Campinas

This week we made a talk about the Google Summer of Code program at the University of Campinas. The talk was part of a serie of seminars about free software, that are held as course of the Institute of Computing in this university. We were five people on speech, all of us past GSoC’ers, some for more than one edition. The main focus of the talk was not just to tell people about what the GSoC program is, but also to tell people how participating in GSoC was a great experience to all of us. In adition, we tried to give people some tips on what to do in order to get accepted and sucessfully complete the program, and also left an open channel to support them during the application process.

We started with the oficial program slides, to tell people what exactly the GSoC program consists of. After that, we showed some statistical data about our university in the program, since we were ranked 2nd both on number of applicants and accepted applications. Then, we had a look at the list of mentoring organizations for last year, and showed then how to get to the ideas list of each org, how to find their bugzilla, feature requests, etc. After, we tried to teach them a little on how to write a good application, how to get in touch with the mentoring organization, and some what-not-to-do’s in a FOSS community. To finish, each of us told a little bit about his own experience on past GSoC’s and opened to questions.

This serie of seminars has the support of the GPSL (a student’s group to promote FOSS), which all speakers are members of, and of the FSFLA, so in the end we all got a FSFLA pen as a stipend!

The speakers were Bruno Cardoso, Bruno Dilly, Luis Felipe Strano Moraes, João Batista Correa Gomes Moreira, and João Paulo Rechi Vita (me).

The talk
The talk
People asking questions at the end
People asking questions at the end
The audience
The audience

Bluez-PulseAudio is now mainstream

With the PulseAudio 0.9.13 being release on Oct 10th, my bluetooth module for PulseAudio has gone upstream! Check out the relese notes.

Com o lançamento do PulseAudio 0.9.13 em 10/Oct, meu módulo bluetooth entrou na linha de desenvolvimento principal! Veja as notas de lançamento.

Con el lanzamiento del PulseAudio 0.9.13 en 10/Oct, mi modulo bluetooth ha entrado en la linea de desarrollo principal! Vea las notas de lanzamiento.

C Statical Analysis Tools

This week I’ve been researching on some statical analysis tools for C language that suits the needs of the project I’m currently working on at LSD-FI-UPM.

Here is a summary of what I’ve found out.

CIL: Intermediate Language and Tools for Analysis and Transformations of C Programs

It’s suitable, but the transformations have to be written in Ocaml.

From the CIL Documentation:

The most common way to use CIL is to write an Ocaml module containing your analysis and transformation, which you then link into our boilerplate driver application called cilly.

It’s possible to use it as a library, but the API is also for Ocaml projects.

CIL is able to handle big projects, through a module they call the whole-program merger. It’s not explicitly mentioned if it’s able to handle shared libs, but it seems so, since it was able to handle some very big projects like the Linux kernel, the gcc compiler and the Apache web server.

It has a Control Flow Graph module and a Data-flow Analysis module, but the paper says that they were not as much exercised as the other parts of CIL.

Frama-C

Written using CIL, has the same drawback that the extensions have to be written in Ocaml.

LLVM/Clang

Clang is the C/C++ front-end of the LLVM compiler. It’s under heavy development, and since it’s intended use is real world compiling, we can expect to have a very good and complete tool. It’s development is founded by Apple Inc. Clang is built with a library based architecture that makes it relatively easy to adapt it and build new tools with it. These are some of it’s layers:

  • libast – Provides classes to represent the C AST, the C type system, builtin functions, and various helpers for analyzing and manipulating the AST (visitors, pretty printers, etc).l
  • libsema – Semantic Analysis. This provides a set of parser actions to build a standardized AST for programs.
  • librewrite – Editing of text buffers (important for code rewriting transformation, like refactoring).
  • libcodegen – Lower the AST to LLVM IR for optimization & code generation.

It fails to compile on my machine at the lab, so I compiled it at my laptop and was able to generate CFG’s for parts of a program, but not for the whole program. Also, I wasn’t able to control exactly for witch parts of the program the CFG’s were generated.

C-Breeze

It’s a tool intended for compilers construction. It seems to suit the project needs, but it’s not available for download on the project page. One need to contact the authors in order to get the tool. In the CIL paper, it’s author says that C-Breeze doesn’t support analyzing programs that span over multiple files, but I haven’t checked this issue.

SUIF

The documentation of this tool is a bit confusing. It seems to do a lot of stuff, the documentation mentions AST’s but it doesn’t say nothing about CFG’s or call graphs, so I’m not sure if it’s suitable for the project or no. In the CIL paper, the author says it can’t handle many of the GCC extensions, so it can’t analyze real-world programs.

Conclusions:

Right now, it seems to me that LLVM/Clang is the best choice. I still have to figure out how to generate call-graphs using it, but I think it’s possible. Another choice wouId be CIL, but since I’ve never used Ocaml, and don’t have a strong basis on functional languages, I prefer to avoid it. If someone has any sugestions on other tools, or pointers on more detailed info regarding these tools (specially LLVM/Clang), please leave a comment.

GSoC 2008

This year I’ve participated in the Google Summer of Code program. Despite the fact that wasn’t summer in the southern hemisphere, everything happened as expected. I’ve worked with BlueZ as my mentoring organization, and my project was to add bluetooth support to the PulseAudio sound server. The abstract of my application can be found here.

The implementation was made through 2 modules: module-bluetooth-device and module-bluetooth-discover. The latter connects to BlueZ through D-Bus to find out what devices have already been paired with each adapter present on the system, and the loads one instance of the module-bluetooth-device for each device found (in contrast to linux kernel modules, PulseAudio modules can be loaded more than once at the same time). It also keeps watching for new adapters and devices, so it can load a module to take care of each new device that shows up.

The former, module-bluetooth-device, is the one who actually does the job of creating the bluetooth audio channel in PulseAudio. First, it connects to the BlueZ audio service through one unix socket to obtain the device capabilities. Then it configures the device according to it’s capabilities, setup the SBC encoder (if applicable) and obtain a file descriptor to write audio data to the device. This fd is passed to a PulseAudio I/O thread (which runs with real time priorities if the user has real time privileges properly set), which gets the audio data coming to this sink (sink is the name of an output channel in PulseAudio), encode it (if applicable) and write it on the device fd. Also, the I/O thread has to take care of the clock synchronization between PulseAudio an the device.

I really enjoyed doing this job. Working with an open source community is outstanding! I’ve learned a lot during the program, made good contacts, and the most important: had a lot of fun! I would like to thank a lot my mentor, Luiz Augusto von Dentz, and the PulseAudio maintainer, Lennart Poettering. Without the help of these two guys I wouldn’t have been able to finish this project. And of course I have to thank Google for helping FLOSS develpment throug this program and LH for making the program happen and for being so kind and patient with all the students. LH, you rock!

I’ll continue working on this project, since there still a lot to be done. Time synchronization is not the best and the usability is far from ideal. I have a git repository for this on gitorious, on an branch called bt. Feel free to point bugs and make sugestions. Also, if you really enjoyed the project and want to help more, I accept donations of A2DP, HSP, or HFP bluetooth audio devices, for test and development. All of this was made so far with a borrowed device from my good friend João Eduardo Ferreira Bertacchi (thanks JE!). The oficial release note on the BlueZ website about this project can be found here.

Hello world!

Welcome to my weblog. Here I plan to publish some techie stuff, especially news about projects I’m working on and maybe some articles and reviews. And in the middle of all of this, maybe some thoughts or interesting things I’ve seen somewhere.

Bem vindo ao meu weblog. Aqui eu planejo publicar coisas técnicas, especialmente novidades sobre os projetos nos quais estou trabalhando e talvez alguns artigos e análises. E no meio de tudo isso, talvez alguns pensamentos ou coisas interessantes que eu tenha visto em algum lugar.

Bienvenido a mi weblog. Aqui yo planejo publicar cosas tecnicas, especialmente novidads sobre los proyectos en que estoy trabajando y talvez alguns articulos y analisys. Y en el medio de todo eso, talvez alguns pensamientos o cosas interesantes que yo tenga visto en algun sitio.