Yes, it's done by the firmware. Some drives even carry a separate internal identification for this purpose (for example, all 1653S-based firmwares will stamp D24A even though none of them are identified as such).
As for the serial number, that depends on the manufacturer. Some manufacturers don't store the serial number in the drive itself so it is impossible for the drive to write the serial number (so it'll leave it blank or write junk data that might look like a serial number but really is not). Some drives choose not to write the s/n. So it all depends.
And to trace a serial number back to a customer is not all that easy, either. Not all companies will bother to spend the money to keep a database like that.