Multiwavelength campaign on Mrk 509 XII. Broad band spectral analysis