Working Version 18022013
+ added length-check for foreigndeviceid