A boundary layer model for magnetospheric substorms